Skip to content

Commit 13c11f4

Browse files
locutus2zamar
authored andcommitted
Introduce Counter Move History tables
Introduce a counter move history table which additionally is indexed by the last move's piece and target square. For quiet move ordering use now the sum of standard and counter move history table. STC: LLR: 2.96 (-2.94,2.94) [-1.50,4.50] Total: 4747 W: 1005 L: 885 D: 2857 LTC: LLR: 2.95 (-2.94,2.94) [0.00,6.00] Total: 5726 W: 1001 L: 872 D: 3853 Because of reported low NPS on multi core test STC (7 threads): ELO: 7.26 +-3.3 (95%) LOS: 100.0% Total: 14937 W: 2710 L: 2398 D: 9829 Bench: 7725341 Resolves official-stockfish#282
1 parent 81c7975 commit 13c11f4

3 files changed

Lines changed: 33 additions & 14 deletions

File tree

src/movepick.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ namespace {
6767
/// search captures, promotions and some checks) and how important good move
6868
/// ordering is at the current node.
6969

70-
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const HistoryStats& h,
71-
Move* cm, Move* fm, Search::Stack* s) : pos(p), history(h), depth(d) {
70+
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const HistoryStats& h, const CounterMovesHistoryStats& cmh,
71+
Move* cm, Move* fm, Search::Stack* s) : pos(p), history(h), counterMovesHistory(cmh), depth(d) {
7272

7373
assert(d > DEPTH_ZERO);
7474

@@ -87,8 +87,8 @@ MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const HistoryStats&
8787
endMoves += (ttMove != MOVE_NONE);
8888
}
8989

90-
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const HistoryStats& h,
91-
Square s) : pos(p), history(h) {
90+
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const HistoryStats& h, const CounterMovesHistoryStats& cmh,
91+
Square s) : pos(p), history(h), counterMovesHistory(cmh) {
9292

9393
assert(d <= DEPTH_ZERO);
9494

@@ -112,8 +112,8 @@ MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const HistoryStats&
112112
endMoves += (ttMove != MOVE_NONE);
113113
}
114114

115-
MovePicker::MovePicker(const Position& p, Move ttm, const HistoryStats& h, PieceType pt)
116-
: pos(p), history(h) {
115+
MovePicker::MovePicker(const Position& p, Move ttm, const HistoryStats& h, const CounterMovesHistoryStats& cmh, PieceType pt)
116+
: pos(p), history(h), counterMovesHistory(cmh) {
117117

118118
assert(!pos.checkers());
119119

@@ -162,8 +162,13 @@ void MovePicker::score<CAPTURES>() {
162162

163163
template<>
164164
void MovePicker::score<QUIETS>() {
165+
Square prevMoveSq = to_sq((ss-1)->currentMove);
166+
Piece prevMovePiece = pos.piece_on(prevMoveSq);
167+
const HistoryStats &cmh = counterMovesHistory[prevMovePiece][prevMoveSq];
168+
165169
for (auto& m : *this)
166-
m.value = history[pos.moved_piece(m)][to_sq(m)];
170+
m.value = history[pos.moved_piece(m)][to_sq(m)]
171+
+ cmh[pos.moved_piece(m)][to_sq(m)];
167172
}
168173

169174
template<>

src/movepick.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ struct Stats {
4343
static const Value Max = Value(250);
4444

4545
const T* operator[](Piece pc) const { return table[pc]; }
46+
T* operator[](Piece pc) { return table[pc]; }
4647
void clear() { std::memset(table, 0, sizeof(table)); }
4748

4849
void update(Piece pc, Square to, Move m) {
@@ -70,6 +71,7 @@ struct Stats {
7071
typedef Stats< true, Value> GainsStats;
7172
typedef Stats<false, Value> HistoryStats;
7273
typedef Stats<false, std::pair<Move, Move> > MovesStats;
74+
typedef Stats<false, HistoryStats> CounterMovesHistoryStats;
7375

7476

7577
/// MovePicker class is used to pick one pseudo legal move at a time from the
@@ -84,9 +86,9 @@ class MovePicker {
8486
MovePicker(const MovePicker&) = delete;
8587
MovePicker& operator=(const MovePicker&) = delete;
8688

87-
MovePicker(const Position&, Move, Depth, const HistoryStats&, Square);
88-
MovePicker(const Position&, Move, const HistoryStats&, PieceType);
89-
MovePicker(const Position&, Move, Depth, const HistoryStats&, Move*, Move*, Search::Stack*);
89+
MovePicker(const Position&, Move, Depth, const HistoryStats&, const CounterMovesHistoryStats&, Square);
90+
MovePicker(const Position&, Move, const HistoryStats&, const CounterMovesHistoryStats&, PieceType);
91+
MovePicker(const Position&, Move, Depth, const HistoryStats&, const CounterMovesHistoryStats&, Move*, Move*, Search::Stack*);
9092

9193
template<bool SpNode> Move next_move();
9294

@@ -98,6 +100,7 @@ class MovePicker {
98100

99101
const Position& pos;
100102
const HistoryStats& history;
103+
const CounterMovesHistoryStats& counterMovesHistory;
101104
Search::Stack* ss;
102105
Move* countermoves;
103106
Move* followupmoves;

src/search.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ namespace {
9595
double BestMoveChanges;
9696
Value DrawValue[COLOR_NB];
9797
HistoryStats History;
98+
CounterMovesHistoryStats CounterMovesHistory;
9899
GainsStats Gains;
99100
MovesStats Countermoves, Followupmoves;
100101

@@ -289,6 +290,7 @@ namespace {
289290

290291
TT.new_search();
291292
History.clear();
293+
CounterMovesHistory.clear();
292294
Gains.clear();
293295
Countermoves.clear();
294296
Followupmoves.clear();
@@ -687,7 +689,7 @@ namespace {
687689
assert((ss-1)->currentMove != MOVE_NONE);
688690
assert((ss-1)->currentMove != MOVE_NULL);
689691

690-
MovePicker mp(pos, ttMove, History, pos.captured_piece_type());
692+
MovePicker mp(pos, ttMove, History, CounterMovesHistory, pos.captured_piece_type());
691693
CheckInfo ci(pos);
692694

693695
while ((move = mp.next_move<false>()) != MOVE_NONE)
@@ -726,7 +728,7 @@ namespace {
726728
Move followupmoves[] = { Followupmoves[pos.piece_on(prevOwnMoveSq)][prevOwnMoveSq].first,
727729
Followupmoves[pos.piece_on(prevOwnMoveSq)][prevOwnMoveSq].second };
728730

729-
MovePicker mp(pos, ttMove, depth, History, countermoves, followupmoves, ss);
731+
MovePicker mp(pos, ttMove, depth, History, CounterMovesHistory, countermoves, followupmoves, ss);
730732
CheckInfo ci(pos);
731733
value = bestValue; // Workaround a bogus 'uninitialized' warning under gcc
732734
improving = ss->staticEval >= (ss-2)->staticEval
@@ -1192,7 +1194,7 @@ namespace {
11921194
// to search the moves. Because the depth is <= 0 here, only captures,
11931195
// queen promotions and checks (only if depth >= DEPTH_QS_CHECKS) will
11941196
// be generated.
1195-
MovePicker mp(pos, ttMove, depth, History, to_sq((ss-1)->currentMove));
1197+
MovePicker mp(pos, ttMove, depth, History, CounterMovesHistory, to_sq((ss-1)->currentMove));
11961198
CheckInfo ci(pos);
11971199

11981200
// Loop through the moves until no moves remain or a beta cutoff occurs
@@ -1356,7 +1358,16 @@ namespace {
13561358
if (is_ok((ss-1)->currentMove))
13571359
{
13581360
Square prevMoveSq = to_sq((ss-1)->currentMove);
1359-
Countermoves.update(pos.piece_on(prevMoveSq), prevMoveSq, move);
1361+
Piece prevMovePiece = pos.piece_on(prevMoveSq);
1362+
Countermoves.update(prevMovePiece, prevMoveSq, move);
1363+
1364+
HistoryStats& cmh = CounterMovesHistory[prevMovePiece][prevMoveSq];
1365+
cmh.update(pos.moved_piece(move), to_sq(move), bonus);
1366+
for (int i = 0; i < quietsCnt; ++i)
1367+
{
1368+
Move m = quiets[i];
1369+
cmh.update(pos.moved_piece(m), to_sq(m), -bonus);
1370+
}
13601371
}
13611372

13621373
if (is_ok((ss-2)->currentMove) && (ss-1)->currentMove == (ss-1)->ttMove)

0 commit comments

Comments
 (0)