X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fmovepick.h;h=d6451f6bf0ad4575212802a1708c4792a2ce5887;hp=34cac635cfb01d83d763e8bc55850b1eee15c91e;hb=9001f55147fa304223623a6de0025ffe79f5fcc3;hpb=ecd3218b6b24bb54509dbe6e9b24517b7df7390d diff --git a/src/movepick.h b/src/movepick.h index 34cac635..d6451f6b 100644 --- a/src/movepick.h +++ b/src/movepick.h @@ -28,13 +28,27 @@ #include "types.h" /// StatBoards is a generic 2-dimensional array used to store various statistics -template +template struct StatBoards : public std::array, 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([&]{ + int v = entry + bonus * 32 - entry * abs(bonus) / D; + return INT16_MIN < v && v < INT16_MAX; + }()); + + assert(abs(bonus) <= D); // Consistency check for below formula + + 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 @@ -49,42 +63,27 @@ typedef StatBoards PieceToBoards; /// ordering decisions. It uses ButterflyBoards as backing store. struct ButterflyHistory : public ButterflyBoards { - void update(Color c, Move m, int v) { - - const int D = 324; - int& entry = (*this)[c][from_to(m)]; - - assert(abs(v) <= D); // Consistency check for below formula - - entry += v * 32 - entry * abs(v) / D; - - assert(abs(entry) <= 32 * D); + void update(Color c, Move m, int bonus) { + StatBoards::update((*this)[c][from_to(m)], bonus, 324); } }; /// PieceToHistory is like ButterflyHistory, but is based on PieceToBoards struct PieceToHistory : public PieceToBoards { - void update(Piece pc, Square to, int v) { - - const int D = 936; - int& entry = (*this)[pc][to]; - - assert(abs(v) <= D); // Consistency check for below formula - - entry += v * 32 - entry * abs(v) / D; - - assert(abs(entry) <= 32 * D); + void update(Piece pc, Square to, int bonus) { + StatBoards::update((*this)[pc][to], bonus, 936); } }; -/// CounterMoveStat stores counter moves indexed by [piece][to] of the previous +/// CounterMoveHistory stores counter moves indexed by [piece][to] of the previous /// move, see chessprogramming.wikispaces.com/Countermove+Heuristic -typedef StatBoards CounterMoveStat; +typedef StatBoards CounterMoveHistory; -/// CounterMoveHistoryStat is like CounterMoveStat but instead of a move it -/// stores a full history (based on PieceTo boards instead of ButterflyBoards). -typedef StatBoards CounterMoveHistoryStat; +/// ContinuationHistory is the history of a given pair of moves, usually the +/// current one given a previous one. History table is based on PieceToBoards +/// instead of ButterflyBoards. +typedef StatBoards ContinuationHistory; /// MovePicker class is used to pick one pseudo legal move at a time from the @@ -93,17 +92,14 @@ typedef StatBoards CounterMoveHistoryStat; /// when MOVE_NONE is returned. In order to improve the efficiency of the alpha /// beta algorithm, MovePicker attempts to return the moves which are most likely /// to get a cut-off first. -namespace Search { struct Stack; } class MovePicker { public: MovePicker(const MovePicker&) = delete; MovePicker& operator=(const MovePicker&) = delete; - MovePicker(const Position&, Move, Value); - MovePicker(const Position&, Move, Depth, Square); - MovePicker(const Position&, Move, Depth, Search::Stack*); - + MovePicker(const Position&, Move, Depth, const ButterflyHistory*, const PieceToHistory**, Square); + MovePicker(const Position&, Move, Depth, const ButterflyHistory*, const PieceToHistory**, Move, Move*); Move next_move(bool skipQuiets = false); private: @@ -112,15 +108,14 @@ private: ExtMove* end() { return endMoves; } const Position& pos; - const Search::Stack* ss; - Move killers[2]; - Move countermove; - Depth depth; - Move ttMove; + const ButterflyHistory* mainHistory; + const PieceToHistory** contHistory; + Move ttMove, countermove, killers[2]; + ExtMove *cur, *endMoves, *endBadCaptures; + int stage; Square recaptureSquare; Value threshold; - int stage; - ExtMove *cur, *endMoves, *endBadCaptures; + Depth depth; ExtMove moves[MAX_MOVES]; };