Creating a debugging tool for chess engine.

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

Colin

Re: Creating a debugging tool for chess engine.

Post by Colin »

Thanks, some good advice there.
To me, it seems like a hybrid method is a pain in the ***, and would only give a small speed up, but I'm using java, so I really need that extra speed.

Do professional chess programs general use this hybrid method?

I don't know what perft is, but I keep seeing the name come up.

Thanks
User avatar
hgm
Posts: 27796
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Creating a debugging tool for chess engine.

Post by hgm »

I'm not sure what 'professional' means. Commercial Chess programs are generally not open source, so we don't know what they use.

My engines only use mailbox (8x16 board, with or without piece list), because uMax is designed for simplicity, and Joker is designed for speed.

perft is the count of (legal) leave nodes (excluding QS) that you get for a fixed-depth search of a given depth (disabling all extensions, reductions and prunings). In particular disabling the beta cutoffs. So from the opening:

perft(1)=20
perft(2)=400
etc.

It is a very sensitive way of testing your move generation, sorting and make/unmake logic, as a search of 6-8 ply is usually able to set up all kind of tricky exceptions, like pinnings during e.p. captures, castlings while in check, etc.

These perft counts are purely defined by the rules of chess, and independent of the engine implementation, so you can immediately spot errors by comparing your numbers with what they should be. And if you have errors, zoom in on them by specifying the total count by move, so that you know in which branch the error occurs.
Uri Blass
Posts: 10282
Joined: Thu Mar 09, 2006 12:37 am
Location: Tel-Aviv Israel

Re: Creating a debugging tool for chess engine.

Post by Uri Blass »

hgm wrote:I'm not sure what 'professional' means. Commercial Chess programs are generally not open source, so we don't know what they use.

My engines only use mailbox (8x16 board, with or without piece list), because uMax is designed for simplicity, and Joker is designed for speed.

perft is the count of (legal) leave nodes (excluding QS) that you get for a fixed-depth search of a given depth (disabling all extensions, reductions and prunings). In particular disabling the beta cutoffs. So from the opening:

perft(1)=20
perft(2)=400
etc.

It is a very sensitive way of testing your move generation, sorting and make/unmake logic, as a search of 6-8 ply is usually able to set up all kind of tricky exceptions, like pinnings during e.p. captures, castlings while in check, etc.

These perft counts are purely defined by the rules of chess, and independent of the engine implementation, so you can immediately spot errors by comparing your numbers with what they should be. And if you have errors, zoom in on them by specifying the total count by move, so that you know in which branch the error occurs.
Note that movei has command that I call perftpgn

If you have some pgn file in the folder that include the exe file of movei(let call it xxx.pgn) then you can run movei in console mode and print perftpgn xxx.pgn 3 and get the sum of perft 3 for all positions in the pgn.

If you want to debug joker (or someone else want to verify no bugs in his program) then you can try to write similiar tool and compare your numbers with the numbers that movei is going to get.

Uri
Colin

Re: Creating a debugging tool for chess engine.

Post by Colin »

I seem to have fixed engine now, I've run across an interesting chess miniature, thats mate in 5(white to play)

I haven't worked out how to display a board on here yet.
So I've done it with numbers

From the position, 1=pawn,2=knight,3=king,5=bish,6=rook,7=queen.

0 0-6 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 5 0 0 0 0 0 0
0 0 0 0 0 0 0 0
-1 0-1 0 0 0 0 0
-3 0 3-5 0 0 0 0

D=1 BM=Bc5 V=-764 C=10 PV=Bc5[1]
D=2 BM=Bd6 V=-768 C=58 PV=Bd6 --> Rc3[2]
D=3 BM=Be7 V=-767 C=247 PV=Be7 --> Rc3 --> Bc5[3]
D=4 BM=Ba3 V=-767 C=1427 PV=Ba3 --> Rb8 --> Bc5 --> Rb2[4]
D=5 BM=Be7 V=-766 C=5572 PV=Be7 --> Rc6 --> Bb4 --> Rc7 --> Bc5[5]
D=6 BM=Be7 V=-767 C=22609 PV=Be7 --> Rc6 --> Bd6 --> Rc8 --> Be5 --> Rc3[6]
D=7 BM=Be7 V=-265 C=60557 PV=Be7 --> Rc6 --> Bd6 --> Rc8 --> Be5 --> Rc3 --> Bxc3[7]
D=8 BM=Be7 V=0 C=408396 PV=Be7 --> Rc6 --> Bd6 --> Rxd6[4]
D=9 BM=Be7 V=0 C=1235249 PV=Be7 --> Rc6 --> Bd6 --> Rxd6[4]
D=10 BM=Bd6 V=1000001 C=10212634 PV=Bd6 --> Re8 --> Bc5 --> Rd8 --> Be7 --> Rb8 --> Bf6 --> Rb2 --> Bxb2[9]

On depths 8 and 9 it spots stalemate, seems a little weird since the principle variation is only 4 moves long, but on depth 10, it gets the checkmate, as indicated by the score 1000001.
Does this look right?
jwes
Posts: 778
Joined: Sat Jul 01, 2006 7:11 am

Re: Creating a debugging tool for chess engine.

Post by jwes »

Colin wrote:I seem to have fixed engine now, I've run across an interesting chess miniature, thats mate in 5(white to play)

I haven't worked out how to display a board on here yet.
So I've done it with numbers

From the position, 1=pawn,2=knight,3=king,5=bish,6=rook,7=queen.

0 0-6 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 5 0 0 0 0 0 0
0 0 0 0 0 0 0 0
-1 0-1 0 0 0 0 0
-3 0 3-5 0 0 0 0

D=1 BM=Bc5 V=-764 C=10 PV=Bc5[1]
D=2 BM=Bd6 V=-768 C=58 PV=Bd6 --> Rc3[2]
D=3 BM=Be7 V=-767 C=247 PV=Be7 --> Rc3 --> Bc5[3]
D=4 BM=Ba3 V=-767 C=1427 PV=Ba3 --> Rb8 --> Bc5 --> Rb2[4]
D=5 BM=Be7 V=-766 C=5572 PV=Be7 --> Rc6 --> Bb4 --> Rc7 --> Bc5[5]
D=6 BM=Be7 V=-767 C=22609 PV=Be7 --> Rc6 --> Bd6 --> Rc8 --> Be5 --> Rc3[6]
D=7 BM=Be7 V=-265 C=60557 PV=Be7 --> Rc6 --> Bd6 --> Rc8 --> Be5 --> Rc3 --> Bxc3[7]
D=8 BM=Be7 V=0 C=408396 PV=Be7 --> Rc6 --> Bd6 --> Rxd6[4]
D=9 BM=Be7 V=0 C=1235249 PV=Be7 --> Rc6 --> Bd6 --> Rxd6[4]
D=10 BM=Bd6 V=1000001 C=10212634 PV=Bd6 --> Re8 --> Bc5 --> Rd8 --> Be7 --> Rb8 --> Bf6 --> Rb2 --> Bxb2[9]

On depths 8 and 9 it spots stalemate, seems a little weird since the principle variation is only 4 moves long, but on depth 10, it gets the checkmate, as indicated by the score 1000001.
Does this look right?
put [D] before the fen, e.g.
[D]2r5/8/8/8/1B6/8/p1p5/k1Kb4 w - - 0 1
Try forcing Bd6 and see if it mates in 8 ply.
User avatar
hgm
Posts: 27796
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Creating a debugging tool for chess engine.

Post by hgm »

It does depend on how your engine detects stalemate and checkmate. Can the side that is checkmated detect this at d=0? Then you should see it from this position at d=9. If he happily stands pat, and only realizes he is checkmated after trying all moves at d=1, and finding them illegal, then you owuld need indeed d=10. On a King-capture engine you owould need 11 ply, but the 11th ply (the capture of the King) is usually recognized in QS, so d=10 would still be good enough.

That it sees the 4-ply stalemate only at d=8 is because it only prefers that stalemate after 1. Be7 once it sees the 7-ply checkmate after 1. ..., Rc6; 2. Bd6, Rc5; 3. Bxc5, B??; 4. Bd4#. Apparently it needs d=8 to see that; as long as the mate is not recognized black is still two Pawns ahead, so it will avoid stalemate.