Skip to content

Commit

Permalink
uniform corrhist size
Browse files Browse the repository at this point in the history
bench 1197149
  • Loading branch information
xu-shawn committed Sep 23, 2024
1 parent dded626 commit 21a369e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 21 deletions.
32 changes: 14 additions & 18 deletions src/movepick.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,14 @@

namespace Stockfish {

constexpr int PAWN_HISTORY_SIZE = 512; // has to be a power of 2
constexpr int PAWN_CORRECTION_HISTORY_SIZE = 16384; // has to be a power of 2
constexpr int MATERIAL_CORRECTION_HISTORY_SIZE = 32768; // has to be a power of 2
constexpr int MAJOR_PIECE_CORRECTION_HISTORY_SIZE = 32768; // has to be a power of 2
constexpr int MINOR_PIECE_CORRECTION_HISTORY_SIZE = 32768; // has to be a power of 2
constexpr int NON_PAWN_CORRECTION_HISTORY_SIZE = 32768; // has to be a power of 2
constexpr int CORRECTION_HISTORY_LIMIT = 1024;
constexpr int PAWN_HISTORY_SIZE = 512; // has to be a power of 2
constexpr int CORRECTION_HISTORY_SIZE = 32768; // has to be a power of 2
constexpr int CORRECTION_HISTORY_LIMIT = 1024;

static_assert((PAWN_HISTORY_SIZE & (PAWN_HISTORY_SIZE - 1)) == 0,
"PAWN_HISTORY_SIZE has to be a power of 2");

static_assert((PAWN_CORRECTION_HISTORY_SIZE & (PAWN_CORRECTION_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 {
Expand All @@ -55,24 +51,24 @@ enum PawnHistoryType {

template<PawnHistoryType T = Normal>
inline int pawn_structure_index(const Position& pos) {
return pos.pawn_key() & ((T == Normal ? PAWN_HISTORY_SIZE : PAWN_CORRECTION_HISTORY_SIZE) - 1);
return pos.pawn_key() & ((T == Normal ? PAWN_HISTORY_SIZE : CORRECTION_HISTORY_SIZE) - 1);
}

inline int material_index(const Position& pos) {
return pos.material_key() & (MATERIAL_CORRECTION_HISTORY_SIZE - 1);
return pos.material_key() & (CORRECTION_HISTORY_SIZE - 1);
}

inline int major_piece_index(const Position& pos) {
return pos.major_piece_key() & (MAJOR_PIECE_CORRECTION_HISTORY_SIZE - 1);
return pos.major_piece_key() & (CORRECTION_HISTORY_SIZE - 1);
}

inline int minor_piece_index(const Position& pos) {
return pos.minor_piece_key() & (MINOR_PIECE_CORRECTION_HISTORY_SIZE - 1);
return pos.minor_piece_key() & (CORRECTION_HISTORY_SIZE - 1);
}

template<Color c>
inline int non_pawn_index(const Position& pos) {
return pos.non_pawn_key(c) & (NON_PAWN_CORRECTION_HISTORY_SIZE - 1);
return pos.non_pawn_key(c) & (CORRECTION_HISTORY_SIZE - 1);
}

// StatsEntry stores the stat table value. It is usually a number but could
Expand Down Expand Up @@ -161,23 +157,23 @@ using PawnHistory = Stats<int16_t, 8192, PAWN_HISTORY_SIZE, PIECE_NB, SQUARE_NB>

// PawnCorrectionHistory is addressed by color and pawn structure
using PawnCorrectionHistory =
Stats<int16_t, CORRECTION_HISTORY_LIMIT, COLOR_NB, PAWN_CORRECTION_HISTORY_SIZE>;
Stats<int16_t, CORRECTION_HISTORY_LIMIT, COLOR_NB, CORRECTION_HISTORY_SIZE>;

// MaterialCorrectionHistory is addressed by color and material configuration
using MaterialCorrectionHistory =
Stats<int16_t, CORRECTION_HISTORY_LIMIT, COLOR_NB, MATERIAL_CORRECTION_HISTORY_SIZE>;
Stats<int16_t, CORRECTION_HISTORY_LIMIT, COLOR_NB, CORRECTION_HISTORY_SIZE>;

// MajorPieceCorrectionHistory is addressed by color and king/major piece (Queen, Rook) positions
using MajorPieceCorrectionHistory =
Stats<int16_t, CORRECTION_HISTORY_LIMIT, COLOR_NB, MAJOR_PIECE_CORRECTION_HISTORY_SIZE>;
Stats<int16_t, CORRECTION_HISTORY_LIMIT, COLOR_NB, CORRECTION_HISTORY_SIZE>;

// MinorPieceCorrectionHistory is addressed by color and king/minor piece (Knight, Bishop) positions
using MinorPieceCorrectionHistory =
Stats<int16_t, CORRECTION_HISTORY_LIMIT, COLOR_NB, MINOR_PIECE_CORRECTION_HISTORY_SIZE>;
Stats<int16_t, CORRECTION_HISTORY_LIMIT, COLOR_NB, CORRECTION_HISTORY_SIZE>;

// NonPawnCorrectionHistory is addressed by color and non-pawn material positions
using NonPawnCorrectionHistory =
Stats<int16_t, CORRECTION_HISTORY_LIMIT, COLOR_NB, NON_PAWN_CORRECTION_HISTORY_SIZE>;
Stats<int16_t, CORRECTION_HISTORY_LIMIT, COLOR_NB, CORRECTION_HISTORY_SIZE>;

// The MovePicker class is used to pick one pseudo-legal move at a time from the
// current position. The most important method is next_move(), which emits one
Expand Down
5 changes: 2 additions & 3 deletions src/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ Value to_corrected_static_eval(Value v, const Worker& w, const Position& pos) {
const auto wnpcv = w.nonPawnCorrectionHistory[WHITE][us][non_pawn_index<WHITE>(pos)];
const auto bnpcv = w.nonPawnCorrectionHistory[BLACK][us][non_pawn_index<BLACK>(pos)];
const auto cv =
(99916 * pcv + 55067 * mcv + 55530 * macv + 95324 * micv + 105056 * (wnpcv + bnpcv))
/ 2097152;
(6245 * pcv + 3442 * mcv + 3471 * macv + 5958 * micv + 6566 * (wnpcv + bnpcv)) / 131072;
v += cv;
return std::clamp(v, VALUE_TB_LOSS_IN_MAX_PLY + 1, VALUE_TB_WIN_IN_MAX_PLY - 1);
}
Expand Down Expand Up @@ -534,7 +533,7 @@ Value Search::Worker::search(

// Dive into quiescence search when the depth reaches zero
if (depth <= 0)
return qsearch < PvNode ? PV : NonPV > (pos, ss, alpha, beta);
return qsearch<PvNode ? PV : NonPV>(pos, ss, alpha, beta);

// Limit the depth if extensions made it too large
depth = std::min(depth, MAX_PLY - 1);
Expand Down

0 comments on commit 21a369e

Please sign in to comment.