1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-04-30 08:43:09 +00:00

Fix a bug in Position::is_ok()

If we cannot castle castleRightsMask[] could be not valid,
for instance when king initial file is FILE_A as queen rook.

In this case castleRightsMask[] at initialQRFile is different
from the expected (ALL_CASTLES ^ WHITE_OOO).

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba 2011-06-26 11:42:58 +01:00
parent ae2f5f25cd
commit 9305983018

View file

@ -2039,6 +2039,10 @@ bool Position::is_ok(int* failedStep) const {
if (can_castle_queenside(c) && piece_on(initial_qr_square(c)) != make_piece(c, ROOK))
return false;
}
// If we cannot castle castleRightsMask[] could be not valid, for instance when
// king initial file is FILE_A as queen rook.
if (can_castle(WHITE) || can_castle(BLACK))
{
if (castleRightsMask[initial_kr_square(WHITE)] != (ALL_CASTLES ^ WHITE_OO))
return false;
if (castleRightsMask[initial_qr_square(WHITE)] != (ALL_CASTLES ^ WHITE_OOO))
@ -2048,6 +2052,7 @@ bool Position::is_ok(int* failedStep) const {
if (castleRightsMask[initial_qr_square(BLACK)] != (ALL_CASTLES ^ BLACK_OOO))
return false;
}
}
if (failedStep) *failedStep = 0;
return true;