mirror of
https://github.com/sockspls/badfish
synced 2025-05-02 09:39:36 +00:00
Further simplify castling rights
Reverse the meaning of castleRightsMask[sq] so that now is stored the castling right that will be removed in case a move starts from or arrives to sq square. This allows to simplify the code. No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
50edb7cd73
commit
6a48325c49
1 changed files with 12 additions and 25 deletions
|
@ -247,8 +247,8 @@ void Position::set_castle_right(Color c, Square rsq) {
|
||||||
int f = (rsq < king_square(c) ? WHITE_OOO : WHITE_OO) << c;
|
int f = (rsq < king_square(c) ? WHITE_OOO : WHITE_OO) << c;
|
||||||
|
|
||||||
st->castleRights |= f;
|
st->castleRights |= f;
|
||||||
castleRightsMask[king_square(c)] ^= f;
|
castleRightsMask[king_square(c)] |= f;
|
||||||
castleRightsMask[rsq] ^= f;
|
castleRightsMask[rsq] |= f;
|
||||||
castleRookSquare[f] = rsq;
|
castleRookSquare[f] = rsq;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -840,12 +840,11 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update castle rights if needed
|
// Update castle rights if needed
|
||||||
if ( st->castleRights != CASTLES_NONE
|
if (st->castleRights && (castleRightsMask[from] | castleRightsMask[to]))
|
||||||
&& (castleRightsMask[from] & castleRightsMask[to]) != ALL_CASTLES)
|
|
||||||
{
|
{
|
||||||
int cr = castleRightsMask[from] & castleRightsMask[to];
|
int cr = castleRightsMask[from] | castleRightsMask[to];
|
||||||
k ^= zobCastle[st->castleRights & (cr ^ ALL_CASTLES)];
|
k ^= zobCastle[st->castleRights & cr];
|
||||||
st->castleRights &= cr;
|
st->castleRights &= ~cr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prefetch TT access as soon as we know key is updated
|
// Prefetch TT access as soon as we know key is updated
|
||||||
|
@ -1151,9 +1150,8 @@ void Position::do_castle_move(Move m) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update castling rights
|
// Update castling rights
|
||||||
int cr = castleRightsMask[kfrom];
|
st->key ^= zobCastle[st->castleRights & castleRightsMask[kfrom]];
|
||||||
st->key ^= zobCastle[st->castleRights & (cr ^ ALL_CASTLES)];
|
st->castleRights &= ~castleRightsMask[kfrom];
|
||||||
st->castleRights &= cr;
|
|
||||||
|
|
||||||
// Update checkers BB
|
// Update checkers BB
|
||||||
st->checkersBB = attackers_to(king_square(~us)) & pieces(us);
|
st->checkersBB = attackers_to(king_square(~us)) & pieces(us);
|
||||||
|
@ -1337,27 +1335,16 @@ int Position::see(Move m) const {
|
||||||
|
|
||||||
void Position::clear() {
|
void Position::clear() {
|
||||||
|
|
||||||
|
memset(this, 0, sizeof(Position));
|
||||||
|
startState.epSquare = SQ_NONE;
|
||||||
st = &startState;
|
st = &startState;
|
||||||
memset(st, 0, sizeof(StateInfo));
|
|
||||||
st->epSquare = SQ_NONE;
|
|
||||||
|
|
||||||
memset(byColorBB, 0, sizeof(Bitboard) * 2);
|
|
||||||
memset(byTypeBB, 0, sizeof(Bitboard) * 8);
|
|
||||||
memset(pieceCount, 0, sizeof(int) * 2 * 8);
|
|
||||||
memset(index, 0, sizeof(int) * 64);
|
|
||||||
|
|
||||||
for (int i = 0; i < 8; i++)
|
for (int i = 0; i < 8; i++)
|
||||||
for (int j = 0; j < 16; j++)
|
for (int j = 0; j < 16; j++)
|
||||||
pieceList[0][i][j] = pieceList[1][i][j] = SQ_NONE;
|
pieceList[0][i][j] = pieceList[1][i][j] = SQ_NONE;
|
||||||
|
|
||||||
for (Square sq = SQ_A1; sq <= SQ_H8; sq++)
|
for (Square sq = SQ_A1; sq <= SQ_H8; sq++)
|
||||||
{
|
|
||||||
board[sq] = NO_PIECE;
|
board[sq] = NO_PIECE;
|
||||||
castleRightsMask[sq] = ALL_CASTLES;
|
|
||||||
}
|
|
||||||
sideToMove = WHITE;
|
|
||||||
nodes = 0;
|
|
||||||
occupied = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1776,8 +1763,8 @@ bool Position::pos_is_ok(int* failedStep) const {
|
||||||
|
|
||||||
Piece rook = (f & (WHITE_OO | WHITE_OOO) ? W_ROOK : B_ROOK);
|
Piece rook = (f & (WHITE_OO | WHITE_OOO) ? W_ROOK : B_ROOK);
|
||||||
|
|
||||||
if ( castleRightsMask[castleRookSquare[f]] != (ALL_CASTLES ^ f)
|
if ( piece_on(castleRookSquare[f]) != rook
|
||||||
|| piece_on(castleRookSquare[f]) != rook)
|
|| castleRightsMask[castleRookSquare[f]] != f)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue