mirror of
https://github.com/opelly27/Stockfish.git
synced 2026-05-20 07:27:46 +00:00
Introduce pawn structure based history
Original idea by Seer chess engine https://github.com/connormcmonigle/seer-nnue, coding done by @Disservin, code refactoring done by @locutus2 to match the style of other histories. This patch introduces pawn structure based history, which assings moves values based on last digits of pawn structure hash and piece type of moved piece and landing square of the move. Idea is that good places for pieces are quite often determined by pawn structure of position. Used in 3 different places - sorting of quiet moves, sorting of quiet check evasions and in history based pruning in search. Passed STC: https://tests.stockfishchess.org/tests/view/65391d08cc309ae83955dbaf LLR: 2.95 (-2.94,2.94) <0.00,2.00> Total: 155488 W: 39408 L: 38913 D: 77167 Ptnml(0-2): 500, 18427, 39408, 18896, 513 Passed LTC: https://tests.stockfishchess.org/tests/view/653a36a2cc309ae83955f181 LLR: 2.94 (-2.94,2.94) <0.50,2.50> Total: 70110 W: 17548 L: 17155 D: 35407 Ptnml(0-2): 33, 7859, 18889, 8230, 44 closes https://github.com/official-stockfish/Stockfish/pull/4849 Bench: 1257882 Co-Authored-By: Disservin <disservin.social@gmail.com> Co-Authored-By: Stefan Geschwentner <locutus2@users.noreply.github.com>
This commit is contained in:
+14
-3
@@ -49,7 +49,7 @@ namespace Zobrist {
|
||||
Key psq[PIECE_NB][SQUARE_NB];
|
||||
Key enpassant[FILE_NB];
|
||||
Key castling[CASTLING_RIGHT_NB];
|
||||
Key side;
|
||||
Key side, noPawns;
|
||||
}
|
||||
|
||||
namespace {
|
||||
@@ -128,7 +128,8 @@ void Position::init() {
|
||||
for (int cr = NO_CASTLING; cr <= ANY_CASTLING; ++cr)
|
||||
Zobrist::castling[cr] = rng.rand<Key>();
|
||||
|
||||
Zobrist::side = rng.rand<Key>();
|
||||
Zobrist::side = rng.rand<Key>();
|
||||
Zobrist::noPawns = rng.rand<Key>();
|
||||
|
||||
// Prepare the cuckoo tables
|
||||
std::memset(cuckoo, 0, sizeof(cuckoo));
|
||||
@@ -337,6 +338,7 @@ void Position::set_check_info() const {
|
||||
void Position::set_state() const {
|
||||
|
||||
st->key = st->materialKey = 0;
|
||||
st->pawnKey = Zobrist::noPawns;
|
||||
st->nonPawnMaterial[WHITE] = st->nonPawnMaterial[BLACK] = VALUE_ZERO;
|
||||
st->checkersBB = attackers_to(square<KING>(sideToMove)) & pieces(~sideToMove);
|
||||
|
||||
@@ -348,7 +350,10 @@ void Position::set_state() const {
|
||||
Piece pc = piece_on(s);
|
||||
st->key ^= Zobrist::psq[pc][s];
|
||||
|
||||
if (type_of(pc) != KING && type_of(pc) != PAWN)
|
||||
if (type_of(pc) == PAWN)
|
||||
st->pawnKey ^= Zobrist::psq[pc][s];
|
||||
|
||||
else if (type_of(pc) != KING)
|
||||
st->nonPawnMaterial[color_of(pc)] += PieceValue[pc];
|
||||
}
|
||||
|
||||
@@ -728,6 +733,8 @@ void Position::do_move(Move m, StateInfo& newSt, bool givesCheck) {
|
||||
assert(piece_on(to) == NO_PIECE);
|
||||
assert(piece_on(capsq) == make_piece(them, PAWN));
|
||||
}
|
||||
|
||||
st->pawnKey ^= Zobrist::psq[captured][capsq];
|
||||
}
|
||||
else
|
||||
st->nonPawnMaterial[them] -= PieceValue[captured];
|
||||
@@ -806,6 +813,7 @@ void Position::do_move(Move m, StateInfo& newSt, bool givesCheck) {
|
||||
|
||||
// Update hash keys
|
||||
k ^= Zobrist::psq[pc][to] ^ Zobrist::psq[promotion][to];
|
||||
st->pawnKey ^= Zobrist::psq[pc][to];
|
||||
st->materialKey ^=
|
||||
Zobrist::psq[promotion][pieceCount[promotion] - 1] ^ Zobrist::psq[pc][pieceCount[pc]];
|
||||
|
||||
@@ -813,6 +821,9 @@ void Position::do_move(Move m, StateInfo& newSt, bool givesCheck) {
|
||||
st->nonPawnMaterial[us] += PieceValue[promotion];
|
||||
}
|
||||
|
||||
// Update pawn hash key
|
||||
st->pawnKey ^= Zobrist::psq[pc][from] ^ Zobrist::psq[pc][to];
|
||||
|
||||
// Reset rule 50 draw counter
|
||||
st->rule50 = 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user