Stockfish do_move + undo_move
Posted: Wed Jun 02, 2010 11:51 pm
I'm using Stockfish 1.7.1 and having issues with the improvements in position.cpp with do_move/undo_move. I have written tests for testing move orders using do_move and reversing them with undo_move. This works for non-capture moves. However, if a move is a capture move it can't update pieceList correctly if I'm right.
inside do_capture_move:
Performing the following moves using do_move, then detach (without st->previous = NULL). Then calling in reverse order the moves.
1. do_move using 1. e4 e5 2. Nf3 Nc6 3. Bb5 a6 4. Bxc6 bxc6 5. Nc3 h5
2. detach safely without st->previous = NULL
3. undo_move in reverse order h5, Nc3, and bxc6. bxc6 is a capture move, but does not correctly work.
After h5
After undo_move h5
After undo_move Nc3:
After undo_move bxc6 which is incorrect:
Is there a way to fix do_capture_move or undo_move to fix this issue accordingly?
inside do_capture_move:
Code: Select all
// Update piece list, move the last piece at index[capsq] position
//
// WARNING: This is a not perfectly revresible operation. When we
// will reinsert the captured piece in undo_move() we will put it
// at the end of the list and not in its original place, it means
// index[] and pieceList[] are not guaranteed to be invariant to a
// do_move() + undo_move() sequence.
Square lastPieceSquare = pieceList[them][capture][pieceCount[them][capture]];
index[lastPieceSquare] = index[capsq];
pieceList[them][capture][index[lastPieceSquare]] = lastPieceSquare;
pieceList[them][capture][pieceCount[them][capture]] = SQ_NONE;
1. do_move using 1. e4 e5 2. Nf3 Nc6 3. Bb5 a6 4. Bxc6 bxc6 5. Nc3 h5
2. detach safely without st->previous = NULL
3. undo_move in reverse order h5, Nc3, and bxc6. bxc6 is a capture move, but does not correctly work.
After h5
Code: Select all
+---+---+---+---+---+---+---+---+
|=R=| |=B=|=Q=|=K=|=B=|=N=|=R=|
+---+---+---+---+---+---+---+---+
| | . |=P=|=P=| |=P=|=P=| . |
+---+---+---+---+---+---+---+---+
|=P=| |=P=| | . | | . | |
+---+---+---+---+---+---+---+---+
| | . | | . |=P=| . | |=P=|
+---+---+---+---+---+---+---+---+
| . | | . | | P | | . | |
+---+---+---+---+---+---+---+---+
| | . | N | . | | N | | . |
+---+---+---+---+---+---+---+---+
| P | P | P | P | . | P | P | P |
+---+---+---+---+---+---+---+---+
| R | . | B | Q | K | . | | R |
+---+---+---+---+---+---+---+---+
Fen is: r1bqkbnr/2pp1pp1/p1p5/4p2p/4P3/2N2N2/PPPP1PPP/R1BQK2R w KQkq -
Key is: 18341137315284503223
Code: Select all
+---+---+---+---+---+---+---+---+
|=R=| |=B=|=Q=|=K=|=B=|=N=|=R=|
+---+---+---+---+---+---+---+---+
| | . |=P=|=P=| |=P=|=P=|=P=|
+---+---+---+---+---+---+---+---+
|=P=| |=P=| | . | | . | |
+---+---+---+---+---+---+---+---+
| | . | | . |=P=| . | | . |
+---+---+---+---+---+---+---+---+
| . | | . | | P | | . | |
+---+---+---+---+---+---+---+---+
| | . | N | . | | N | | . |
+---+---+---+---+---+---+---+---+
| P | P | P | P | . | P | P | P |
+---+---+---+---+---+---+---+---+
| R | . | B | Q | K | . | | R |
+---+---+---+---+---+---+---+---+
Fen is: r1bqkbnr/2pp1ppp/p1p5/4p3/4P3/2N2N2/PPPP1PPP/R1BQK2R b KQkq -
Key is: 18341137315284503223
Code: Select all
+---+---+---+---+---+---+---+---+
|=R=| |=B=|=Q=|=K=|=B=|=N=|=R=|
+---+---+---+---+---+---+---+---+
| | . |=P=|=P=| |=P=|=P=|=P=|
+---+---+---+---+---+---+---+---+
|=P=| |=P=| | . | | . | |
+---+---+---+---+---+---+---+---+
| | . | | . |=P=| . | | . |
+---+---+---+---+---+---+---+---+
| . | | . | | P | | . | |
+---+---+---+---+---+---+---+---+
| | . | | . | | N | | . |
+---+---+---+---+---+---+---+---+
| P | P | P | P | . | P | P | P |
+---+---+---+---+---+---+---+---+
| R | N | B | Q | K | . | | R |
+---+---+---+---+---+---+---+---+
Fen is: r1bqkbnr/2pp1ppp/p1p5/4p3/4P3/5N2/PPPP1PPP/RNBQK2R w KQkq -
Key is: 18341137315284503223
Code: Select all
+---+---+---+---+---+---+---+---+
|=R=| |=B=|=Q=|=K=|=B=|=N=|=R=|
+---+---+---+---+---+---+---+---+
| |=P=|=P=|=P=| |=P=|=P=|=P=|
+---+---+---+---+---+---+---+---+
|=P=| | . | | . | | . | |
+---+---+---+---+---+---+---+---+
| | . | | . |=P=| . | | . |
+---+---+---+---+---+---+---+---+
| . | | . | | P | | . | |
+---+---+---+---+---+---+---+---+
| | . | | . | | N | | . |
+---+---+---+---+---+---+---+---+
| P | P | P | P | . | P | P | P |
+---+---+---+---+---+---+---+---+
| R | N | B | Q | K | . | | R |
+---+---+---+---+---+---+---+---+
Fen is: r1bqkbnr/1ppp1ppp/p7/4p3/4P3/5N2/PPPP1PPP/RNBQK2R b KQkq -
Key is: 18341137315284503223