/// search captures, promotions and some checks) and about how important good
/// move ordering is at the current node.
-MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const History& h, const Refutations& r,
- Search::Stack* s, Value beta) : pos(p), Hist(h), depth(d) {
+MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const HistoryStats& h, const CountermovesStats& cm,
+ Search::Stack* s, Value beta) : pos(p), history(h), depth(d) {
assert(d > DEPTH_ZERO);
killers[0].move = ss->killers[0];
killers[1].move = ss->killers[1];
Square prevSq = to_sq((ss-1)->currentMove);
- killers[2].move = r[pos.piece_on(prevSq)][prevSq];
+ killers[2].move = cm[pos.piece_on(prevSq)][prevSq];
// Consider sligtly negative captures as good if at low depth and far from beta
if (ss && ss->staticEval < beta - PawnValueMg && d < 3 * ONE_PLY)
end += (ttMove != MOVE_NONE);
}
-MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const History& h,
- Square sq) : pos(p), Hist(h), cur(moves), end(moves) {
+MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const HistoryStats& h,
+ Square sq) : pos(p), history(h), cur(moves), end(moves) {
assert(d <= DEPTH_ZERO);
end += (ttMove != MOVE_NONE);
}
-MovePicker::MovePicker(const Position& p, Move ttm, const History& h, PieceType pt)
- : pos(p), Hist(h), cur(moves), end(moves) {
+MovePicker::MovePicker(const Position& p, Move ttm, const HistoryStats& h, PieceType pt)
+ : pos(p), history(h), cur(moves), end(moves) {
assert(!pos.checkers());
for (MoveStack* it = moves; it != end; ++it)
{
m = it->move;
- it->score = Hist[pos.piece_moved(m)][to_sq(m)];
+ it->score = history[pos.piece_moved(m)][to_sq(m)];
}
}
{
m = it->move;
if ((seeScore = pos.see_sign(m)) < 0)
- it->score = seeScore - History::Max; // At the bottom
+ it->score = seeScore - HistoryStats::Max; // At the bottom
else if (pos.is_capture(m))
it->score = PieceValue[MG][pos.piece_on(to_sq(m))]
- - type_of(pos.piece_moved(m)) + History::Max;
+ - type_of(pos.piece_moved(m)) + HistoryStats::Max;
else
- it->score = Hist[pos.piece_moved(m)][to_sq(m)];
+ it->score = history[pos.piece_moved(m)][to_sq(m)];
}
}
/// The Stats struct stores moves statistics. According to the template parameter
-/// the class can store History, Gains and Refutations statistics. History records
-/// how often different moves have been successful or unsuccessful during the
-/// current search and is used for reduction and move ordering decisions. Gains
-/// records the move's best evaluation gain from one ply to the next and is used
-/// for pruning decisions. Refutations store the move that refute a previous one.
-/// Entries are stored according only to moving piece and destination square, in
-/// particular two moves with different origin but same destination and same piece
-/// will be considered identical.
+/// the class can store History, Gains and Countermoves. History records how often
+/// different moves have been successful or unsuccessful during the current search
+/// and is used for reduction and move ordering decisions. Gains records the move's
+/// best evaluation gain from one ply to the next and is used for pruning decisions.
+/// Countermoves store the move that refute a previous one. Entries are stored
+/// according only to moving piece and destination square, hence two moves with
+/// different origin but same destination and piece will be considered identical.
template<bool Gain, typename T>
struct Stats {
T table[PIECE_NB][SQUARE_NB];
};
-typedef Stats<true, Value> Gains;
-typedef Stats<false, Value> History;
-typedef Stats<false, Move> Refutations;
+typedef Stats< true, Value> GainsStats;
+typedef Stats<false, Value> HistoryStats;
+typedef Stats<false, Move> CountermovesStats;
/// MovePicker class is used to pick one pseudo legal move at a time from the
MovePicker& operator=(const MovePicker&); // Silence a warning under MSVC
public:
- MovePicker(const Position&, Move, Depth, const History&, const Refutations&, Search::Stack*, Value);
- MovePicker(const Position&, Move, Depth, const History&, Square);
- MovePicker(const Position&, Move, const History&, PieceType);
+ MovePicker(const Position&, Move, Depth, const HistoryStats&, Square);
+ MovePicker(const Position&, Move, const HistoryStats&, PieceType);
+ MovePicker(const Position&, Move, Depth, const HistoryStats&,
+ const CountermovesStats&, Search::Stack*, Value);
+
template<bool SpNode> Move next_move();
private:
void generate_next();
const Position& pos;
- const History& Hist;
+ const HistoryStats& history;
Search::Stack* ss;
Depth depth;
Move ttMove;
TimeManager TimeMgr;
int BestMoveChanges;
Value DrawValue[COLOR_NB];
- History Hist;
- Gains Gain;
- Refutations Refutation;
+ HistoryStats History;
+ GainsStats Gains;
+ CountermovesStats Countermoves;
template <NodeType NT>
Value search(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth);
bestValue = delta = -VALUE_INFINITE;
ss->currentMove = MOVE_NULL; // Hack to skip update gains
TT.new_search();
- Hist.clear();
- Gain.clear();
- Refutation.clear();
+ History.clear();
+ Gains.clear();
+ Countermoves.clear();
PVSize = Options["MultiPV"];
Skill skill(Options["Skill Level"]);
&& type_of(move) == NORMAL)
{
Square to = to_sq(move);
- Gain.update(pos.piece_on(to), to, -(ss-1)->staticEval - ss->staticEval);
+ Gains.update(pos.piece_on(to), to, -(ss-1)->staticEval - ss->staticEval);
}
// Step 6. Razoring (is omitted in PV nodes)
assert((ss-1)->currentMove != MOVE_NONE);
assert((ss-1)->currentMove != MOVE_NULL);
- MovePicker mp(pos, ttMove, Hist, pos.captured_piece_type());
+ MovePicker mp(pos, ttMove, History, pos.captured_piece_type());
CheckInfo ci(pos);
while ((move = mp.next_move<false>()) != MOVE_NONE)
split_point_start: // At split points actual search starts from here
- MovePicker mp(pos, ttMove, depth, Hist, Refutation, ss, PvNode ? -VALUE_INFINITE : beta);
+ MovePicker mp(pos, ttMove, depth, History, Countermoves, ss, PvNode ? -VALUE_INFINITE : beta);
CheckInfo ci(pos);
value = bestValue; // Workaround a bogus 'uninitialized' warning under gcc
singularExtensionNode = !RootNode
// but fixing this made program slightly weaker.
Depth predictedDepth = newDepth - reduction<PvNode>(depth, moveCount);
futilityValue = ss->staticEval + ss->evalMargin + futility_margin(predictedDepth, moveCount)
- + Gain[pos.piece_moved(move)][to_sq(move)];
+ + Gains[pos.piece_moved(move)][to_sq(move)];
if (futilityValue < beta)
{
// Increase history value of the cut-off move
Value bonus = Value(int(depth) * int(depth));
- Hist.update(pos.piece_moved(bestMove), to_sq(bestMove), bonus);
+ History.update(pos.piece_moved(bestMove), to_sq(bestMove), bonus);
if (is_ok((ss-1)->currentMove))
{
Square prevSq = to_sq((ss-1)->currentMove);
- Refutation.update(pos.piece_on(prevSq), prevSq, bestMove);
+ Countermoves.update(pos.piece_on(prevSq), prevSq, bestMove);
}
// Decrease history of all the other played non-capture moves
for (int i = 0; i < playedMoveCount - 1; i++)
{
Move m = movesSearched[i];
- Hist.update(pos.piece_moved(m), to_sq(m), -bonus);
+ History.update(pos.piece_moved(m), to_sq(m), -bonus);
}
}
}
// to search the moves. Because the depth is <= 0 here, only captures,
// queen promotions and checks (only if depth >= DEPTH_QS_CHECKS) will
// be generated.
- MovePicker mp(pos, ttMove, depth, Hist, to_sq((ss-1)->currentMove));
+ MovePicker mp(pos, ttMove, depth, History, to_sq((ss-1)->currentMove));
CheckInfo ci(pos);
// Loop through the moves until no moves remain or a beta cutoff occurs