Skip to content

Commit

Permalink
Better check evasion move sorting
Browse files Browse the repository at this point in the history
Use in addition the counter move history table for sorting quiet
check evasion moves in main and quiecence search. Also rename
"contHistory" to "continuationHistory" while there.

STC:
LLR: 2.96 (-2.94,2.94) [0.00,5.00]
Total: 73284 W: 16433 L: 15938 D: 40913
http://tests.stockfishchess.org/tests/view/5b4f526e0ebc5902bdb7a401

LTC:
LLR: 2.96 (-2.94,2.94) [0.00,5.00]
Total: 12135 W: 2171 L: 1997 D: 7967
http://tests.stockfishchess.org/tests/view/5b4fc0ef0ebc5902bdb7ae0e

Closes #1685

Bench 4817583
  • Loading branch information
locutus2 authored and snicolet committed Jul 19, 2018
1 parent 3913726 commit 12e79be
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 21 deletions.
16 changes: 9 additions & 7 deletions src/movepick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ namespace {
/// MovePicker constructor for the main search
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const ButterflyHistory* mh,
const CapturePieceToHistory* cph, const PieceToHistory** ch, Move cm, Move* killers)
: pos(p), mainHistory(mh), captureHistory(cph), contHistory(ch),
: pos(p), mainHistory(mh), captureHistory(cph), continuationHistory(ch),
refutations{{killers[0], 0}, {killers[1], 0}, {cm, 0}}, depth(d) {

assert(d > DEPTH_ZERO);
Expand All @@ -73,8 +73,8 @@ MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const ButterflyHist

/// MovePicker constructor for quiescence search
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const ButterflyHistory* mh,
const CapturePieceToHistory* cph, Square rs)
: pos(p), mainHistory(mh), captureHistory(cph), recaptureSquare(rs), depth(d) {
const CapturePieceToHistory* cph, const PieceToHistory** ch, Square rs)
: pos(p), mainHistory(mh), captureHistory(cph), continuationHistory(ch), recaptureSquare(rs), depth(d) {

assert(d <= DEPTH_ZERO);

Expand Down Expand Up @@ -115,17 +115,19 @@ void MovePicker::score() {

else if (Type == QUIETS)
m.value = (*mainHistory)[pos.side_to_move()][from_to(m)]
+ (*contHistory[0])[pos.moved_piece(m)][to_sq(m)]
+ (*contHistory[1])[pos.moved_piece(m)][to_sq(m)]
+ (*contHistory[3])[pos.moved_piece(m)][to_sq(m)];
+ (*continuationHistory[0])[pos.moved_piece(m)][to_sq(m)]
+ (*continuationHistory[1])[pos.moved_piece(m)][to_sq(m)]
+ (*continuationHistory[3])[pos.moved_piece(m)][to_sq(m)];

else // Type == EVASIONS
{
if (pos.capture(m))
m.value = PieceValue[MG][pos.piece_on(to_sq(m))]
- Value(type_of(pos.moved_piece(m)));
else
m.value = (*mainHistory)[pos.side_to_move()][from_to(m)] - (1 << 28);
m.value = (*mainHistory)[pos.side_to_move()][from_to(m)]
+ (*continuationHistory[0])[pos.moved_piece(m)][to_sq(m)]
- (1 << 28);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/movepick.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ class MovePicker {
MovePicker(const Position&, Move, Value, const CapturePieceToHistory*);
MovePicker(const Position&, Move, Depth, const ButterflyHistory*,
const CapturePieceToHistory*,
const PieceToHistory**,
Square);
MovePicker(const Position&, Move, Depth, const ButterflyHistory*,
const CapturePieceToHistory*,
Expand All @@ -136,7 +137,7 @@ class MovePicker {
const Position& pos;
const ButterflyHistory* mainHistory;
const CapturePieceToHistory* captureHistory;
const PieceToHistory** contHistory;
const PieceToHistory** continuationHistory;
Move ttMove;
ExtMove refutations[3], *cur, *endMoves, *endBadCaptures;
int stage;
Expand Down
24 changes: 15 additions & 9 deletions src/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ void Thread::search() {

std::memset(ss-4, 0, 7 * sizeof(Stack));
for (int i = 4; i > 0; i--)
(ss-i)->contHistory = this->contHistory[NO_PIECE][0].get(); // Use as sentinel
(ss-i)->continuationHistory = this->continuationHistory[NO_PIECE][0].get(); // Use as sentinel

bestValue = delta = alpha = -VALUE_INFINITE;
beta = VALUE_INFINITE;
Expand Down Expand Up @@ -587,7 +587,7 @@ namespace {

(ss+1)->ply = ss->ply + 1;
ss->currentMove = (ss+1)->excludedMove = bestMove = MOVE_NONE;
ss->contHistory = thisThread->contHistory[NO_PIECE][0].get();
ss->continuationHistory = thisThread->continuationHistory[NO_PIECE][0].get();
(ss+2)->killers[0] = (ss+2)->killers[1] = MOVE_NONE;
Square prevSq = to_sq((ss-1)->currentMove);

Expand Down Expand Up @@ -751,7 +751,7 @@ namespace {
Depth R = ((823 + 67 * depth / ONE_PLY) / 256 + std::min((eval - beta) / PawnValueMg, 3)) * ONE_PLY;

ss->currentMove = MOVE_NULL;
ss->contHistory = thisThread->contHistory[NO_PIECE][0].get();
ss->continuationHistory = thisThread->continuationHistory[NO_PIECE][0].get();

pos.do_null_move(st);

Expand Down Expand Up @@ -802,7 +802,7 @@ namespace {
probCutCount++;

ss->currentMove = move;
ss->contHistory = thisThread->contHistory[pos.moved_piece(move)][to_sq(move)].get();
ss->continuationHistory = thisThread->continuationHistory[pos.moved_piece(move)][to_sq(move)].get();

assert(depth >= 5 * ONE_PLY);

Expand Down Expand Up @@ -835,7 +835,7 @@ namespace {

moves_loop: // When in check, search starts from here

const PieceToHistory* contHist[] = { (ss-1)->contHistory, (ss-2)->contHistory, nullptr, (ss-4)->contHistory };
const PieceToHistory* contHist[] = { (ss-1)->continuationHistory, (ss-2)->continuationHistory, nullptr, (ss-4)->continuationHistory };
Move countermove = thisThread->counterMoves[pos.piece_on(prevSq)][prevSq];

MovePicker mp(pos, ttMove, depth, &thisThread->mainHistory,
Expand Down Expand Up @@ -970,7 +970,7 @@ namespace {

// Update the current move (this must be done after singular extension search)
ss->currentMove = move;
ss->contHistory = thisThread->contHistory[movedPiece][to_sq(move)].get();
ss->continuationHistory = thisThread->continuationHistory[movedPiece][to_sq(move)].get();

// Step 15. Make the move
pos.do_move(move, st, givesCheck);
Expand Down Expand Up @@ -1212,8 +1212,10 @@ namespace {
ss->pv[0] = MOVE_NONE;
}

Thread* thisThread = pos.this_thread();
(ss+1)->ply = ss->ply + 1;
ss->currentMove = bestMove = MOVE_NONE;
ss->continuationHistory = thisThread->continuationHistory[NO_PIECE][0].get();
inCheck = pos.checkers();
moveCount = 0;

Expand Down Expand Up @@ -1283,12 +1285,15 @@ namespace {
futilityBase = bestValue + 128;
}

const PieceToHistory* contHist[] = { (ss-1)->continuationHistory, (ss-2)->continuationHistory, nullptr, (ss-4)->continuationHistory };

// Initialize a MovePicker object for the current position, and prepare
// 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, &pos.this_thread()->mainHistory,
&pos.this_thread()->captureHistory,
MovePicker mp(pos, ttMove, depth, &thisThread->mainHistory,
&thisThread->captureHistory,
contHist,
to_sq((ss-1)->currentMove));

// Loop through the moves until no moves remain or a beta cutoff occurs
Expand Down Expand Up @@ -1345,6 +1350,7 @@ namespace {
}

ss->currentMove = move;
ss->continuationHistory = thisThread->continuationHistory[pos.moved_piece(move)][to_sq(move)].get();

// Make and search the move
pos.do_move(move, st, givesCheck);
Expand Down Expand Up @@ -1436,7 +1442,7 @@ namespace {

for (int i : {1, 2, 4})
if (is_ok((ss-i)->currentMove))
(*(ss-i)->contHistory)[pc][to] << bonus;
(*(ss-i)->continuationHistory)[pc][to] << bonus;
}


Expand Down
2 changes: 1 addition & 1 deletion src/search.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ constexpr int CounterMovePruneThreshold = 0;

struct Stack {
Move* pv;
PieceToHistory* contHistory;
PieceToHistory* continuationHistory;
int ply;
Move currentMove;
Move excludedMove;
Expand Down
4 changes: 2 additions & 2 deletions src/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ void Thread::clear() {
mainHistory.fill(0);
captureHistory.fill(0);

for (auto& to : contHistory)
for (auto& to : continuationHistory)
for (auto& h : to)
h.get()->fill(0);

contHistory[NO_PIECE][0].get()->fill(Search::CounterMovePruneThreshold - 1);
continuationHistory[NO_PIECE][0].get()->fill(Search::CounterMovePruneThreshold - 1);
}

/// Thread::start_searching() wakes up the thread that will start the search
Expand Down
2 changes: 1 addition & 1 deletion src/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class Thread {
CounterMoveHistory counterMoves;
ButterflyHistory mainHistory;
CapturePieceToHistory captureHistory;
ContinuationHistory contHistory;
ContinuationHistory continuationHistory;
Score contempt;
};

Expand Down

0 comments on commit 12e79be

Please sign in to comment.