3333
3434namespace Stockfish {
3535
36- constexpr int PAWN_HISTORY_SIZE = 8192 ; // has to be a power of 2
37- constexpr int CORRECTION_HISTORY_SIZE = 32768 ; // has to be a power of 2
36+ constexpr int PAWN_HISTORY_SIZE = 8192 ; // has to be a power of 2
37+ constexpr int UINT_16_HISTORY_SIZE = std::numeric_limits< uint16_t >::max() + 1 ;
3838constexpr int CORRECTION_HISTORY_LIMIT = 1024 ;
3939constexpr int LOW_PLY_HISTORY_SIZE = 5 ;
4040
4141static_assert ((PAWN_HISTORY_SIZE & (PAWN_HISTORY_SIZE - 1 )) == 0 ,
4242 " PAWN_HISTORY_SIZE has to be a power of 2" );
4343
44- static_assert ((CORRECTION_HISTORY_SIZE & (CORRECTION_HISTORY_SIZE - 1 )) == 0 ,
44+ static_assert ((UINT_16_HISTORY_SIZE & (UINT_16_HISTORY_SIZE - 1 )) == 0 ,
4545 " CORRECTION_HISTORY_SIZE has to be a power of 2" );
4646
4747inline int pawn_history_index (const Position& pos) {
4848 return pos.pawn_key () & (PAWN_HISTORY_SIZE - 1 );
4949}
5050
51- inline int pawn_correction_history_index (const Position& pos) {
52- return pos.pawn_key () & (CORRECTION_HISTORY_SIZE - 1 );
53- }
51+ inline uint16_t pawn_correction_history_index (const Position& pos) { return pos.pawn_key (); }
5452
55- inline int minor_piece_index (const Position& pos) {
56- return pos.minor_piece_key () & (CORRECTION_HISTORY_SIZE - 1 );
57- }
53+ inline uint16_t minor_piece_index (const Position& pos) { return pos.minor_piece_key (); }
5854
5955template <Color c>
60- inline int non_pawn_index (const Position& pos) {
61- return pos.non_pawn_key (c) & (CORRECTION_HISTORY_SIZE - 1 ) ;
56+ inline uint16_t non_pawn_index (const Position& pos) {
57+ return pos.non_pawn_key (c);
6258}
6359
6460// StatsEntry is the container of various numerical statistics. We use a class
@@ -102,12 +98,11 @@ using Stats = MultiArray<StatsEntry<T, D>, Sizes...>;
10298// during the current search, and is used for reduction and move ordering decisions.
10399// It uses 2 tables (one for each color) indexed by the move's from and to squares,
104100// see https://www.chessprogramming.org/Butterfly_Boards
105- using ButterflyHistory = Stats<std::int16_t , 7183 , COLOR_NB, int (SQUARE_NB) * int (SQUARE_NB) >;
101+ using ButterflyHistory = Stats<std::int16_t , 7183 , COLOR_NB, UINT_16_HISTORY_SIZE >;
106102
107103// LowPlyHistory is addressed by play and move's from and to squares, used
108104// to improve move ordering near the root
109- using LowPlyHistory =
110- Stats<std::int16_t , 7183 , LOW_PLY_HISTORY_SIZE, int (SQUARE_NB) * int (SQUARE_NB)>;
105+ using LowPlyHistory = Stats<std::int16_t , 7183 , LOW_PLY_HISTORY_SIZE, UINT_16_HISTORY_SIZE>;
111106
112107// CapturePieceToHistory is addressed by a move's [piece][to][captured piece type]
113108using CapturePieceToHistory = Stats<std::int16_t , 10692 , PIECE_NB, SQUARE_NB, PIECE_TYPE_NB>;
@@ -139,7 +134,7 @@ namespace Detail {
139134
140135template <CorrHistType>
141136struct CorrHistTypedef {
142- using type = Stats<std::int16_t , CORRECTION_HISTORY_LIMIT, CORRECTION_HISTORY_SIZE , COLOR_NB>;
137+ using type = Stats<std::int16_t , CORRECTION_HISTORY_LIMIT, UINT_16_HISTORY_SIZE , COLOR_NB>;
143138};
144139
145140template <>
@@ -155,7 +150,7 @@ struct CorrHistTypedef<Continuation> {
155150template <>
156151struct CorrHistTypedef <NonPawn> {
157152 using type =
158- Stats<std::int16_t , CORRECTION_HISTORY_LIMIT, CORRECTION_HISTORY_SIZE , COLOR_NB, COLOR_NB>;
153+ Stats<std::int16_t , CORRECTION_HISTORY_LIMIT, UINT_16_HISTORY_SIZE , COLOR_NB, COLOR_NB>;
159154};
160155
161156}
0 commit comments