diff --git a/src/history.h b/src/history.h index 46914789e..b2abd9cc0 100644 --- a/src/history.h +++ b/src/history.h @@ -44,14 +44,12 @@ static_assert((PAWN_HISTORY_SIZE & (PAWN_HISTORY_SIZE - 1)) == 0, static_assert((CORRECTION_HISTORY_SIZE & (CORRECTION_HISTORY_SIZE - 1)) == 0, "CORRECTION_HISTORY_SIZE has to be a power of 2"); -enum PawnHistoryType { - Normal, - Correction -}; +inline int pawn_history_index(const Position& pos) { + return pos.pawn_key() & (PAWN_HISTORY_SIZE - 1); +} -template -inline int pawn_structure_index(const Position& pos) { - return pos.pawn_key() & ((T == Normal ? PAWN_HISTORY_SIZE : CORRECTION_HISTORY_SIZE) - 1); +inline int pawn_correction_history_index(const Position& pos) { + return pos.pawn_key() & (CORRECTION_HISTORY_SIZE - 1); } inline int minor_piece_index(const Position& pos) { diff --git a/src/movepick.cpp b/src/movepick.cpp index 79b6f55a2..eb7c45837 100644 --- a/src/movepick.cpp +++ b/src/movepick.cpp @@ -158,7 +158,7 @@ ExtMove* MovePicker::score(MoveList& ml) { { // histories m.value = 2 * (*mainHistory)[us][m.from_to()]; - m.value += 2 * (*pawnHistory)[pawn_structure_index(pos)][pc][to]; + m.value += 2 * (*pawnHistory)[pawn_history_index(pos)][pc][to]; m.value += (*continuationHistory[0])[pc][to]; m.value += (*continuationHistory[1])[pc][to]; m.value += (*continuationHistory[2])[pc][to]; diff --git a/src/search.cpp b/src/search.cpp index baf6dfb62..3c17042ca 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -75,7 +75,7 @@ using SearchedList = ValueList; int correction_value(const Worker& w, const Position& pos, const Stack* const ss) { const Color us = pos.side_to_move(); const auto m = (ss - 1)->currentMove; - const auto pcv = w.pawnCorrectionHistory[pawn_structure_index(pos)][us]; + const auto pcv = w.pawnCorrectionHistory[pawn_correction_history_index(pos)][us]; const auto micv = w.minorPieceCorrectionHistory[minor_piece_index(pos)][us]; const auto wnpcv = w.nonPawnCorrectionHistory[non_pawn_index(pos)][WHITE][us]; const auto bnpcv = w.nonPawnCorrectionHistory[non_pawn_index(pos)][BLACK][us]; @@ -101,8 +101,7 @@ void update_correction_history(const Position& pos, static constexpr int nonPawnWeight = 165; - workerThread.pawnCorrectionHistory[pawn_structure_index(pos)][us] - << bonus * 128 / 128; + workerThread.pawnCorrectionHistory[pawn_correction_history_index(pos)][us] << bonus; workerThread.minorPieceCorrectionHistory[minor_piece_index(pos)][us] << bonus * 153 / 128; workerThread.nonPawnCorrectionHistory[non_pawn_index(pos)][WHITE][us] << bonus * nonPawnWeight / 128; @@ -815,7 +814,7 @@ Value Search::Worker::search( mainHistory[~us][((ss - 1)->currentMove).from_to()] << bonus * 935 / 1024; if (!ttHit && type_of(pos.piece_on(prevSq)) != PAWN && ((ss - 1)->currentMove).type_of() != PROMOTION) - pawnHistory[pawn_structure_index(pos)][pos.piece_on(prevSq)][prevSq] + pawnHistory[pawn_history_index(pos)][pos.piece_on(prevSq)][prevSq] << bonus * 1428 / 1024; } @@ -823,8 +822,7 @@ Value Search::Worker::search( // bigger than the previous static evaluation at our turn (if we were in // check at our previous move we go back until we weren't in check) and is // false otherwise. The improving flag is used in various pruning heuristics. - improving = ss->staticEval > (ss - 2)->staticEval; - + improving = ss->staticEval > (ss - 2)->staticEval; opponentWorsening = ss->staticEval > -(ss - 1)->staticEval; if (priorReduction >= (depth < 10 ? 1 : 3) && !opponentWorsening) @@ -1069,7 +1067,7 @@ moves_loop: // When in check, search starts here { int history = (*contHist[0])[movedPiece][move.to_sq()] + (*contHist[1])[movedPiece][move.to_sq()] - + pawnHistory[pawn_structure_index(pos)][movedPiece][move.to_sq()]; + + pawnHistory[pawn_history_index(pos)][movedPiece][move.to_sq()]; // Continuation history based pruning if (history < -4361 * depth) @@ -1423,7 +1421,7 @@ moves_loop: // When in check, search starts here mainHistory[~us][((ss - 1)->currentMove).from_to()] << scaledBonus * 224 / 32768; if (type_of(pos.piece_on(prevSq)) != PAWN && ((ss - 1)->currentMove).type_of() != PROMOTION) - pawnHistory[pawn_structure_index(pos)][pos.piece_on(prevSq)][prevSq] + pawnHistory[pawn_history_index(pos)][pos.piece_on(prevSq)][prevSq] << scaledBonus * 1127 / 32768; } @@ -1642,7 +1640,7 @@ Value Search::Worker::qsearch(Position& pos, Stack* ss, Value alpha, Value beta) // Continuation history based pruning if (!capture && (*contHist[0])[pos.moved_piece(move)][move.to_sq()] - + pawnHistory[pawn_structure_index(pos)][pos.moved_piece(move)][move.to_sq()] + + pawnHistory[pawn_history_index(pos)][pos.moved_piece(move)][move.to_sq()] <= 5868) continue; @@ -1879,7 +1877,7 @@ void update_quiet_histories( update_continuation_histories(ss, pos.moved_piece(move), move.to_sq(), bonus * (bonus > 0 ? 979 : 842) / 1024); - int pIndex = pawn_structure_index(pos); + int pIndex = pawn_history_index(pos); workerThread.pawnHistory[pIndex][pos.moved_piece(move)][move.to_sq()] << (bonus * (bonus > 0 ? 704 : 439) / 1024) + 70; }