Remove Stack/thread dependence in movepick

as a lower level routine, movepicker should not depend on the
search stack or the thread class, removing a circular dependency.
Instead of copying the search stack into the movepicker object,
as well as accessing the thread class for one of the histories,
pass the required fields explicitly to the constructor (removing
the need for thread.h and implicitly search.h in movepick.cpp).
The signature is thus longer, but more explicit:

Also some renaming of histories structures while there.

passed STC [-3,1], suggesting a small elo impact:

LLR: 3.13 (-2.94,2.94) [-3.00,1.00]
Total: 381053 W: 68071 L: 68551 D: 244431
elo =   -0.438 +-    0.660 LOS:    9.7%

No functional change.
This commit is contained in:
Joost VandeVondele
2017-06-30 17:20:00 +02:00
committed by Marco Costalba
parent 53c2d9df5e
commit b40e45c1cc
5 changed files with 71 additions and 87 deletions

View File

@@ -49,14 +49,14 @@ typedef StatBoards<PIECE_NB, SQUARE_NB> 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
entry += v * 32 - entry * abs(v) / D;
entry += bonus * 32 - entry * abs(bonus) / D;
assert(abs(entry) <= 32 * D);
}
@@ -65,26 +65,27 @@ 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
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<PIECE_NB, SQUARE_NB, Move> CounterMoveStat;
typedef StatBoards<PIECE_NB, SQUARE_NB, Move> CounterMoveHistory;
/// CounterMoveHistoryStat is like CounterMoveStat but instead of a move it
/// stores a full history (based on PieceTo boards instead of ButterflyBoards).
typedef StatBoards<PIECE_NB, SQUARE_NB, PieceToHistory> 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<PIECE_NB, SQUARE_NB, PieceToHistory> ContinuationHistory;
/// MovePicker class is used to pick one pseudo legal move at a time from the
@@ -93,17 +94,14 @@ typedef StatBoards<PIECE_NB, SQUARE_NB, PieceToHistory> 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 +110,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];
};