For H.G.Muller - bug in the qperft program.

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

Ratta

For H.G.Muller - bug in the qperft program.

Post by Ratta »

Hi, the following two positions are triggering bugs in your "qperft" program:

[d]K3k2r/2pnp3/1P2R3/1P1n4/B4p1p/8/p2PP1b1/8 w k - 0 0
gives the following (wrong) moves count:
perft(1)= 20 ( 0.000 sec)
perft(2)= 644 ( 0.000 sec)
perft(3)= 11000 ( 0.000 sec)
perft(4)= 357091 ( 0.000 sec)

The correct one (verified with my engine, my rewritten engine, Crafty, etc) is:
perft 1 20 (time 0.00)
perft 2 660 (time 0.00)
perft 3 11057 (time 0.00)
perft 4 364256 (time 0.02)

[d]nnn1nnn1/1PpPPP2/8/1P1k1PpR/rp4K1/8/2P5/8 w - g6 0 0
Is considered a bad fen, but it looks ok to me, and it is also ok for Crafty, xboard, and my nazist fen parser :)

I'm posting this bugs here for benefit of all the people that are using your perft program as reference for debugging their move generators, and so that you will be able to fix these bugs if you are using the same move generator in Joker or Fairy-Max.
Regards!
User avatar
hgm
Posts: 27808
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: For H.G.Muller - bug in the qperft program.

Post by hgm »

Interesting. When you take away black's castling rights in the FEN, perft(2) goes down by exactly 1, while you would expect that black can castle after about any white move.

If I split the perft, it turns out that the difference between having (black kingside) castling rights, and not having them, occurs after the move 1. Ka8-a7. When I do then a split one ply deeper, it turns out that the move that black gets extra through having castling rights is that it does....

Queenside castling with the white King! :shock: :shock: :shock:

Problem was in the FEN reader after all: it mixed up the castling rights, swapping Queen-side for King-side. If you 'castle' with the enemy King in the corner, you end up next to it, meaning you are in check, and that is of course illegal. So the King had to step away first: then you can safely 'castle' with the empty corner square, and an empty square can never check you... :lol: :lol: :lol:

Now the perft 1-3 are OK, but I still have a different perft(4), namely 363208. Can you give me a divided perft?
kongsian
Posts: 46
Joined: Thu Jun 15, 2006 11:21 am

Re: For H.G.Muller - bug in the qperft program.

Post by kongsian »

Hi H.G. Here is the divided perft 4

1/20 Ka7 23063
2/20 Kb7 21441
3/20 Re5 17611
4/20 Re4 18469
5/20 Re3 20082
6/20 Rd6 19432
7/20 Rc6 21350
8/20 Rf6 18334
9/20 Rg6 21361
10/20 Rh6 18368
11/20 Rxe7+ 1338
12/20 Bb3 19125
13/20 Bc2 20886
14/20 Bd1 16688
15/20 bxc7 16482
16/20 b7 20904
17/20 d3 17026
18/20 d4 16307
19/20 e3 17981
20/20 e4 18008
Total: 364256

Rgds
Kong Sian
User avatar
hgm
Posts: 27808
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: For H.G.Muller - bug in the qperft program.

Post by hgm »

OK, I finally had time to fix the final problem, of the perft(4). Again it was in the FEN reader:

I forgot to clear all castling spoilers in the piece list before reading the FEN. Pieces read from the initial position did overwrite their castling spoilers. But for empty entries, later used by promoted piees, they kept the castling spoiler of the previous position (the normal opening). The Pawn promoting here was so unlucky to occupy the position of an opening Rook after promotion. So the promotion spoiled the castling rights.

In the evrsion that is on my website now, this should be fixed. Also the reading of the second position, which was a bug in reading the e.p. square.