X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmovepick.h;h=66fc1bdba4a929bd1680eeb5715a9786581881f2;hb=3fd7e37868ce3a770ab5ca5ef686f75c8aa348f4;hp=41a83604e09e99b768360ebb66b382d7510918a8;hpb=ae6a4ebf1f44cb05e96f8f33342ec281b41b0cc0;p=stockfish diff --git a/src/movepick.h b/src/movepick.h index 41a83604..66fc1bdb 100644 --- a/src/movepick.h +++ b/src/movepick.h @@ -35,6 +35,16 @@ struct StatBoards : public std::array, Size1> { 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 @@ -50,19 +60,7 @@ typedef StatBoards PieceToBoards; 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 - assert([&]{ - int v = entry + bonus * 32 - entry * abs(bonus) / D; - return INT16_MIN < v && v < INT16_MAX; - }()); - - entry += bonus * 32 - entry * abs(bonus) / D; - - assert(abs(entry) <= 32 * D); + StatBoards::update((*this)[c][from_to(m)], bonus, 324); } }; @@ -70,19 +68,7 @@ struct ButterflyHistory : public ButterflyBoards { 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 - assert([&]{ - int v = entry + bonus * 32 - entry * abs(bonus) / D; - return INT16_MIN < v && v < INT16_MAX; - }()); - - entry += bonus * 32 - entry * abs(bonus) / D; - - assert(abs(entry) <= 32 * D); + StatBoards::update((*this)[pc][to], bonus, 936); } }; @@ -108,7 +94,7 @@ public: 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);