UCI based chess Engine : Some questions.

Started by
8 comments, last by ashish123 10 years, 10 months ago

I have coded a chess engine in C# which has no sophisticated features.

I have just done with mate detection and some crude static evaluation.

I am trying to make it UCI compatible, but then I am facing a question as to why the protocol returns the list of moves rather than the fen of the new position.

I mean the list of moves will take more time to execute and the space required is also more than equivalent FEN string.

Can any one help me with this?

Advertisement

Presumably so it can tell if the same position comes up 3 times for a draw?

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

First of all, the protocol allows both possibilities. What Paradigm Shifter says is true, but after an irreversible move (i.e., a pawn move or a capture) is played, the GUI could send the FEN for the position after the last such move and then the list of moves from that point. However, many GUIs choose to send the whole list of moves every time. Presumably this is done for simplicity. Although it might be suboptimal, it's not a problem in practice.

Hi all, Thanks for replying.

I faced this question as I programmed by Engine to setup board via FEN and not by move input.

I don't really keep track of game specs like castling and enpassant squares on move by move basis, but rather break the fen and adjust all parameters accordingly.

I am using Arena as GUI. Is there any setting where in I can just tweak it to send me the FEN instead of moves, but then again I wouldn't be able to keep track of 3-repetition draws.

If I go with the move approach, then I have to convert the physical move to logical 64 bit-bit-board move, adjust all the flags and so on.

So is this worth or is there anything else which I am missing.

Converting the move in algebraic notation to whatever data structure you use for moves shouldn't be too hard and you should definitely do it. You should also be able to keep track of castling, the en-passant square and how many moves have happened since the last irreversible move, because otherwise you can't implement the rules of the game correctly.

Hi alvaro, thanks for replying.

I implemented the move logic without considering 3 move repetitions which is going to be my next priority.

Here is a game that it played at maxDepth 5 without any sophistication not even killers or anything of that sort, plain alpha beta with very crude static evaluation.

it took about 15 secs to make a move on an average.

Here is the first game where it played with white.
1. d4 e6 2. e4 Nc6 3. Nc3 Bb4 4. Nf3 Nf6 5. e5 Ne4 6. Bd2 Nxd2 7. Qxd2 O-O
8. Bb5 d5 9. Bxc6 bxc6 10. O-O-O Bb7 11. Rhe1 a5 12. g4 f6 13. g5 fxe5 14.
Nxe5 Bd6 15. a3 g6 16. f4 a4 17. h3 Qe7 18. h4 Qg7 19. Qe3 Rfe8 20. Ng4 Kf8
21. Kb1 Re7 22. Qf2 Qh8 23. Qf3 Qg7 24. Qf2 Qh8 25. Qf3 Qg7 26. Qf2 {3-fold
repetition} 1/2-1/2
Here is the second game, playing with black.
1. g3 d5 2. Nf3 e6 3. Nc3 d4 4. Nb5 Nc6 5. e3 e5 6. exd4 exd4 7. c3 Bg4 8.
Qe2+ Be7 9. Nbxd4 Nxd4 10. cxd4 c6 11. Bg2 Bxf3 12. Bxf3 Qxd4 13. Qe3 O-O-O
14. Qxd4 Rxd4 15. h4 Nf6 16. b3 Rhd8 17. a4 Bb4 18. Ra2 Rd3 19. Bd1 Ne4 20.
Bg4+ Kb8 21. Bf5 Re8 22. O-O Bc5 23. Kg2 Rxb3 24. Bxh7 g6 25. Re1 Bxf2 26.
Rxe4 Rxe4 27. Kxf2 Rd3 28. Bg8 f5 29. Bh7 Rc4 30. Ra1 Rg4 31. h5 Rgxg3 32.
hxg6 Rg4 33. Ke2 Rd5 34. a5 Re5+ 35. Kf3 Rd5 36. Bg8 Rd6 37. Bf7 a6 38. Ra3
Rg1 39. Rc3 Rd8 40. d3 Rf1+ 41. Kg2 Re1 42. Kf2 Rh1 43. Bf4+ Ka8 44. g7 Rh4
45. Bc7 Rc8 46. g8=Q Rh2+ 47. Bxh2 b6 48. Qxc8 {Arena Adjudication. Illegal
move!} 1-0

There was a time when I actually thought that my program was pressing the game, but then as it is clear from the game, I have messed up with some move making issues which as of now I would be checking.

Look up "perft". It's the best way to find bugs in your move generation code and in your functions to make and undo moves.

Thanks for replying.

Can you comment on the speed of the engine when it take max 30 secs to play a move at 5 plys and further 5 plies at QSearch(Without MVV/LVA or any sorting).

I asked you this as I would like to know if I don't have anything terribly wrong going on.

I ran perft suite as my unit test suite, had no findings.

I think I have messed up some where in make moves that come from GUI through UCI protocol. May be its missing some checks and other feature.

I would check on those by printing some display boards.

30 seconds for depth 5 is absurdly slow these days, but I don't see much point in looking at the performance before you have implemented some very basic improvements. MVV/LVA in quiescence search is particularly critical.

How many nodes per second is your engine searching? Some people count calls to make_move, some people count calls to the recursive search functions; either one will do.

Thanks for the reply.
I setup this position r1bqkb1r/1p1p1ppp/p1n1p1n1/4P3/2B5/2N2N2/PP3PPP/R1BQR1K1 b kq - 0 9
In the first round, I didnot search in QSearch as the condition ply>=maxPly would fail and it wouldn't proceed with generation of Capture moves.
In the second round I added Qsearch with addition of 5 plys to search. So if at depth 5 it went to QSearch then it would search in Qsearch for 5+5 = 10 plys.
and got the following results on the first day and I also noted that my machine (Dell Studio Laptop was heated up pretty much).
Without QSearch.
[table]
[tr]
[td]Depth[/td]
[td]Nodes[/td]
[td]Time(msecs)[/td]
[td]kNodes/Sec[/td]
[/tr]
[tr]
[td]1[/td]
[td]36[/td]
[td]131[/td]
[td]0.27[/td]
[/tr]
[tr]
[td]2[/td]
[td]1757[/td]
[td]160[/td]
[td]10.98[/td]
[/tr]
[tr]
[td]3[/td]
[td]7689[/td]
[td]336[/td]
[td]22.88[/td]
[/tr]
[tr]
[td]4[/td]
[td]136953[/td]
[td]2743[/td]
[td]49.92[/td]
[/tr]
[tr]
[td]5[/td]
[td]604808[/td]
[td]17768[/td]
[td]34.039[/td]
[/tr]
[tr]
[td]6[/td]
[td]11339038[/td]
[td]207256[/td]
[td]54.71[/td]
[/tr]
[/table]
With QSearch
[table]
[tr]
[td]Depth[/td]
[td]Nodes[/td]
[td]Time(msecs)[/td]
[td]kNodes/Sec[/td]
[/tr]
[tr]
[td]1[/td]
[td]1087[/td]
[td]239[/td]
[td]4.54[/td]
[/tr]
[tr]
[td]2[/td]
[td]13289[/td]
[td]543[/td]
[td]24.47[/td]
[/tr]
[tr]
[td]3[/td]
[td]103435[/td]
[td]2864[/td]
[td]36.11[/td]
[/tr]
[tr]
[td]4[/td]
[td]1313863[/td]
[td]28137[/td]
[td]46.49[/td]
[/tr]
[tr]
[td]5[/td]
[td]7980765[/td]
[td]175669[/td]
[td]45.43[/td]
[/tr]
[tr]
[td]6[/td]
[td]57394529[/td]
[td]1266073[/td]
[td]45.33[/td]
[/tr]
[/table]
Here are the results after second day when laptop didn't heat up much.
Without QSearch.
[table]
[tr]
[td]Depth[/td]
[td]Nodes[/td]
[td]Time(msecs)[/td]
[td]kNodes/Sec[/td]
[/tr]
[tr]
[td]1[/td]
[td]36[/td]
[td]16[/td]
[td]2.25[/td]
[/tr]
[tr]
[td]2[/td]
[td]1757[/td]
[td]19[/td]
[td]92.47[/td]
[/tr]
[tr]
[td]3[/td]
[td]7689[/td]
[td]37[/td]
[td]207.81[/td]
[/tr]
[tr]
[td]4[/td]
[td]136953[/td]
[td]288[/td]
[td]475.53[/td]
[/tr]
[tr]
[td]5[/td]
[td]604808[/td]
[td]1742[/td]
[td]347.19[/td]
[/tr]
[/table]
With QSearch
[table]
[tr]
[td]Depth[/td]
[td]Nodes[/td]
[td]Time(msecs)[/td]
[td]kNodes/Sec[/td]
[/tr]
[tr]
[td]1[/td]
[td]1087[/td]
[td]17[/td]
[td]63.94[/td]
[/tr]
[tr]
[td]2[/td]
[td]13289[/td]
[td]43[/td]
[td]309.04[/td]
[/tr]
[tr]
[td]3[/td]
[td]103435[/td]
[td]242[/td]
[td]427.41[/td]
[/tr]
[tr]
[td]4[/td]
[td]1313863[/td]
[td]2715[/td]
[td]483.92[/td]
[/tr]
[tr]
[td]5[/td]
[td]7980765[/td]
[td]17249[/td]
[td]462.67[/td]
[/tr]
[/table]

I think this is a hardware + programming efficiency issue.

Please comment as to how can I improvise this.

This topic is closed to new replies.

Advertisement