mirror of
https://github.com/sockspls/badfish
synced 2025-05-16 23:49:35 +00:00
Fixes a Chess960 bug when playing with more than one search thread.
The init_eval() function corrupted the static array castleRightsMask[] in the Position class, resulting in instant crashes in most Chess960 games. Fixed by repairing the damage directly after the function is called. Also modified the Position::to_fen() function to display castle rights correctly for Chess960 positions, and added sanity checks for uncastled rook files in Position::is_ok().
This commit is contained in:
parent
43fa3a4d64
commit
290caf9960
2 changed files with 42 additions and 4 deletions
|
@ -270,11 +270,25 @@ const string Position::to_fen() const {
|
||||||
}
|
}
|
||||||
fen += (sideToMove == WHITE ? "w " : "b ");
|
fen += (sideToMove == WHITE ? "w " : "b ");
|
||||||
if (st->castleRights != NO_CASTLES)
|
if (st->castleRights != NO_CASTLES)
|
||||||
|
{
|
||||||
|
if (initialKFile == FILE_E && initialQRFile == FILE_A && initialKRFile == FILE_H)
|
||||||
{
|
{
|
||||||
if (can_castle_kingside(WHITE)) fen += 'K';
|
if (can_castle_kingside(WHITE)) fen += 'K';
|
||||||
if (can_castle_queenside(WHITE)) fen += 'Q';
|
if (can_castle_queenside(WHITE)) fen += 'Q';
|
||||||
if (can_castle_kingside(BLACK)) fen += 'k';
|
if (can_castle_kingside(BLACK)) fen += 'k';
|
||||||
if (can_castle_queenside(BLACK)) fen += 'q';
|
if (can_castle_queenside(BLACK)) fen += 'q';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (can_castle_kingside(WHITE))
|
||||||
|
fen += toupper(file_to_char(initialKRFile));
|
||||||
|
if (can_castle_queenside(WHITE))
|
||||||
|
fen += toupper(file_to_char(initialQRFile));
|
||||||
|
if (can_castle_kingside(BLACK))
|
||||||
|
fen += file_to_char(initialKRFile);
|
||||||
|
if (can_castle_queenside(BLACK))
|
||||||
|
fen += file_to_char(initialQRFile);
|
||||||
|
}
|
||||||
} else
|
} else
|
||||||
fen += '-';
|
fen += '-';
|
||||||
|
|
||||||
|
@ -1848,6 +1862,7 @@ bool Position::is_ok(int* failedStep) const {
|
||||||
static const bool debugNonPawnMaterial = false;
|
static const bool debugNonPawnMaterial = false;
|
||||||
static const bool debugPieceCounts = false;
|
static const bool debugPieceCounts = false;
|
||||||
static const bool debugPieceList = false;
|
static const bool debugPieceList = false;
|
||||||
|
static const bool debugCastleSquares = false;
|
||||||
|
|
||||||
if (failedStep) *failedStep = 1;
|
if (failedStep) *failedStep = 1;
|
||||||
|
|
||||||
|
@ -1984,6 +1999,25 @@ bool Position::is_ok(int* failedStep) const {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (failedStep) (*failedStep)++;
|
||||||
|
if (debugCastleSquares) {
|
||||||
|
for (Color c = WHITE; c <= BLACK; c++) {
|
||||||
|
if (can_castle_kingside(c) && piece_on(initial_kr_square(c)) != piece_of_color_and_type(c, ROOK))
|
||||||
|
return false;
|
||||||
|
if (can_castle_queenside(c) && piece_on(initial_qr_square(c)) != piece_of_color_and_type(c, ROOK))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (castleRightsMask[initial_kr_square(WHITE)] != (ALL_CASTLES ^ WHITE_OO))
|
||||||
|
return false;
|
||||||
|
if (castleRightsMask[initial_qr_square(WHITE)] != (ALL_CASTLES ^ WHITE_OOO))
|
||||||
|
return false;
|
||||||
|
if (castleRightsMask[initial_kr_square(BLACK)] != (ALL_CASTLES ^ BLACK_OO))
|
||||||
|
return false;
|
||||||
|
if (castleRightsMask[initial_qr_square(BLACK)] != (ALL_CASTLES ^ BLACK_OOO))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (failedStep) *failedStep = 0;
|
if (failedStep) *failedStep = 0;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -452,6 +452,10 @@ bool think(const Position& pos, bool infinite, bool ponder, int side_to_move,
|
||||||
{
|
{
|
||||||
ActiveThreads = newActiveThreads;
|
ActiveThreads = newActiveThreads;
|
||||||
init_eval(ActiveThreads);
|
init_eval(ActiveThreads);
|
||||||
|
// HACK: init_eval() destroys the static castleRightsMask[] array in the
|
||||||
|
// Position class. The below line repairs the damage.
|
||||||
|
Position p(pos.to_fen());
|
||||||
|
assert(pos.is_ok());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wake up sleeping threads
|
// Wake up sleeping threads
|
||||||
|
|
Loading…
Add table
Reference in a new issue