Skip to content

Commit

Permalink
template corrhist
Browse files Browse the repository at this point in the history
bench 1283457
  • Loading branch information
xu-shawn committed Oct 22, 2024
1 parent 9766db8 commit d264d43
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 42 deletions.
53 changes: 30 additions & 23 deletions src/movepick.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,6 @@ using CapturePieceToHistory = Stats<int16_t, 10692, PIECE_NB, SQUARE_NB, PIECE_T
// PieceToHistory is like ButterflyHistory but is addressed by a move's [piece][to]
using PieceToHistory = Stats<int16_t, 29952, PIECE_NB, SQUARE_NB>;

// PieceToCorrectionHistory is addressed by a move's [piece][to]
using PieceToCorrectionHistory = Stats<int16_t, CORRECTION_HISTORY_LIMIT, PIECE_NB, SQUARE_NB>;

// ContinuationHistory is the combined history of a given pair of moves, usually
// the current one given a previous one. The nested history table is based on
// PieceToHistory instead of ButterflyBoards.
Expand All @@ -162,30 +159,40 @@ using PawnHistory = Stats<int16_t, 8192, PAWN_HISTORY_SIZE, PIECE_NB, SQUARE_NB>
// positions and their search score. It is used to improve the static evaluation
// used by some search heuristics.
// see https://www.chessprogramming.org/Static_Evaluation_Correction_History
enum CorrHistType {
// Pawn Correction History is addressed by color and pawn structure
Pawn,
// Material Correction History is addressed by color and material configuration
Material,
// Major Piece Correction History is addressed by color and king/major piece (Queen, Rook) positions
Major,
// Minor Piece Correction History is addressed by color and king/minor piece (Knight, Bishop) positions
Minor,
// Non-Pawn Correction History is addressed by color and non-pawn material positions
NonPawn,
// Piece-To Correction History is addressed by a move's [piece][to]
PieceTo,
// Continuation Correction History is the combined correction history of a given pair of moves
Continuation,
};

// PawnCorrectionHistory is addressed by color and pawn structure
using PawnCorrectionHistory =
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, 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, CORRECTION_HISTORY_SIZE>;
template<CorrHistType _>
struct CorrHistTypedef {
typedef Stats<int16_t, CORRECTION_HISTORY_LIMIT, COLOR_NB, CORRECTION_HISTORY_SIZE> type;
};

// MinorPieceCorrectionHistory is addressed by color and king/minor piece (Knight, Bishop) positions
using MinorPieceCorrectionHistory =
Stats<int16_t, CORRECTION_HISTORY_LIMIT, COLOR_NB, CORRECTION_HISTORY_SIZE>;
template<>
struct CorrHistTypedef<PieceTo> {
typedef Stats<int16_t, CORRECTION_HISTORY_LIMIT, PIECE_NB, SQUARE_NB> type;
};

// NonPawnCorrectionHistory is addressed by color and non-pawn material positions
using NonPawnCorrectionHistory =
Stats<int16_t, CORRECTION_HISTORY_LIMIT, COLOR_NB, CORRECTION_HISTORY_SIZE>;
template<>
struct CorrHistTypedef<Continuation> {
typedef Stats<CorrHistTypedef<PieceTo>::type, NOT_USED, PIECE_NB, SQUARE_NB> type;
};

// ContinuationCorrectionHistory is the combined correction history of a given pair of moves
using ContinuationCorrectionHistory =
Stats<PieceToCorrectionHistory, NOT_USED, PIECE_NB, SQUARE_NB>;
template<CorrHistType T>
using CorrectionHistory = typename CorrHistTypedef<T>::type;

// 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
38 changes: 19 additions & 19 deletions src/search.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,19 @@ namespace Search {
// shallower and deeper in the tree during the search. Each search thread has
// its own array of Stack objects, indexed by the current ply.
struct Stack {
Move* pv;
PieceToHistory* continuationHistory;
PieceToCorrectionHistory* continuationCorrectionHistory;
int ply;
Move currentMove;
Move excludedMove;
Value staticEval;
int statScore;
int moveCount;
bool inCheck;
bool ttPv;
bool ttHit;
int cutoffCnt;
Move* pv;
PieceToHistory* continuationHistory;
CorrectionHistory<PieceTo>* continuationCorrectionHistory;
int ply;
Move currentMove;
Move excludedMove;
Value staticEval;
int statScore;
int moveCount;
bool inCheck;
bool ttPv;
bool ttHit;
int cutoffCnt;
};


Expand Down Expand Up @@ -286,12 +286,12 @@ class Worker {
ContinuationHistory continuationHistory[2][2];
PawnHistory pawnHistory;

PawnCorrectionHistory pawnCorrectionHistory;
MaterialCorrectionHistory materialCorrectionHistory;
MajorPieceCorrectionHistory majorPieceCorrectionHistory;
MinorPieceCorrectionHistory minorPieceCorrectionHistory;
NonPawnCorrectionHistory nonPawnCorrectionHistory[COLOR_NB];
ContinuationCorrectionHistory continuationCorrectionHistory;
CorrectionHistory<Pawn> pawnCorrectionHistory;
CorrectionHistory<Material> materialCorrectionHistory;
CorrectionHistory<Major> majorPieceCorrectionHistory;
CorrectionHistory<Minor> minorPieceCorrectionHistory;
CorrectionHistory<NonPawn> nonPawnCorrectionHistory[COLOR_NB];
CorrectionHistory<Continuation> continuationCorrectionHistory;

private:
void iterative_deepening();
Expand Down

0 comments on commit d264d43

Please sign in to comment.