1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-04-29 16:23:09 +00:00

Template Corrhist

Avoids duplication of `using ... = Stats<int16_t,
CORRECTION_HISTORY_LIMIT, COLOR_NB, CORRECTION_HISTORY_SIZE>;`

closes https://github.com/official-stockfish/Stockfish/pull/5650

No functional change

Co-authored-by: Disservin <disservin.social@gmail.com>
This commit is contained in:
Shawn Xu 2024-10-22 14:57:07 -07:00 committed by Disservin
parent 8ef403c786
commit 4a9c980f3b
2 changed files with 40 additions and 37 deletions

View file

@ -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] // PieceToHistory is like ButterflyHistory but is addressed by a move's [piece][to]
using PieceToHistory = Stats<int16_t, 29952, PIECE_NB, SQUARE_NB>; 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 // 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 // the current one given a previous one. The nested history table is based on
// PieceToHistory instead of ButterflyBoards. // PieceToHistory instead of ButterflyBoards.
@ -162,26 +159,32 @@ 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 // positions and their search score. It is used to improve the static evaluation
// used by some search heuristics. // used by some search heuristics.
// see https://www.chessprogramming.org/Static_Evaluation_Correction_History // see https://www.chessprogramming.org/Static_Evaluation_Correction_History
enum CorrHistType {
Pawn, // By color and pawn structure
Major, // By color and positions of major pieces (Queen, Rook) and King
Minor, // By color and positions of minor pieces (Knight, Bishop) and King
NonPawn, // By color and non-pawn material positions
PieceTo, // By [piece][to] move
Continuation, // Combined history of move pairs
};
// PawnCorrectionHistory is addressed by color and pawn structure template<CorrHistType _>
using PawnCorrectionHistory = struct CorrHistTypedef {
Stats<int16_t, CORRECTION_HISTORY_LIMIT, COLOR_NB, CORRECTION_HISTORY_SIZE>; using type = Stats<int16_t, CORRECTION_HISTORY_LIMIT, COLOR_NB, CORRECTION_HISTORY_SIZE>;
};
// MajorPieceCorrectionHistory is addressed by color and king/major piece (Queen, Rook) positions template<>
using MajorPieceCorrectionHistory = struct CorrHistTypedef<PieceTo> {
Stats<int16_t, CORRECTION_HISTORY_LIMIT, COLOR_NB, CORRECTION_HISTORY_SIZE>; using type = Stats<int16_t, CORRECTION_HISTORY_LIMIT, PIECE_NB, SQUARE_NB>;
};
// MinorPieceCorrectionHistory is addressed by color and king/minor piece (Knight, Bishop) positions template<>
using MinorPieceCorrectionHistory = struct CorrHistTypedef<Continuation> {
Stats<int16_t, CORRECTION_HISTORY_LIMIT, COLOR_NB, CORRECTION_HISTORY_SIZE>; using type = Stats<CorrHistTypedef<PieceTo>::type, NOT_USED, PIECE_NB, SQUARE_NB>;
};
// NonPawnCorrectionHistory is addressed by color and non-pawn material positions template<CorrHistType T>
using NonPawnCorrectionHistory = using CorrectionHistory = typename CorrHistTypedef<T>::type;
Stats<int16_t, CORRECTION_HISTORY_LIMIT, COLOR_NB, CORRECTION_HISTORY_SIZE>;
// ContinuationCorrectionHistory is the combined correction history of a given pair of moves
using ContinuationCorrectionHistory =
Stats<PieceToCorrectionHistory, NOT_USED, PIECE_NB, SQUARE_NB>;
// The MovePicker class is used to pick one pseudo-legal move at a time from the // 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 // current position. The most important method is next_move(), which emits one

View file

@ -61,19 +61,19 @@ namespace Search {
// shallower and deeper in the tree during the search. Each search thread has // shallower and deeper in the tree during the search. Each search thread has
// its own array of Stack objects, indexed by the current ply. // its own array of Stack objects, indexed by the current ply.
struct Stack { struct Stack {
Move* pv; Move* pv;
PieceToHistory* continuationHistory; PieceToHistory* continuationHistory;
PieceToCorrectionHistory* continuationCorrectionHistory; CorrectionHistory<PieceTo>* continuationCorrectionHistory;
int ply; int ply;
Move currentMove; Move currentMove;
Move excludedMove; Move excludedMove;
Value staticEval; Value staticEval;
int statScore; int statScore;
int moveCount; int moveCount;
bool inCheck; bool inCheck;
bool ttPv; bool ttPv;
bool ttHit; bool ttHit;
int cutoffCnt; int cutoffCnt;
}; };
@ -286,11 +286,11 @@ class Worker {
ContinuationHistory continuationHistory[2][2]; ContinuationHistory continuationHistory[2][2];
PawnHistory pawnHistory; PawnHistory pawnHistory;
PawnCorrectionHistory pawnCorrectionHistory; CorrectionHistory<Pawn> pawnCorrectionHistory;
MajorPieceCorrectionHistory majorPieceCorrectionHistory; CorrectionHistory<Major> majorPieceCorrectionHistory;
MinorPieceCorrectionHistory minorPieceCorrectionHistory; CorrectionHistory<Minor> minorPieceCorrectionHistory;
NonPawnCorrectionHistory nonPawnCorrectionHistory[COLOR_NB]; CorrectionHistory<NonPawn> nonPawnCorrectionHistory[COLOR_NB];
ContinuationCorrectionHistory continuationCorrectionHistory; CorrectionHistory<Continuation> continuationCorrectionHistory;
private: private:
void iterative_deepening(); void iterative_deepening();