Thursday, 22 March 2007

Frustrantion, anger and despression!

Vicki kept on getting beaten over the knuckles by Windows (invalid operation) and after hours of debugging, I've detected a nasty error occurring with the piece lists. For some unknown reason, black pieces landed in the white lists and white pieces landed in the black lists. This caused a problem when the makeMove() method tried to remove a white piece from the white list and the white piece happened to be in the black list (something like a naughty boy being caught in the girl's dormitory!).

The can only happen is if a piece captures another piece of the same colour, but surely, that cannot happen. The move generation carefully checks such scenarios. Yet, after generating over 600,000 random games of 10 moves each from the following starting position,
"r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 1", the following happened:

+---+---+---+---+---+---+---+---+
8 | | r | B | | k | . | | |
+---+---+---+---+---+---+---+---+
7 | . | . | p | N | q | p | b | |
+---+---+---+---+---+---+---+---+
6 | . | . | . | . | p | n | p | . |
+---+---+---+---+---+---+---+---+
5 | p | N | . | P | . | . | . | . |
+---+---+---+---+---+---+---+---+
4 | | p | n | . | P | . | P | r |
+---+---+---+---+---+---+---+---+
3 | . | . | . | . | . | Q | . | p |
+---+---+---+---+---+---+---+---+
2 | P | P | P | B | . | P | . | P |
+---+---+---+---+---+---+---+---+
1 | R | . | . | . | K | . | . | R |
+---+---+---+---+---+---+---+---+
a b c d e f g h

In the above position, Vicki generated the move c8xd7 (capturing it's own knight) ??? I took the FEN-string from the above position and passed it through the move generator by itself. It did not generate the self-capture move, which means somewhere something is messing up the board.

What I really don't understand is that perft(7) gave a valid move count, without any crashes (from the standard opening position), which make me think that promotion may have something to do with it - yet, I did ran a test for promotions and it worked fine! What is going on?

No comments: