}
+/// History class method definitions
+
+void History::clear() {
+ memset(history, 0, sizeof(history));
+ memset(gains, 0, sizeof(gains));
+}
+
+void History::update(Piece p, Square to, Value bonus) {
+ if (abs(history[p][to] + bonus) < History::Max)
+ history[p][to] += bonus;
+}
+
+void History::update_gain(Piece p, Square to, Value gain) {
+ gains[p][to] = std::max(gain, gains[p][to] - 1);
+}
+
+
/// Constructors of the MovePicker class. As arguments we pass information
/// to help it to return the presumably good moves first, to decide which
/// moves to return (in the quiescence search, for instance, we only want to
endBadCaptures = moves + MAX_MOVES - 1;
ss = s;
- if (p.in_check())
+ if (p.checkers())
phase = EVASION;
else
killers[1].move = ss->killers[1];
// Consider sligtly negative captures as good if at low depth and far from beta
- if (ss && ss->eval < beta - PawnValueMg && d < 3 * ONE_PLY)
+ if (ss && ss->staticEval < beta - PawnValueMg && d < 3 * ONE_PLY)
captureThreshold = -PawnValueMg;
// Consider negative captures as good if still enough to reach beta
- else if (ss && ss->eval > beta)
- captureThreshold = beta - ss->eval;
+ else if (ss && ss->staticEval > beta)
+ captureThreshold = beta - ss->staticEval;
}
ttMove = (ttm && pos.is_pseudo_legal(ttm) ? ttm : MOVE_NONE);
assert(d <= DEPTH_ZERO);
- if (p.in_check())
+ if (p.checkers())
phase = EVASION;
else if (d > DEPTH_QS_NO_CHECKS)
MovePicker::MovePicker(const Position& p, Move ttm, const History& h, PieceType pt)
: pos(p), H(h), cur(moves), end(moves) {
- assert(!pos.in_check());
+ assert(!pos.checkers());
phase = PROBCUT;
// In ProbCut we generate only captures better than parent's captured piece
- captureThreshold = PieceValue[Mg][pt];
+ captureThreshold = PieceValue[MG][pt];
ttMove = (ttm && pos.is_pseudo_legal(ttm) ? ttm : MOVE_NONE);
if (ttMove && (!pos.is_capture(ttMove) || pos.see(ttMove) <= captureThreshold))
for (MoveStack* it = moves; it != end; ++it)
{
m = it->move;
- it->score = PieceValue[Mg][pos.piece_on(to_sq(m))]
+ it->score = PieceValue[MG][pos.piece_on(to_sq(m))]
- type_of(pos.piece_moved(m));
if (type_of(m) == PROMOTION)
- it->score += PieceValue[Mg][promotion_type(m)];
+ it->score += PieceValue[MG][promotion_type(m)];
}
}
for (MoveStack* it = moves; it != end; ++it)
{
m = it->move;
- it->score = H.value(pos.piece_moved(m), to_sq(m));
+ it->score = H[pos.piece_moved(m)][to_sq(m)];
}
}
{
m = it->move;
if ((seeScore = pos.see_sign(m)) < 0)
- it->score = seeScore - History::MaxValue; // Be sure we are at the bottom
+ it->score = seeScore - History::Max; // Be sure we are 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::MaxValue;
+ it->score = PieceValue[MG][pos.piece_on(to_sq(m))]
+ - type_of(pos.piece_moved(m)) + History::Max;
else
- it->score = H.value(pos.piece_moved(m), to_sq(m));
+ it->score = H[pos.piece_moved(m)][to_sq(m)];
}
}