Skip to content

Commit

Permalink
Tweak usage of correction history
Browse files Browse the repository at this point in the history
Instead of using linear formula use quadratic one. Maximum impact of
correction history is doubled this way, it breaks even with previous
formula on half of maximum value.
  • Loading branch information
Vizvezdenec authored and PikaCat-OuO committed Jan 11, 2024
1 parent 366f8f9 commit deb7afe
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
7 changes: 7 additions & 0 deletions src/movepick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,26 @@ namespace Stockfish {
namespace {

enum Stages {
// generate main search moves
MAIN_TT,
CAPTURE_INIT,
GOOD_CAPTURE,
REFUTATION,
QUIET_INIT,
QUIET,
BAD_CAPTURE,

// generate evasion moves
EVASION_TT,
EVASION_INIT,
EVASION,

// generate probcut moves
PROBCUT_TT,
PROBCUT_INIT,
PROBCUT,

// generate qsearch moves
QSEARCH_TT,
QCAPTURE_INIT,
QCAPTURE,
Expand Down
10 changes: 4 additions & 6 deletions src/nnue/features/half_ka_v2_hm.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ namespace Stockfish::Eval::NNUE::Features {
// position of pieces. Position mirrored such that king is always on d..e files.
class HalfKAv2_hm {

// clang-format off
// Unique number for each piece type on each square
enum {
PS_NONE = 0,
Expand All @@ -48,14 +49,11 @@ class HalfKAv2_hm {
PS_B_CANNON = 3 * SQUARE_NB,
PS_W_KNIGHT = 4 * SQUARE_NB,
PS_B_KNIGHT = 5 * SQUARE_NB,
PS_AB_W_KP =
6
* SQUARE_NB, // White King and Pawn are merged into one plane, also used for Advisor and Bishop
PS_B_KP = 7 * SQUARE_NB, // Black King and Pawn are merged into one plane
PS_NB = 8 * SQUARE_NB
PS_AB_W_KP = 6 * SQUARE_NB, // White King and Pawn are merged into one plane, also used for Advisor and Bishop
PS_B_KP = 7 * SQUARE_NB, // Black King and Pawn are merged into one plane
PS_NB = 8 * SQUARE_NB
};

// clang-format off
static constexpr IndexType PieceSquareIndex[COLOR_NB][PIECE_NB] = {
// Convention: W - us, B - them
// Viewed from other side, W and B are reversed
Expand Down
18 changes: 14 additions & 4 deletions src/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,9 @@ Value search(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth, boo

Value newEval =
ss->staticEval
+ thisThread->correctionHistory[us][pawn_structure_index<Correction>(pos)] / 32;
+ thisThread->correctionHistory[us][pawn_structure_index<Correction>(pos)]
* std::abs(thisThread->correctionHistory[us][pawn_structure_index<Correction>(pos)])
/ 16384;

ss->staticEval = eval = to_static_eval(newEval);

Expand All @@ -637,7 +639,9 @@ Value search(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth, boo

Value newEval =
ss->staticEval
+ thisThread->correctionHistory[us][pawn_structure_index<Correction>(pos)] / 32;
+ thisThread->correctionHistory[us][pawn_structure_index<Correction>(pos)]
* std::abs(thisThread->correctionHistory[us][pawn_structure_index<Correction>(pos)])
/ 16384;

ss->staticEval = eval = to_static_eval(newEval);

Expand Down Expand Up @@ -1366,7 +1370,10 @@ Value qsearch(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth) {

Value newEval =
ss->staticEval
+ thisThread->correctionHistory[us][pawn_structure_index<Correction>(pos)] / 32;
+ thisThread->correctionHistory[us][pawn_structure_index<Correction>(pos)]
* std::abs(
thisThread->correctionHistory[us][pawn_structure_index<Correction>(pos)])
/ 16384;

ss->staticEval = bestValue = to_static_eval(newEval);

Expand All @@ -1383,7 +1390,10 @@ Value qsearch(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth) {

Value newEval =
ss->staticEval
+ thisThread->correctionHistory[us][pawn_structure_index<Correction>(pos)] / 32;
+ thisThread->correctionHistory[us][pawn_structure_index<Correction>(pos)]
* std::abs(
thisThread->correctionHistory[us][pawn_structure_index<Correction>(pos)])
/ 16384;

ss->staticEval = bestValue = to_static_eval(newEval);
}
Expand Down

0 comments on commit deb7afe

Please sign in to comment.