Skip to content

Commit

Permalink
Rename Refutation to Countermove
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mcostalba committed May 15, 2013
1 parent 7c6f346 commit 148490f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 40 deletions.
22 changes: 11 additions & 11 deletions src/movepick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ namespace {
/// 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);

Expand All @@ -90,7 +90,7 @@ MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const History& h, c
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)
Expand All @@ -105,8 +105,8 @@ MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const History& h, c
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);

Expand Down Expand Up @@ -137,8 +137,8 @@ MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const History& h,
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());

Expand Down Expand Up @@ -196,7 +196,7 @@ void MovePicker::score<QUIETS>() {
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)];
}
}

Expand All @@ -212,13 +212,13 @@ void MovePicker::score<EVASIONS>() {
{
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)];
}
}

Expand Down
31 changes: 16 additions & 15 deletions src/movepick.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,13 @@


/// 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 {

Expand All @@ -60,9 +59,9 @@ 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
Expand All @@ -77,17 +76,19 @@ class MovePicker {
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:
template<GenType> void score();
void generate_next();

const Position& pos;
const History& Hist;
const HistoryStats& history;
Search::Stack* ss;
Depth depth;
Move ttMove;
Expand Down
28 changes: 14 additions & 14 deletions src/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ namespace {
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);
Expand Down Expand Up @@ -304,9 +304,9 @@ namespace {
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"]);
Expand Down Expand Up @@ -623,7 +623,7 @@ namespace {
&& 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)
Expand Down Expand Up @@ -734,7 +734,7 @@ namespace {
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)
Expand Down Expand Up @@ -766,7 +766,7 @@ namespace {

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
Expand Down Expand Up @@ -884,7 +884,7 @@ namespace {
// 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)
{
Expand Down Expand Up @@ -1091,18 +1091,18 @@ namespace {

// 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);
}
}
}
Expand Down Expand Up @@ -1215,7 +1215,7 @@ namespace {
// 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
Expand Down

0 comments on commit 148490f

Please sign in to comment.