X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fmovepick.h;h=41a83604e09e99b768360ebb66b382d7510918a8;hp=a7cac4ba85ba64c03ceb29f64a0aa2eca7d5a939;hb=ae6a4ebf1f44cb05e96f8f33342ec281b41b0cc0;hpb=1781439fc2bfb12f8a4e89b2a75fdeac6cd58672 diff --git a/src/movepick.h b/src/movepick.h index a7cac4ba..41a83604 100644 --- a/src/movepick.h +++ b/src/movepick.h @@ -28,7 +28,7 @@ #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) { @@ -49,14 +49,18 @@ typedef StatBoards PieceToBoards; /// ordering decisions. It uses ButterflyBoards as backing store. struct ButterflyHistory : public ButterflyBoards { - void update(Color c, Move m, int v) { + void update(Color c, Move m, int bonus) { const int D = 324; auto& entry = (*this)[c][from_to(m)]; - assert(abs(v) <= D); // Consistency check for below formula + 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 += v * 32 - entry * abs(v) / D; + entry += bonus * 32 - entry * abs(bonus) / D; assert(abs(entry) <= 32 * D); } @@ -65,26 +69,31 @@ struct ButterflyHistory : public ButterflyBoards { /// PieceToHistory is like ButterflyHistory, but is based on PieceToBoards struct PieceToHistory : public PieceToBoards { - void update(Piece pc, Square to, int v) { + void update(Piece pc, Square to, int bonus) { const int D = 936; auto& entry = (*this)[pc][to]; - assert(abs(v) <= D); // Consistency check for below formula + 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 += v * 32 - entry * abs(v) / D; + entry += bonus * 32 - entry * abs(bonus) / D; assert(abs(entry) <= 32 * D); } }; -/// 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 +102,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 +118,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]; };