Skip to content

Commit

Permalink
Some history fixes and tidy-up
Browse files Browse the repository at this point in the history
This adds the functions `update_refutations` and `update_quiet_histories` to better distinguish the two. `update_quiet_stats` now just calls both of these functions.

The functional side of this patch is two-fold:
1. Stop refutations being updated when we carry out multicut
2. Update pawn history every time we update other quiet histories

Yellow STC:
LLR: -2.95 (-2.94,2.94) <0.00,2.00>
Total: 238976 W: 61506 L: 61415 D: 116055
Ptnml(0-2): 846, 28628, 60456, 28705, 853
https://tests.stockfishchess.org/tests/view/66321b5ed01fb9ac9bcdca83

However, it passed in <-1.75, 0.25> bounds:
$ python3 sprt.py --wins 61506 --losses 61415 --draws 116055 --elo0 -1.75 --elo1 0.25
ELO: 0.132 +- 0.998 [-0.865, 1.13]
LLR: 4.15 [-1.75, 0.25] (-2.94, 2.94)
H1 Accepted

Passed LTC:
LLR: 2.94 (-2.94,2.94) <-1.75,0.25>
Total: 399126 W: 100730 L: 100896 D: 197500
Ptnml(0-2): 116, 44328, 110843, 44158, 118
https://tests.stockfishchess.org/tests/view/66357b0473559a8aa857ba6f

closes official-stockfish#5215

Bench 2370967
  • Loading branch information
cj5716 authored and vondele committed May 5, 2024
1 parent d712ed3 commit 6da1590
Showing 1 changed file with 28 additions and 23 deletions.
51 changes: 28 additions & 23 deletions src/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,11 @@ Value value_to_tt(Value v, int ply);
Value value_from_tt(Value v, int ply, int r50c);
void update_pv(Move* pv, Move move, const Move* childPv);
void update_continuation_histories(Stack* ss, Piece pc, Square to, int bonus);
void update_quiet_stats(
void update_refutations(const Position& pos, Stack* ss, Search::Worker& workerThread, Move move);
void update_quiet_histories(
const Position& pos, Stack* ss, Search::Worker& workerThread, Move move, int bonus);
void update_quiet_stats(
const Position& pos, Stack* ss, Search::Worker& workerThread, Move move, int bonus);
void update_all_stats(const Position& pos,
Stack* ss,
Search::Worker& workerThread,
Expand Down Expand Up @@ -1068,7 +1071,7 @@ Value Search::Worker::search(
else if (singularBeta >= beta)
{
if (!ttCapture)
update_quiet_stats(pos, ss, *this, ttMove, -stat_malus(depth));
update_quiet_histories(pos, ss, *this, ttMove, -stat_malus(depth));

return singularBeta;
}
Expand Down Expand Up @@ -1724,7 +1727,6 @@ void update_all_stats(const Position& pos,
int captureCount,
Depth depth) {

Color us = pos.side_to_move();
CapturePieceToHistory& captureHistory = workerThread.captureHistory;
Piece moved_piece = pos.moved_piece(bestMove);
PieceType captured;
Expand All @@ -1737,23 +1739,11 @@ void update_all_stats(const Position& pos,
int bestMoveBonus = bestValue > beta + 185 ? quietMoveBonus // larger bonus
: stat_bonus(depth); // smaller bonus

// Increase stats for the best move in case it was a quiet move
update_quiet_stats(pos, ss, workerThread, bestMove, bestMoveBonus);

int pIndex = pawn_structure_index(pos);
workerThread.pawnHistory[pIndex][moved_piece][bestMove.to_sq()] << quietMoveBonus;

// Decrease stats for all non-best quiet moves
for (int i = 0; i < quietCount; ++i)
{
workerThread
.pawnHistory[pIndex][pos.moved_piece(quietsSearched[i])][quietsSearched[i].to_sq()]
<< -quietMoveMalus;

workerThread.mainHistory[us][quietsSearched[i].from_to()] << -quietMoveMalus;
update_continuation_histories(ss, pos.moved_piece(quietsSearched[i]),
quietsSearched[i].to_sq(), -quietMoveMalus);
}
update_quiet_histories(pos, ss, workerThread, quietsSearched[i], -quietMoveMalus);
}
else
{
Expand Down Expand Up @@ -1794,10 +1784,8 @@ void update_continuation_histories(Stack* ss, Piece pc, Square to, int bonus) {
}
}


// Updates move sorting heuristics
void update_quiet_stats(
const Position& pos, Stack* ss, Search::Worker& workerThread, Move move, int bonus) {
void update_refutations(const Position& pos, Stack* ss, Search::Worker& workerThread, Move move) {

// Update killers
if (ss->killers[0] != move)
Expand All @@ -1806,17 +1794,34 @@ void update_quiet_stats(
ss->killers[0] = move;
}

Color us = pos.side_to_move();
workerThread.mainHistory[us][move.from_to()] << bonus;
update_continuation_histories(ss, pos.moved_piece(move), move.to_sq(), bonus);

// Update countermove history
if (((ss - 1)->currentMove).is_ok())
{
Square prevSq = ((ss - 1)->currentMove).to_sq();
workerThread.counterMoves[pos.piece_on(prevSq)][prevSq] = move;
}
}

void update_quiet_histories(
const Position& pos, Stack* ss, Search::Worker& workerThread, Move move, int bonus) {

Color us = pos.side_to_move();
workerThread.mainHistory[us][move.from_to()] << bonus;

update_continuation_histories(ss, pos.moved_piece(move), move.to_sq(), bonus);

int pIndex = pawn_structure_index(pos);
workerThread.pawnHistory[pIndex][pos.moved_piece(move)][move.to_sq()] << bonus;
}

// Updates move sorting heuristics
void update_quiet_stats(
const Position& pos, Stack* ss, Search::Worker& workerThread, Move move, int bonus) {

update_refutations(pos, ss, workerThread, move);
update_quiet_histories(pos, ss, workerThread, move, bonus);
}

}

// When playing with strength handicap, choose the best move among a set of RootMoves
Expand Down

0 comments on commit 6da1590

Please sign in to comment.