Skip to content

Commit a273b6e

Browse files
locutus2zamar
authored andcommitted
Add followup moves history for move ordering
STC: LLR: 2.96 (-2.94,2.94) [0.00,5.00] Total: 7955 W: 1538 L: 1378 D: 5039 LTC: LLR: 2.95 (-2.94,2.94) [0.00,5.00] Total: 5323 W: 778 L: 642 D: 3903 Bench: 8261839 Resolves #599
1 parent e1a7d13 commit a273b6e

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

src/movepick.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ namespace {
6868
/// ordering is at the current node.
6969

7070
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const HistoryStats& h,
71-
const CounterMoveStats& cmh, Move cm, Search::Stack* s)
72-
: pos(p), history(h), counterMoveHistory(&cmh), ss(s), countermove(cm), depth(d) {
71+
const CounterMoveStats& cmh, const CounterMoveStats& fmh, Move cm, Search::Stack* s)
72+
: pos(p), history(h), counterMoveHistory(&cmh), followupMoveHistory(&fmh), ss(s), countermove(cm), depth(d) {
7373

7474
assert(d > DEPTH_ZERO);
7575

@@ -80,7 +80,7 @@ MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const HistoryStats&
8080

8181
MovePicker::MovePicker(const Position& p, Move ttm, Depth d,
8282
const HistoryStats& h, Square s)
83-
: pos(p), history(h), counterMoveHistory(nullptr) {
83+
: pos(p), history(h), counterMoveHistory(nullptr), followupMoveHistory(nullptr) {
8484

8585
assert(d <= DEPTH_ZERO);
8686

@@ -105,7 +105,7 @@ MovePicker::MovePicker(const Position& p, Move ttm, Depth d,
105105
}
106106

107107
MovePicker::MovePicker(const Position& p, Move ttm, const HistoryStats& h, Value th)
108-
: pos(p), history(h), counterMoveHistory(nullptr), threshold(th) {
108+
: pos(p), history(h), counterMoveHistory(nullptr), followupMoveHistory(nullptr), threshold(th) {
109109

110110
assert(!pos.checkers());
111111

@@ -142,7 +142,8 @@ void MovePicker::score<QUIETS>() {
142142

143143
for (auto& m : *this)
144144
m.value = history[pos.moved_piece(m)][to_sq(m)]
145-
+ (*counterMoveHistory)[pos.moved_piece(m)][to_sq(m)];
145+
+ (*counterMoveHistory)[pos.moved_piece(m)][to_sq(m)]
146+
+ (*followupMoveHistory)[pos.moved_piece(m)][to_sq(m)];
146147
}
147148

148149
template<>

src/movepick.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class MovePicker {
8585

8686
MovePicker(const Position&, Move, Depth, const HistoryStats&, Square);
8787
MovePicker(const Position&, Move, const HistoryStats&, Value);
88-
MovePicker(const Position&, Move, Depth, const HistoryStats&, const CounterMoveStats&, Move, Search::Stack*);
88+
MovePicker(const Position&, Move, Depth, const HistoryStats&, const CounterMoveStats&, const CounterMoveStats&, Move, Search::Stack*);
8989

9090
Move next_move();
9191

@@ -98,6 +98,7 @@ class MovePicker {
9898
const Position& pos;
9999
const HistoryStats& history;
100100
const CounterMoveStats* counterMoveHistory;
101+
const CounterMoveStats* followupMoveHistory;
101102
Search::Stack* ss;
102103
Move countermove;
103104
Depth depth;

src/search.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -870,10 +870,12 @@ namespace {
870870
moves_loop: // When in check search starts from here
871871

872872
Square prevSq = to_sq((ss-1)->currentMove);
873+
Square ownPrevSq = to_sq((ss-2)->currentMove);
873874
Move cm = thisThread->counterMoves[pos.piece_on(prevSq)][prevSq];
874875
const CounterMoveStats& cmh = CounterMoveHistory[pos.piece_on(prevSq)][prevSq];
876+
const CounterMoveStats& fmh = CounterMoveHistory[pos.piece_on(ownPrevSq)][ownPrevSq];
875877

876-
MovePicker mp(pos, ttMove, depth, thisThread->history, cmh, cm, ss);
878+
MovePicker mp(pos, ttMove, depth, thisThread->history, cmh, fmh, cm, ss);
877879
CheckInfo ci(pos);
878880
value = bestValue; // Workaround a bogus 'uninitialized' warning under gcc
879881
improving = ss->staticEval >= (ss-2)->staticEval
@@ -1442,7 +1444,9 @@ namespace {
14421444
Value bonus = Value((depth / ONE_PLY) * (depth / ONE_PLY) + depth / ONE_PLY - 1);
14431445

14441446
Square prevSq = to_sq((ss-1)->currentMove);
1447+
Square ownPrevSq = to_sq((ss-2)->currentMove);
14451448
CounterMoveStats& cmh = CounterMoveHistory[pos.piece_on(prevSq)][prevSq];
1449+
CounterMoveStats& fmh = CounterMoveHistory[pos.piece_on(ownPrevSq)][ownPrevSq];
14461450
Thread* thisThread = pos.this_thread();
14471451

14481452
thisThread->history.update(pos.moved_piece(move), to_sq(move), bonus);
@@ -1453,13 +1457,19 @@ namespace {
14531457
cmh.update(pos.moved_piece(move), to_sq(move), bonus);
14541458
}
14551459

1460+
if (is_ok((ss-2)->currentMove))
1461+
fmh.update(pos.moved_piece(move), to_sq(move), bonus);
1462+
14561463
// Decrease all the other played quiet moves
14571464
for (int i = 0; i < quietsCnt; ++i)
14581465
{
14591466
thisThread->history.update(pos.moved_piece(quiets[i]), to_sq(quiets[i]), -bonus);
14601467

14611468
if (is_ok((ss-1)->currentMove))
14621469
cmh.update(pos.moved_piece(quiets[i]), to_sq(quiets[i]), -bonus);
1470+
1471+
if (is_ok((ss-2)->currentMove))
1472+
fmh.update(pos.moved_piece(quiets[i]), to_sq(quiets[i]), -bonus);
14631473
}
14641474

14651475
// Extra penalty for a quiet TT move in previous ply when it gets refuted

0 commit comments

Comments
 (0)