mirror of
https://github.com/sockspls/badfish
synced 2025-07-11 19:49:14 +00:00
Document index[] and pieceList[] are not invariants
Array index[] and pieceList[] are not guaranteed to be invariant to a do_move() + undo_move() sequence when a capture move is involved. The reason is that the captured piece is removed form the list and substituted with the last one in do_move() while in undo_move() is added again but at the end of the list. Because index[] and pieceList[] are used in move generation to scan the pieces it means that moves will be generated in a different order before and after a do_move() + undo_move() sequence as, for instance, the one in Position::has_mate_threat() After latest patches, move generation could now be invoked also by MovePicker c'tor and this explains why order of picked moves is different if MovePicker object is istantiated before or after a Position::has_mate_threat() call. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
af220cfd52
commit
97dd7568ed
1 changed files with 6 additions and 0 deletions
|
@ -939,6 +939,12 @@ void Position::do_capture_move(Bitboard& key, PieceType capture, Color them, Squ
|
|||
pieceCount[them][capture]--;
|
||||
|
||||
// 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;
|
||||
|
|
Loading…
Add table
Reference in a new issue