mirror of
https://github.com/HChaZZY/Stockfish.git
synced 2025-12-21 09:37:16 +08:00
Rename Refutation to Countermove
Use proper naming according to: http://chessprogramming.wikispaces.com/Countermove+Heuristic The name of this idea is "Countermove Heuristic" and was first introduced by Jos Uiterwijk in 1992 No functional change.
This commit is contained in:
@@ -70,8 +70,8 @@ namespace {
|
|||||||
/// search captures, promotions and some checks) and about how important good
|
/// search captures, promotions and some checks) and about how important good
|
||||||
/// move ordering is at the current node.
|
/// move ordering is at the current node.
|
||||||
|
|
||||||
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const History& h, const Refutations& r,
|
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const HistoryStats& h, const CountermovesStats& cm,
|
||||||
Search::Stack* s, Value beta) : pos(p), Hist(h), depth(d) {
|
Search::Stack* s, Value beta) : pos(p), history(h), depth(d) {
|
||||||
|
|
||||||
assert(d > DEPTH_ZERO);
|
assert(d > DEPTH_ZERO);
|
||||||
|
|
||||||
@@ -90,7 +90,7 @@ MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const History& h, c
|
|||||||
killers[0].move = ss->killers[0];
|
killers[0].move = ss->killers[0];
|
||||||
killers[1].move = ss->killers[1];
|
killers[1].move = ss->killers[1];
|
||||||
Square prevSq = to_sq((ss-1)->currentMove);
|
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
|
// Consider sligtly negative captures as good if at low depth and far from beta
|
||||||
if (ss && ss->staticEval < beta - PawnValueMg && d < 3 * ONE_PLY)
|
if (ss && ss->staticEval < beta - PawnValueMg && d < 3 * ONE_PLY)
|
||||||
@@ -105,8 +105,8 @@ MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const History& h, c
|
|||||||
end += (ttMove != MOVE_NONE);
|
end += (ttMove != MOVE_NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const History& h,
|
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const HistoryStats& h,
|
||||||
Square sq) : pos(p), Hist(h), cur(moves), end(moves) {
|
Square sq) : pos(p), history(h), cur(moves), end(moves) {
|
||||||
|
|
||||||
assert(d <= DEPTH_ZERO);
|
assert(d <= DEPTH_ZERO);
|
||||||
|
|
||||||
@@ -137,8 +137,8 @@ MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const History& h,
|
|||||||
end += (ttMove != MOVE_NONE);
|
end += (ttMove != MOVE_NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
MovePicker::MovePicker(const Position& p, Move ttm, const History& h, PieceType pt)
|
MovePicker::MovePicker(const Position& p, Move ttm, const HistoryStats& h, PieceType pt)
|
||||||
: pos(p), Hist(h), cur(moves), end(moves) {
|
: pos(p), history(h), cur(moves), end(moves) {
|
||||||
|
|
||||||
assert(!pos.checkers());
|
assert(!pos.checkers());
|
||||||
|
|
||||||
@@ -196,7 +196,7 @@ void MovePicker::score<QUIETS>() {
|
|||||||
for (MoveStack* it = moves; it != end; ++it)
|
for (MoveStack* it = moves; it != end; ++it)
|
||||||
{
|
{
|
||||||
m = it->move;
|
m = it->move;
|
||||||
it->score = Hist[pos.piece_moved(m)][to_sq(m)];
|
it->score = history[pos.piece_moved(m)][to_sq(m)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,13 +212,13 @@ void MovePicker::score<EVASIONS>() {
|
|||||||
{
|
{
|
||||||
m = it->move;
|
m = it->move;
|
||||||
if ((seeScore = pos.see_sign(m)) < 0)
|
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))
|
else if (pos.is_capture(m))
|
||||||
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)) + History::Max;
|
- type_of(pos.piece_moved(m)) + HistoryStats::Max;
|
||||||
else
|
else
|
||||||
it->score = Hist[pos.piece_moved(m)][to_sq(m)];
|
it->score = history[pos.piece_moved(m)][to_sq(m)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,14 +30,13 @@
|
|||||||
|
|
||||||
|
|
||||||
/// The Stats struct stores moves statistics. According to the template parameter
|
/// The Stats struct stores moves statistics. According to the template parameter
|
||||||
/// the class can store History, Gains and Refutations statistics. History records
|
/// the class can store History, Gains and Countermoves. History records how often
|
||||||
/// how often different moves have been successful or unsuccessful during the
|
/// different moves have been successful or unsuccessful during the current search
|
||||||
/// current search and is used for reduction and move ordering decisions. Gains
|
/// and is used for reduction and move ordering decisions. Gains records the move's
|
||||||
/// records the move's best evaluation gain from one ply to the next and is used
|
/// best evaluation gain from one ply to the next and is used for pruning decisions.
|
||||||
/// for pruning decisions. Refutations store the move that refute a previous one.
|
/// Countermoves store the move that refute a previous one. Entries are stored
|
||||||
/// Entries are stored according only to moving piece and destination square, in
|
/// according only to moving piece and destination square, hence two moves with
|
||||||
/// particular two moves with different origin but same destination and same piece
|
/// different origin but same destination and piece will be considered identical.
|
||||||
/// will be considered identical.
|
|
||||||
template<bool Gain, typename T>
|
template<bool Gain, typename T>
|
||||||
struct Stats {
|
struct Stats {
|
||||||
|
|
||||||
@@ -60,9 +59,9 @@ private:
|
|||||||
T table[PIECE_NB][SQUARE_NB];
|
T table[PIECE_NB][SQUARE_NB];
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef Stats<true, Value> Gains;
|
typedef Stats< true, Value> GainsStats;
|
||||||
typedef Stats<false, Value> History;
|
typedef Stats<false, Value> HistoryStats;
|
||||||
typedef Stats<false, Move> Refutations;
|
typedef Stats<false, Move> CountermovesStats;
|
||||||
|
|
||||||
|
|
||||||
/// MovePicker class is used to pick one pseudo legal move at a time from the
|
/// MovePicker class is used to pick one pseudo legal move at a time from the
|
||||||
@@ -77,9 +76,11 @@ class MovePicker {
|
|||||||
MovePicker& operator=(const MovePicker&); // Silence a warning under MSVC
|
MovePicker& operator=(const MovePicker&); // Silence a warning under MSVC
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MovePicker(const Position&, Move, Depth, const History&, const Refutations&, Search::Stack*, Value);
|
MovePicker(const Position&, Move, Depth, const HistoryStats&, Square);
|
||||||
MovePicker(const Position&, Move, Depth, const History&, Square);
|
MovePicker(const Position&, Move, const HistoryStats&, PieceType);
|
||||||
MovePicker(const Position&, Move, const History&, PieceType);
|
MovePicker(const Position&, Move, Depth, const HistoryStats&,
|
||||||
|
const CountermovesStats&, Search::Stack*, Value);
|
||||||
|
|
||||||
template<bool SpNode> Move next_move();
|
template<bool SpNode> Move next_move();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -87,7 +88,7 @@ private:
|
|||||||
void generate_next();
|
void generate_next();
|
||||||
|
|
||||||
const Position& pos;
|
const Position& pos;
|
||||||
const History& Hist;
|
const HistoryStats& history;
|
||||||
Search::Stack* ss;
|
Search::Stack* ss;
|
||||||
Depth depth;
|
Depth depth;
|
||||||
Move ttMove;
|
Move ttMove;
|
||||||
|
|||||||
@@ -86,9 +86,9 @@ namespace {
|
|||||||
TimeManager TimeMgr;
|
TimeManager TimeMgr;
|
||||||
int BestMoveChanges;
|
int BestMoveChanges;
|
||||||
Value DrawValue[COLOR_NB];
|
Value DrawValue[COLOR_NB];
|
||||||
History Hist;
|
HistoryStats History;
|
||||||
Gains Gain;
|
GainsStats Gains;
|
||||||
Refutations Refutation;
|
CountermovesStats Countermoves;
|
||||||
|
|
||||||
template <NodeType NT>
|
template <NodeType NT>
|
||||||
Value search(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth);
|
Value search(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth);
|
||||||
@@ -304,9 +304,9 @@ namespace {
|
|||||||
bestValue = delta = -VALUE_INFINITE;
|
bestValue = delta = -VALUE_INFINITE;
|
||||||
ss->currentMove = MOVE_NULL; // Hack to skip update gains
|
ss->currentMove = MOVE_NULL; // Hack to skip update gains
|
||||||
TT.new_search();
|
TT.new_search();
|
||||||
Hist.clear();
|
History.clear();
|
||||||
Gain.clear();
|
Gains.clear();
|
||||||
Refutation.clear();
|
Countermoves.clear();
|
||||||
|
|
||||||
PVSize = Options["MultiPV"];
|
PVSize = Options["MultiPV"];
|
||||||
Skill skill(Options["Skill Level"]);
|
Skill skill(Options["Skill Level"]);
|
||||||
@@ -623,7 +623,7 @@ namespace {
|
|||||||
&& type_of(move) == NORMAL)
|
&& type_of(move) == NORMAL)
|
||||||
{
|
{
|
||||||
Square to = to_sq(move);
|
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)
|
// Step 6. Razoring (is omitted in PV nodes)
|
||||||
@@ -734,7 +734,7 @@ namespace {
|
|||||||
assert((ss-1)->currentMove != MOVE_NONE);
|
assert((ss-1)->currentMove != MOVE_NONE);
|
||||||
assert((ss-1)->currentMove != MOVE_NULL);
|
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);
|
CheckInfo ci(pos);
|
||||||
|
|
||||||
while ((move = mp.next_move<false>()) != MOVE_NONE)
|
while ((move = mp.next_move<false>()) != MOVE_NONE)
|
||||||
@@ -766,7 +766,7 @@ namespace {
|
|||||||
|
|
||||||
split_point_start: // At split points actual search starts from here
|
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);
|
CheckInfo ci(pos);
|
||||||
value = bestValue; // Workaround a bogus 'uninitialized' warning under gcc
|
value = bestValue; // Workaround a bogus 'uninitialized' warning under gcc
|
||||||
singularExtensionNode = !RootNode
|
singularExtensionNode = !RootNode
|
||||||
@@ -884,7 +884,7 @@ split_point_start: // At split points actual search starts from here
|
|||||||
// but fixing this made program slightly weaker.
|
// but fixing this made program slightly weaker.
|
||||||
Depth predictedDepth = newDepth - reduction<PvNode>(depth, moveCount);
|
Depth predictedDepth = newDepth - reduction<PvNode>(depth, moveCount);
|
||||||
futilityValue = ss->staticEval + ss->evalMargin + futility_margin(predictedDepth, 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)
|
if (futilityValue < beta)
|
||||||
{
|
{
|
||||||
@@ -1091,18 +1091,18 @@ split_point_start: // At split points actual search starts from here
|
|||||||
|
|
||||||
// Increase history value of the cut-off move
|
// Increase history value of the cut-off move
|
||||||
Value bonus = Value(int(depth) * int(depth));
|
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))
|
if (is_ok((ss-1)->currentMove))
|
||||||
{
|
{
|
||||||
Square prevSq = to_sq((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
|
// Decrease history of all the other played non-capture moves
|
||||||
for (int i = 0; i < playedMoveCount - 1; i++)
|
for (int i = 0; i < playedMoveCount - 1; i++)
|
||||||
{
|
{
|
||||||
Move m = movesSearched[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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1215,7 +1215,7 @@ split_point_start: // At split points actual search starts from here
|
|||||||
// to search the moves. Because the depth is <= 0 here, only captures,
|
// to search the moves. Because the depth is <= 0 here, only captures,
|
||||||
// queen promotions and checks (only if depth >= DEPTH_QS_CHECKS) will
|
// queen promotions and checks (only if depth >= DEPTH_QS_CHECKS) will
|
||||||
// be generated.
|
// 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);
|
CheckInfo ci(pos);
|
||||||
|
|
||||||
// Loop through the moves until no moves remain or a beta cutoff occurs
|
// Loop through the moves until no moves remain or a beta cutoff occurs
|
||||||
|
|||||||
Reference in New Issue
Block a user