Skip to content

Commit 53ab32e

Browse files
Stefan Geschwentnerunknown
authored andcommitted
Introduce 'follow up' moves
When we have a fail-high of a quiet move, store it in a Followupmoves table indexed by the previous move of the same color (instead of immediate previous move as is in countermoves case). Then use this table for quiet moves ordering in the same way we are already doing with countermoves. These followup moves will be tried just after countermoves and before remaining quiet moves. Passed both short TC LLR: 2.95 (-2.94,2.94) [-1.50,4.50] Total: 10350 W: 1998 L: 1866 D: 6486 And long TC LLR: 2.95 (-2.94,2.94) [0.00,6.00] Total: 14066 W: 2303 L: 2137 D: 9626 bench: 7205153
1 parent 402a7ae commit 53ab32e

File tree

4 files changed

+42
-13
lines changed

4 files changed

+42
-13
lines changed

src/movepick.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,14 @@ namespace {
7171
/// ordering is at the current node.
7272

7373
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const HistoryStats& h,
74-
Move* cm, Search::Stack* s) : pos(p), history(h), depth(d) {
74+
Move* cm, Move* fm, Search::Stack* s) : pos(p), history(h), depth(d) {
7575

7676
assert(d > DEPTH_ZERO);
7777

7878
cur = end = moves;
7979
endBadCaptures = moves + MAX_MOVES - 1;
8080
countermoves = cm;
81+
followupmoves = fm;
8182
ss = s;
8283

8384
if (p.checkers())
@@ -230,15 +231,28 @@ void MovePicker::generate_next() {
230231
killers[0].move = ss->killers[0];
231232
killers[1].move = ss->killers[1];
232233
killers[2].move = killers[3].move = MOVE_NONE;
234+
killers[4].move = killers[5].move = MOVE_NONE;
233235

234236
// Be sure countermoves are different from killers
235237
for (int i = 0; i < 2; ++i)
236-
if (countermoves[i] != cur->move && countermoves[i] != (cur+1)->move)
238+
if ( countermoves[i] != (cur+0)->move
239+
&& countermoves[i] != (cur+1)->move)
237240
(end++)->move = countermoves[i];
238241

239242
if (countermoves[1] && countermoves[1] == countermoves[0]) // Due to SMP races
240243
killers[3].move = MOVE_NONE;
241244

245+
// Be sure followupmoves are different from killers and countermoves
246+
for (int i = 0; i < 2; ++i)
247+
if ( followupmoves[i] != (cur+0)->move
248+
&& followupmoves[i] != (cur+1)->move
249+
&& followupmoves[i] != (cur+2)->move
250+
&& followupmoves[i] != (cur+3)->move)
251+
(end++)->move = followupmoves[i];
252+
253+
if (followupmoves[1] && followupmoves[1] == followupmoves[0]) // Due to SMP races
254+
(--end)->move = MOVE_NONE;
255+
242256
return;
243257

244258
case QUIETS_1_S1:
@@ -330,7 +344,9 @@ Move MovePicker::next_move<false>() {
330344
&& move != killers[0].move
331345
&& move != killers[1].move
332346
&& move != killers[2].move
333-
&& move != killers[3].move)
347+
&& move != killers[3].move
348+
&& move != killers[4].move
349+
&& move != killers[5].move)
334350
return move;
335351
break;
336352

src/movepick.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ struct Stats {
6969

7070
typedef Stats< true, Value> GainsStats;
7171
typedef Stats<false, Value> HistoryStats;
72-
typedef Stats<false, std::pair<Move, Move> > CountermovesStats;
72+
typedef Stats<false, std::pair<Move, Move> > MovesStats;
7373

7474

7575
/// MovePicker class is used to pick one pseudo legal move at a time from the
@@ -86,7 +86,7 @@ class MovePicker {
8686
public:
8787
MovePicker(const Position&, Move, Depth, const HistoryStats&, Square);
8888
MovePicker(const Position&, Move, const HistoryStats&, PieceType);
89-
MovePicker(const Position&, Move, Depth, const HistoryStats&, Move*, Search::Stack*);
89+
MovePicker(const Position&, Move, Depth, const HistoryStats&, Move*, Move*, Search::Stack*);
9090

9191
template<bool SpNode> Move next_move();
9292

@@ -98,9 +98,10 @@ class MovePicker {
9898
const HistoryStats& history;
9999
Search::Stack* ss;
100100
Move* countermoves;
101+
Move* followupmoves;
101102
Depth depth;
102103
Move ttMove;
103-
ExtMove killers[4];
104+
ExtMove killers[6];
104105
Square recaptureSquare;
105106
int captureThreshold, stage;
106107
ExtMove *cur, *end, *endQuiets, *endBadCaptures;

src/search.cpp

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ namespace {
8383
Value DrawValue[COLOR_NB];
8484
HistoryStats History;
8585
GainsStats Gains;
86-
CountermovesStats Countermoves;
86+
MovesStats Countermoves, Followupmoves;
8787

8888
template <NodeType NT>
8989
Value search(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth, bool cutNode);
@@ -304,6 +304,7 @@ namespace {
304304
History.clear();
305305
Gains.clear();
306306
Countermoves.clear();
307+
Followupmoves.clear();
307308

308309
PVSize = Options["MultiPV"];
309310
Skill skill(Options["Skill Level"]);
@@ -499,7 +500,7 @@ namespace {
499500

500501
moveCount = quietCount = 0;
501502
bestValue = -VALUE_INFINITE;
502-
ss->currentMove = (ss+1)->excludedMove = bestMove = MOVE_NONE;
503+
ss->currentMove = ss->ttMove = (ss+1)->excludedMove = bestMove = MOVE_NONE;
503504
ss->ply = (ss-1)->ply + 1;
504505
(ss+1)->skipNullMove = false; (ss+1)->reduction = DEPTH_ZERO;
505506
(ss+2)->killers[0] = (ss+2)->killers[1] = MOVE_NONE;
@@ -532,7 +533,7 @@ namespace {
532533
excludedMove = ss->excludedMove;
533534
posKey = excludedMove ? pos.exclusion_key() : pos.key();
534535
tte = TT.probe(posKey);
535-
ttMove = RootNode ? RootMoves[PVIdx].pv[0] : tte ? tte->move() : MOVE_NONE;
536+
ss->ttMove = ttMove = RootNode ? RootMoves[PVIdx].pv[0] : tte ? tte->move() : MOVE_NONE;
536537
ttValue = tte ? value_from_tt(tte->value(), ss->ply) : VALUE_NONE;
537538

538539
// At PV nodes we check for exact scores, whilst at non-PV nodes we check for
@@ -550,7 +551,7 @@ namespace {
550551
TT.refresh(tte);
551552
ss->currentMove = ttMove; // Can be MOVE_NONE
552553

553-
// If ttMove is quiet, update killers, history, and counter move on TT hit
554+
// If ttMove is quiet, update killers, history, counter move and followup move on TT hit
554555
if (ttValue >= beta && ttMove && !pos.capture_or_promotion(ttMove) && !inCheck)
555556
update_stats(pos, ss, ttMove, depth, NULL, 0);
556557

@@ -712,7 +713,11 @@ namespace {
712713
Move countermoves[] = { Countermoves[pos.piece_on(prevMoveSq)][prevMoveSq].first,
713714
Countermoves[pos.piece_on(prevMoveSq)][prevMoveSq].second };
714715

715-
MovePicker mp(pos, ttMove, depth, History, countermoves, ss);
716+
Square prevOwnMoveSq = to_sq((ss-2)->currentMove);
717+
Move followupmoves[] = { Followupmoves[pos.piece_on(prevOwnMoveSq)][prevOwnMoveSq].first,
718+
Followupmoves[pos.piece_on(prevOwnMoveSq)][prevOwnMoveSq].second };
719+
720+
MovePicker mp(pos, ttMove, depth, History, countermoves, followupmoves, ss);
716721
CheckInfo ci(pos);
717722
value = bestValue; // Workaround a bogus 'uninitialized' warning under gcc
718723
improving = ss->staticEval >= (ss-2)->staticEval
@@ -1029,7 +1034,7 @@ namespace {
10291034
PvNode && bestMove ? BOUND_EXACT : BOUND_UPPER,
10301035
depth, bestMove, ss->staticEval);
10311036

1032-
// Quiet best move: update killers, history and countermoves
1037+
// Quiet best move: update killers, history, countermoves and followupmoves
10331038
if (bestValue >= beta && !pos.capture_or_promotion(bestMove) && !inCheck)
10341039
update_stats(pos, ss, bestMove, depth, quietsSearched, quietCount - 1);
10351040

@@ -1264,7 +1269,7 @@ namespace {
12641269
}
12651270

12661271

1267-
// update_stats() updates killers, history and countermoves stats after a fail-high
1272+
// update_stats() updates killers, history, countermoves and followupmoves stats after a fail-high
12681273
// of a quiet move.
12691274

12701275
void update_stats(Position& pos, Stack* ss, Move move, Depth depth, Move* quiets, int quietsCnt) {
@@ -1290,6 +1295,12 @@ namespace {
12901295
Square prevMoveSq = to_sq((ss-1)->currentMove);
12911296
Countermoves.update(pos.piece_on(prevMoveSq), prevMoveSq, move);
12921297
}
1298+
1299+
if (is_ok((ss-2)->currentMove) && (ss-1)->currentMove == (ss-1)->ttMove)
1300+
{
1301+
Square prevOwnMoveSq = to_sq((ss-2)->currentMove);
1302+
Followupmoves.update(pos.piece_on(prevOwnMoveSq), prevOwnMoveSq, move);
1303+
}
12931304
}
12941305

12951306

src/search.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ struct Stack {
4141
SplitPoint* splitPoint;
4242
int ply;
4343
Move currentMove;
44+
Move ttMove;
4445
Move excludedMove;
4546
Move killers[2];
4647
Depth reduction;

0 commit comments

Comments
 (0)