#include "types.h"
/// StatBoards is a generic 2-dimensional array used to store various statistics
-template<int Size1, int Size2, typename T = int>
+template<int Size1, int Size2, typename T = int16_t>
struct StatBoards : public std::array<std::array<T, Size2>, Size1> {
void fill(const T& v) {
T* p = &(*this)[0][0];
std::fill(p, p + sizeof(*this) / sizeof(*p), v);
}
+
+ void update(T& entry, int bonus, const int D) {
+
+ assert(abs(bonus) <= D); // Ensure range is [-32 * D, 32 * D]
+ assert(abs(32 * D) < INT16_MAX); // Ensure we don't overflow
+
+ entry += bonus * 32 - entry * abs(bonus) / D;
+
+ assert(abs(entry) <= 32 * D);
+ }
};
/// ButterflyBoards are 2 tables (one for each color) indexed by the move's from
struct ButterflyHistory : public ButterflyBoards {
void update(Color c, Move m, int bonus) {
-
- const int D = 324;
- auto& entry = (*this)[c][from_to(m)];
-
- assert(abs(bonus) <= D); // Consistency check for below formula
-
- entry += bonus * 32 - entry * abs(bonus) / D;
-
- assert(abs(entry) <= 32 * D);
+ StatBoards::update((*this)[c][from_to(m)], bonus, 324);
}
};
struct PieceToHistory : public PieceToBoards {
void update(Piece pc, Square to, int bonus) {
-
- const int D = 936;
- auto& entry = (*this)[pc][to];
-
- assert(abs(bonus) <= D); // Consistency check for below formula
-
- entry += bonus * 32 - entry * abs(bonus) / D;
-
- assert(abs(entry) <= 32 * D);
+ StatBoards::update((*this)[pc][to], bonus, 936);
}
};
MovePicker(const MovePicker&) = delete;
MovePicker& operator=(const MovePicker&) = delete;
MovePicker(const Position&, Move, Value);
- MovePicker(const Position&, Move, Depth, const ButterflyHistory*, const PieceToHistory**, Square);
+ MovePicker(const Position&, Move, Depth, const ButterflyHistory*, Square);
MovePicker(const Position&, Move, Depth, const ButterflyHistory*, const PieceToHistory**, Move, Move*);
Move next_move(bool skipQuiets = false);