mirror of
https://github.com/sockspls/badfish
synced 2025-07-11 19:49:14 +00:00
Move PSQ score to Position
This patch simplifies Position::do_move() by moving the PSQ score from StateInfo to Position and updating it inside the put/remove/move_piece functions. The downside is that there is now slightly more computation done in Position::undo_move(), but the fishtest results are Elo neutral. Passed STC: LLR: 2.95 (-2.94,2.94) [-3.00,1.00] Total: 78820 W: 15775 L: 15760 D: 47285 http://tests.stockfishchess.org/tests/view/5b1cd1d00ebc5902ab9c64ab Passed LTC: LLR: 2.96 (-2.94,2.94) [-3.00,1.00] Total: 32966 W: 5716 L: 5615 D: 21635 http://tests.stockfishchess.org/tests/view/5b31e1230ebc5902b2e5a833 Closes https://github.com/official-stockfish/Stockfish/pull/1647 No functional change.
This commit is contained in:
parent
af6072c8b7
commit
a781535168
2 changed files with 9 additions and 18 deletions
|
@ -36,10 +36,6 @@
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
namespace PSQT {
|
|
||||||
extern Score psq[PIECE_NB][SQUARE_NB];
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace Zobrist {
|
namespace Zobrist {
|
||||||
|
|
||||||
Key psq[PIECE_NB][SQUARE_NB];
|
Key psq[PIECE_NB][SQUARE_NB];
|
||||||
|
@ -381,7 +377,6 @@ void Position::set_state(StateInfo* si) const {
|
||||||
si->key = si->materialKey = 0;
|
si->key = si->materialKey = 0;
|
||||||
si->pawnKey = Zobrist::noPawns;
|
si->pawnKey = Zobrist::noPawns;
|
||||||
si->nonPawnMaterial[WHITE] = si->nonPawnMaterial[BLACK] = VALUE_ZERO;
|
si->nonPawnMaterial[WHITE] = si->nonPawnMaterial[BLACK] = VALUE_ZERO;
|
||||||
si->psq = SCORE_ZERO;
|
|
||||||
si->checkersBB = attackers_to(square<KING>(sideToMove)) & pieces(~sideToMove);
|
si->checkersBB = attackers_to(square<KING>(sideToMove)) & pieces(~sideToMove);
|
||||||
|
|
||||||
set_check_info(si);
|
set_check_info(si);
|
||||||
|
@ -391,7 +386,6 @@ void Position::set_state(StateInfo* si) const {
|
||||||
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];
|
si->key ^= Zobrist::psq[pc][s];
|
||||||
si->psq += PSQT::psq[pc][s];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (si->epSquare != SQ_NONE)
|
if (si->epSquare != SQ_NONE)
|
||||||
|
@ -752,7 +746,6 @@ void Position::do_move(Move m, StateInfo& newSt, bool givesCheck) {
|
||||||
Square rfrom, rto;
|
Square rfrom, rto;
|
||||||
do_castling<true>(us, from, to, rfrom, rto);
|
do_castling<true>(us, from, to, rfrom, rto);
|
||||||
|
|
||||||
st->psq += PSQT::psq[captured][rto] - PSQT::psq[captured][rfrom];
|
|
||||||
k ^= Zobrist::psq[captured][rfrom] ^ Zobrist::psq[captured][rto];
|
k ^= Zobrist::psq[captured][rfrom] ^ Zobrist::psq[captured][rto];
|
||||||
captured = NO_PIECE;
|
captured = NO_PIECE;
|
||||||
}
|
}
|
||||||
|
@ -791,9 +784,6 @@ void Position::do_move(Move m, StateInfo& newSt, bool givesCheck) {
|
||||||
st->materialKey ^= Zobrist::psq[captured][pieceCount[captured]];
|
st->materialKey ^= Zobrist::psq[captured][pieceCount[captured]];
|
||||||
prefetch(thisThread->materialTable[st->materialKey]);
|
prefetch(thisThread->materialTable[st->materialKey]);
|
||||||
|
|
||||||
// Update incremental scores
|
|
||||||
st->psq -= PSQT::psq[captured][capsq];
|
|
||||||
|
|
||||||
// Reset rule 50 counter
|
// Reset rule 50 counter
|
||||||
st->rule50 = 0;
|
st->rule50 = 0;
|
||||||
}
|
}
|
||||||
|
@ -847,9 +837,6 @@ void Position::do_move(Move m, StateInfo& newSt, bool givesCheck) {
|
||||||
st->materialKey ^= Zobrist::psq[promotion][pieceCount[promotion]-1]
|
st->materialKey ^= Zobrist::psq[promotion][pieceCount[promotion]-1]
|
||||||
^ Zobrist::psq[pc][pieceCount[pc]];
|
^ Zobrist::psq[pc][pieceCount[pc]];
|
||||||
|
|
||||||
// Update incremental score
|
|
||||||
st->psq += PSQT::psq[promotion][to] - PSQT::psq[pc][to];
|
|
||||||
|
|
||||||
// Update material
|
// Update material
|
||||||
st->nonPawnMaterial[us] += PieceValue[MG][promotion];
|
st->nonPawnMaterial[us] += PieceValue[MG][promotion];
|
||||||
}
|
}
|
||||||
|
@ -862,9 +849,6 @@ void Position::do_move(Move m, StateInfo& newSt, bool givesCheck) {
|
||||||
st->rule50 = 0;
|
st->rule50 = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update incremental scores
|
|
||||||
st->psq += PSQT::psq[pc][to] - PSQT::psq[pc][from];
|
|
||||||
|
|
||||||
// Set capture piece
|
// Set capture piece
|
||||||
st->capturedPiece = captured;
|
st->capturedPiece = captured;
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,6 @@ struct StateInfo {
|
||||||
int castlingRights;
|
int castlingRights;
|
||||||
int rule50;
|
int rule50;
|
||||||
int pliesFromNull;
|
int pliesFromNull;
|
||||||
Score psq;
|
|
||||||
Square epSquare;
|
Square epSquare;
|
||||||
|
|
||||||
// Not copied when making a move (will be recomputed anyhow)
|
// Not copied when making a move (will be recomputed anyhow)
|
||||||
|
@ -188,11 +187,16 @@ private:
|
||||||
Bitboard castlingPath[CASTLING_RIGHT_NB];
|
Bitboard castlingPath[CASTLING_RIGHT_NB];
|
||||||
int gamePly;
|
int gamePly;
|
||||||
Color sideToMove;
|
Color sideToMove;
|
||||||
|
Score psq;
|
||||||
Thread* thisThread;
|
Thread* thisThread;
|
||||||
StateInfo* st;
|
StateInfo* st;
|
||||||
bool chess960;
|
bool chess960;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
namespace PSQT {
|
||||||
|
extern Score psq[PIECE_NB][SQUARE_NB];
|
||||||
|
}
|
||||||
|
|
||||||
extern std::ostream& operator<<(std::ostream& os, const Position& pos);
|
extern std::ostream& operator<<(std::ostream& os, const Position& pos);
|
||||||
|
|
||||||
inline Color Position::side_to_move() const {
|
inline Color Position::side_to_move() const {
|
||||||
|
@ -327,7 +331,7 @@ inline Key Position::material_key() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Score Position::psq_score() const {
|
inline Score Position::psq_score() const {
|
||||||
return st->psq;
|
return psq;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Value Position::non_pawn_material(Color c) const {
|
inline Value Position::non_pawn_material(Color c) const {
|
||||||
|
@ -384,6 +388,7 @@ inline void Position::put_piece(Piece pc, Square s) {
|
||||||
index[s] = pieceCount[pc]++;
|
index[s] = pieceCount[pc]++;
|
||||||
pieceList[pc][index[s]] = s;
|
pieceList[pc][index[s]] = s;
|
||||||
pieceCount[make_piece(color_of(pc), ALL_PIECES)]++;
|
pieceCount[make_piece(color_of(pc), ALL_PIECES)]++;
|
||||||
|
psq += PSQT::psq[pc][s];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void Position::remove_piece(Piece pc, Square s) {
|
inline void Position::remove_piece(Piece pc, Square s) {
|
||||||
|
@ -401,6 +406,7 @@ inline void Position::remove_piece(Piece pc, Square s) {
|
||||||
pieceList[pc][index[lastSquare]] = lastSquare;
|
pieceList[pc][index[lastSquare]] = lastSquare;
|
||||||
pieceList[pc][pieceCount[pc]] = SQ_NONE;
|
pieceList[pc][pieceCount[pc]] = SQ_NONE;
|
||||||
pieceCount[make_piece(color_of(pc), ALL_PIECES)]--;
|
pieceCount[make_piece(color_of(pc), ALL_PIECES)]--;
|
||||||
|
psq -= PSQT::psq[pc][s];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void Position::move_piece(Piece pc, Square from, Square to) {
|
inline void Position::move_piece(Piece pc, Square from, Square to) {
|
||||||
|
@ -415,6 +421,7 @@ inline void Position::move_piece(Piece pc, Square from, Square to) {
|
||||||
board[to] = pc;
|
board[to] = pc;
|
||||||
index[to] = index[from];
|
index[to] = index[from];
|
||||||
pieceList[pc][index[to]] = to;
|
pieceList[pc][index[to]] = to;
|
||||||
|
psq += PSQT::psq[pc][to] - PSQT::psq[pc][from];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void Position::do_move(Move m, StateInfo& newSt) {
|
inline void Position::do_move(Move m, StateInfo& newSt) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue