Skip to content

Commit

Permalink
bench 1350473
Browse files Browse the repository at this point in the history
  • Loading branch information
Vizvezdenec committed Sep 14, 2024
1 parent f677aee commit f15e170
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 15 deletions.
11 changes: 9 additions & 2 deletions src/movepick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,20 @@ MovePicker::MovePicker(const Position& p,
Move ttm,
Depth d,
const ButterflyHistory* mh,
const ButterflyHistory* rh,
const CapturePieceToHistory* cph,
const PieceToHistory** ch,
const PawnHistory* ph) :
const PawnHistory* ph,
bool rn) :
pos(p),
mainHistory(mh),
rootHistory(rh),
captureHistory(cph),
continuationHistory(ch),
pawnHistory(ph),
ttMove(ttm),
depth(d) {
depth(d),
rootNode(rn) {

if (pos.checkers())
stage = EVASION_TT + !(ttm && pos.pseudo_legal(ttm));
Expand Down Expand Up @@ -174,6 +178,9 @@ void MovePicker::score() {
m.value -= (pt == QUEEN ? bool(to & threatenedByRook) * 49000
: pt == ROOK ? bool(to & threatenedByMinor) * 24335
: bool(to & threatenedByPawn) * 14900);

if (rootNode)
m.value += 4 * (*rootHistory)[pos.side_to_move()][m.from_to()];
}

else // Type == EVASIONS
Expand Down
6 changes: 5 additions & 1 deletion src/movepick.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,11 @@ class MovePicker {
Move,
Depth,
const ButterflyHistory*,
const ButterflyHistory*,
const CapturePieceToHistory*,
const PieceToHistory**,
const PawnHistory*);
const PawnHistory*,
bool);
MovePicker(const Position&, Move, int, const CapturePieceToHistory*);
Move next_move(bool skipQuiets = false);

Expand All @@ -187,6 +189,7 @@ class MovePicker {

const Position& pos;
const ButterflyHistory* mainHistory;
const ButterflyHistory* rootHistory;
const CapturePieceToHistory* captureHistory;
const PieceToHistory** continuationHistory;
const PawnHistory* pawnHistory;
Expand All @@ -195,6 +198,7 @@ class MovePicker {
int stage;
int threshold;
Depth depth;
bool rootNode;
ExtMove moves[MAX_MOVES];
};

Expand Down
31 changes: 19 additions & 12 deletions src/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,16 @@ 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_histories(
const Position& pos, Stack* ss, Search::Worker& workerThread, Move move, int bonus);
const Position& pos, Stack* ss, Search::Worker& workerThread, Move move, int bonus, bool rootNode);
void update_all_stats(const Position& pos,
Stack* ss,
Search::Worker& workerThread,
Move bestMove,
Square prevSq,
ValueList<Move, 32>& quietsSearched,
ValueList<Move, 32>& capturesSearched,
Depth depth);
Depth depth,
bool rootNode);

} // namespace

Expand Down Expand Up @@ -264,6 +265,8 @@ void Search::Worker::iterative_deepening() {

int searchAgainCounter = 0;

rootHistory.fill(0);

// Iterative deepening loop until requested to stop or the target depth is reached
while (++rootDepth < MAX_PLY && !threads.stop
&& !(limits.depth && mainThread && rootDepth > limits.depth))
Expand Down Expand Up @@ -488,6 +491,7 @@ void Search::Worker::iterative_deepening() {
// Reset histories, usually before a new game
void Search::Worker::clear() {
mainHistory.fill(0);
rootHistory.fill(0);
captureHistory.fill(-700);
pawnHistory.fill(-1188);
pawnCorrectionHistory.fill(0);
Expand Down Expand Up @@ -622,7 +626,7 @@ Value Search::Worker::search(
{
// Bonus for a quiet ttMove that fails high (~2 Elo)
if (!ttCapture)
update_quiet_histories(pos, ss, *this, ttData.move, stat_bonus(depth));
update_quiet_histories(pos, ss, *this, ttData.move, stat_bonus(depth), rootNode);

// Extra penalty for early quiet moves of
// the previous ply (~1 Elo on STC, ~2 Elo on LTC)
Expand Down Expand Up @@ -912,8 +916,8 @@ Value Search::Worker::search(
(ss - 6)->continuationHistory};


MovePicker mp(pos, ttData.move, depth, &thisThread->mainHistory, &thisThread->captureHistory,
contHist, &thisThread->pawnHistory);
MovePicker mp(pos, ttData.move, depth, &thisThread->mainHistory, &thisThread->rootHistory, &thisThread->captureHistory,
contHist, &thisThread->pawnHistory, rootNode);

value = bestValue;

Expand Down Expand Up @@ -1339,7 +1343,7 @@ Value Search::Worker::search(
// If there is a move that produces search value greater than alpha,
// we update the stats of searched moves.
else if (bestMove)
update_all_stats(pos, ss, *this, bestMove, prevSq, quietsSearched, capturesSearched, depth);
update_all_stats(pos, ss, *this, bestMove, prevSq, quietsSearched, capturesSearched, depth, rootNode);

// Bonus for prior countermove that caused the fail low
else if (!priorCapture && prevSq != SQ_NONE)
Expand Down Expand Up @@ -1533,8 +1537,8 @@ Value Search::Worker::qsearch(Position& pos, Stack* ss, Value alpha, Value beta)
// Initialize a MovePicker object for the current position, and prepare to search
// the moves. We presently use two stages of move generator in quiescence search:
// captures, or evasions only when in check.
MovePicker mp(pos, ttData.move, DEPTH_QS, &thisThread->mainHistory, &thisThread->captureHistory,
contHist, &thisThread->pawnHistory);
MovePicker mp(pos, ttData.move, DEPTH_QS, &thisThread->mainHistory, &thisThread->rootHistory, &thisThread->captureHistory,
contHist, &thisThread->pawnHistory, nodeType == Root);

// Step 5. Loop through all pseudo-legal moves until no moves remain or a beta
// cutoff occurs.
Expand Down Expand Up @@ -1751,7 +1755,8 @@ void update_all_stats(const Position& pos,
Square prevSq,
ValueList<Move, 32>& quietsSearched,
ValueList<Move, 32>& capturesSearched,
Depth depth) {
Depth depth,
bool rootNode) {

CapturePieceToHistory& captureHistory = workerThread.captureHistory;
Piece moved_piece = pos.moved_piece(bestMove);
Expand All @@ -1762,11 +1767,11 @@ void update_all_stats(const Position& pos,

if (!pos.capture_stage(bestMove))
{
update_quiet_histories(pos, ss, workerThread, bestMove, quietMoveBonus);
update_quiet_histories(pos, ss, workerThread, bestMove, quietMoveBonus, rootNode);

// Decrease stats for all non-best quiet moves
for (Move move : quietsSearched)
update_quiet_histories(pos, ss, workerThread, move, -quietMoveMalus);
update_quiet_histories(pos, ss, workerThread, move, -quietMoveMalus, rootNode);
}
else
{
Expand Down Expand Up @@ -1809,10 +1814,12 @@ void update_continuation_histories(Stack* ss, Piece pc, Square to, int bonus) {
// Updates move sorting heuristics

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

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

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

Expand Down
1 change: 1 addition & 0 deletions src/search.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ class Worker {

// Public because they need to be updatable by the stats
ButterflyHistory mainHistory;
ButterflyHistory rootHistory;
CapturePieceToHistory captureHistory;
ContinuationHistory continuationHistory[2][2];
PawnHistory pawnHistory;
Expand Down

0 comments on commit f15e170

Please sign in to comment.