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

Remove 'si' StateInfo variable/parameter.

Since st is a member of position we don't need to pass it separately as
parameter.

While being there also remove some line in pos_is_ok, where
a copy of StateInfo was made by using default copy constructor and
then verified it's correctedness by doing a memcmp.
There is no point in doing that.

Passed non-regression test
https://tests.stockfishchess.org/tests/view/64098d562644b62c33942b35
LLR: 3.24 (-2.94,2.94) <-1.75,0.25>
Total: 548960 W: 145834 L: 146134 D: 256992
Ptnml(0-2): 1617, 57652, 156261, 57314, 1636

closes https://github.com/official-stockfish/Stockfish/pull/4444

No functional change
This commit is contained in:
pb00067 2023-03-13 18:32:40 +01:00 committed by Joost VandeVondele
parent af4b62a593
commit 02e4697055
2 changed files with 28 additions and 34 deletions

View file

@ -282,7 +282,7 @@ Position& Position::set(const string& fenStr, bool isChess960, StateInfo* si, Th
chess960 = isChess960; chess960 = isChess960;
thisThread = th; thisThread = th;
set_state(st); set_state();
assert(pos_is_ok()); assert(pos_is_ok());
@ -313,19 +313,19 @@ void Position::set_castling_right(Color c, Square rfrom) {
/// Position::set_check_info() sets king attacks to detect if a move gives check /// Position::set_check_info() sets king attacks to detect if a move gives check
void Position::set_check_info(StateInfo* si) const { void Position::set_check_info() const {
si->blockersForKing[WHITE] = slider_blockers(pieces(BLACK), square<KING>(WHITE), si->pinners[BLACK]); st->blockersForKing[WHITE] = slider_blockers(pieces(BLACK), square<KING>(WHITE), st->pinners[BLACK]);
si->blockersForKing[BLACK] = slider_blockers(pieces(WHITE), square<KING>(BLACK), si->pinners[WHITE]); st->blockersForKing[BLACK] = slider_blockers(pieces(WHITE), square<KING>(BLACK), st->pinners[WHITE]);
Square ksq = square<KING>(~sideToMove); Square ksq = square<KING>(~sideToMove);
si->checkSquares[PAWN] = pawn_attacks_bb(~sideToMove, ksq); st->checkSquares[PAWN] = pawn_attacks_bb(~sideToMove, ksq);
si->checkSquares[KNIGHT] = attacks_bb<KNIGHT>(ksq); st->checkSquares[KNIGHT] = attacks_bb<KNIGHT>(ksq);
si->checkSquares[BISHOP] = attacks_bb<BISHOP>(ksq, pieces()); st->checkSquares[BISHOP] = attacks_bb<BISHOP>(ksq, pieces());
si->checkSquares[ROOK] = attacks_bb<ROOK>(ksq, pieces()); st->checkSquares[ROOK] = attacks_bb<ROOK>(ksq, pieces());
si->checkSquares[QUEEN] = si->checkSquares[BISHOP] | si->checkSquares[ROOK]; st->checkSquares[QUEEN] = st->checkSquares[BISHOP] | st->checkSquares[ROOK];
si->checkSquares[KING] = 0; st->checkSquares[KING] = 0;
} }
@ -334,39 +334,39 @@ void Position::set_check_info(StateInfo* si) const {
/// The function is only used when a new position is set up, and to verify /// The function is only used when a new position is set up, and to verify
/// the correctness of the StateInfo data when running in debug mode. /// the correctness of the StateInfo data when running in debug mode.
void Position::set_state(StateInfo* si) const { void Position::set_state() const {
si->key = si->materialKey = 0; st->key = st->materialKey = 0;
si->pawnKey = Zobrist::noPawns; st->pawnKey = Zobrist::noPawns;
si->nonPawnMaterial[WHITE] = si->nonPawnMaterial[BLACK] = VALUE_ZERO; st->nonPawnMaterial[WHITE] = st->nonPawnMaterial[BLACK] = VALUE_ZERO;
si->checkersBB = attackers_to(square<KING>(sideToMove)) & pieces(~sideToMove); st->checkersBB = attackers_to(square<KING>(sideToMove)) & pieces(~sideToMove);
set_check_info(si); set_check_info();
for (Bitboard b = pieces(); b; ) for (Bitboard b = pieces(); b; )
{ {
Square s = pop_lsb(b); Square s = pop_lsb(b);
Piece pc = piece_on(s); Piece pc = piece_on(s);
si->key ^= Zobrist::psq[pc][s]; st->key ^= Zobrist::psq[pc][s];
if (type_of(pc) == PAWN) if (type_of(pc) == PAWN)
si->pawnKey ^= Zobrist::psq[pc][s]; st->pawnKey ^= Zobrist::psq[pc][s];
else if (type_of(pc) != KING) else if (type_of(pc) != KING)
si->nonPawnMaterial[color_of(pc)] += PieceValue[MG][pc]; st->nonPawnMaterial[color_of(pc)] += PieceValue[MG][pc];
} }
if (si->epSquare != SQ_NONE) if (st->epSquare != SQ_NONE)
si->key ^= Zobrist::enpassant[file_of(si->epSquare)]; st->key ^= Zobrist::enpassant[file_of(st->epSquare)];
if (sideToMove == BLACK) if (sideToMove == BLACK)
si->key ^= Zobrist::side; st->key ^= Zobrist::side;
si->key ^= Zobrist::castling[si->castlingRights]; st->key ^= Zobrist::castling[st->castlingRights];
for (Piece pc : Pieces) for (Piece pc : Pieces)
for (int cnt = 0; cnt < pieceCount[pc]; ++cnt) for (int cnt = 0; cnt < pieceCount[pc]; ++cnt)
si->materialKey ^= Zobrist::psq[pc][cnt]; st->materialKey ^= Zobrist::psq[pc][cnt];
} }
@ -865,7 +865,7 @@ void Position::do_move(Move m, StateInfo& newSt, bool givesCheck) {
sideToMove = ~sideToMove; sideToMove = ~sideToMove;
// Update king attacks used for fast check detection // Update king attacks used for fast check detection
set_check_info(st); set_check_info();
// Calculate the repetition info. It is the ply distance from the previous // Calculate the repetition info. It is the ply distance from the previous
// occurrence of the same position, negative in the 3-fold case, or zero // occurrence of the same position, negative in the 3-fold case, or zero
@ -1017,7 +1017,7 @@ void Position::do_null_move(StateInfo& newSt) {
sideToMove = ~sideToMove; sideToMove = ~sideToMove;
set_check_info(st); set_check_info();
st->repetition = 0; st->repetition = 0;
@ -1320,12 +1320,6 @@ bool Position::pos_is_ok() const {
if (p1 != p2 && (pieces(p1) & pieces(p2))) if (p1 != p2 && (pieces(p1) & pieces(p2)))
assert(0 && "pos_is_ok: Bitboards"); assert(0 && "pos_is_ok: Bitboards");
StateInfo si = *st;
ASSERT_ALIGNED(&si, Eval::NNUE::CacheLineSize);
set_state(&si);
if (std::memcmp(&si, st, sizeof(StateInfo)))
assert(0 && "pos_is_ok: State");
for (Piece pc : Pieces) for (Piece pc : Pieces)
if ( pieceCount[pc] != popcount(pieces(color_of(pc), type_of(pc))) if ( pieceCount[pc] != popcount(pieces(color_of(pc), type_of(pc)))

View file

@ -179,8 +179,8 @@ public:
private: private:
// Initialization helpers (used while setting up a position) // Initialization helpers (used while setting up a position)
void set_castling_right(Color c, Square rfrom); void set_castling_right(Color c, Square rfrom);
void set_state(StateInfo* si) const; void set_state() const;
void set_check_info(StateInfo* si) const; void set_check_info() const;
// Other helpers // Other helpers
void move_piece(Square from, Square to); void move_piece(Square from, Square to);