Skip to content

Commit be7a03a

Browse files
Vizvezdenecvondele
authored andcommitted
Introduce static history
The idea of this patch can be described as following: we update static history stats based on comparison of the static evaluations of the position before and after the move. If the move increases static evaluation it's assigned positive bonus, if it decreases static evaluation it's assigned negative bonus. These stats are used in movepicker to sort quiet moves. passed STC https://tests.stockfishchess.org/tests/view/5fca4c0842a050a89f02cd66 LLR: 3.00 (-2.94,2.94) {-0.25,1.25} Total: 78152 W: 7409 L: 7171 D: 63572 Ptnml(0-2): 303, 5695, 26873, 5871, 334 passed LTC https://tests.stockfishchess.org/tests/view/5fca6be442a050a89f02cd75 LLR: 2.94 (-2.94,2.94) {0.25,1.25} Total: 40240 W: 1602 L: 1441 D: 37197 Ptnml(0-2): 19, 1306, 17305, 1475, 15 closes official-stockfish/Stockfish#3253 bench 3845156
1 parent 7364006 commit be7a03a

File tree

5 files changed

+21
-4
lines changed

5 files changed

+21
-4
lines changed

src/movepick.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ namespace {
5454
/// ordering is at the current node.
5555

5656
/// MovePicker constructor for the main search
57-
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const ButterflyHistory* mh, const LowPlyHistory* lp,
57+
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const ButterflyHistory* mh, const ButterflyHistory* sh, const LowPlyHistory* lp,
5858
const CapturePieceToHistory* cph, const PieceToHistory** ch, Move cm, const Move* killers, int pl)
59-
: pos(p), mainHistory(mh), lowPlyHistory(lp), captureHistory(cph), continuationHistory(ch),
59+
: pos(p), mainHistory(mh), staticHistory(sh), lowPlyHistory(lp), captureHistory(cph), continuationHistory(ch),
6060
ttMove(ttm), refutations{{killers[0], 0}, {killers[1], 0}, {cm, 0}}, depth(d), ply(pl) {
6161

6262
assert(d > 0);
@@ -66,9 +66,9 @@ MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const ButterflyHist
6666
}
6767

6868
/// MovePicker constructor for quiescence search
69-
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const ButterflyHistory* mh,
69+
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const ButterflyHistory* mh, const ButterflyHistory* sh,
7070
const CapturePieceToHistory* cph, const PieceToHistory** ch, Square rs)
71-
: pos(p), mainHistory(mh), captureHistory(cph), continuationHistory(ch), ttMove(ttm), recaptureSquare(rs), depth(d) {
71+
: pos(p), mainHistory(mh), staticHistory(sh), captureHistory(cph), continuationHistory(ch), ttMove(ttm), recaptureSquare(rs), depth(d) {
7272

7373
assert(d <= 0);
7474

@@ -105,6 +105,7 @@ void MovePicker::score() {
105105

106106
else if (Type == QUIETS)
107107
m.value = (*mainHistory)[pos.side_to_move()][from_to(m)]
108+
+ (*staticHistory)[pos.side_to_move()][from_to(m)]
108109
+ 2 * (*continuationHistory[0])[pos.moved_piece(m)][to_sq(m)]
109110
+ 2 * (*continuationHistory[1])[pos.moved_piece(m)][to_sq(m)]
110111
+ 2 * (*continuationHistory[3])[pos.moved_piece(m)][to_sq(m)]

src/movepick.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,12 @@ class MovePicker {
123123
MovePicker& operator=(const MovePicker&) = delete;
124124
MovePicker(const Position&, Move, Value, const CapturePieceToHistory*);
125125
MovePicker(const Position&, Move, Depth, const ButterflyHistory*,
126+
const ButterflyHistory*,
126127
const CapturePieceToHistory*,
127128
const PieceToHistory**,
128129
Square);
129130
MovePicker(const Position&, Move, Depth, const ButterflyHistory*,
131+
const ButterflyHistory*,
130132
const LowPlyHistory*,
131133
const CapturePieceToHistory*,
132134
const PieceToHistory**,
@@ -143,6 +145,7 @@ class MovePicker {
143145

144146
const Position& pos;
145147
const ButterflyHistory* mainHistory;
148+
const ButterflyHistory* staticHistory;
146149
const LowPlyHistory* lowPlyHistory;
147150
const CapturePieceToHistory* captureHistory;
148151
const PieceToHistory** continuationHistory;

src/search.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,15 @@ namespace {
807807
tte->save(posKey, VALUE_NONE, ss->ttPv, BOUND_NONE, DEPTH_NONE, MOVE_NONE, eval);
808808
}
809809

810+
// Update static history for previous move
811+
if (is_ok((ss-1)->currentMove) && !(ss-1)->inCheck && !priorCapture)
812+
{
813+
int bonus = ss->staticEval > -(ss-1)->staticEval + 2 * Tempo ? -stat_bonus(depth) :
814+
ss->staticEval < -(ss-1)->staticEval + 2 * Tempo ? stat_bonus(depth) :
815+
0;
816+
thisThread->staticHistory[~us][from_to((ss-1)->currentMove)] << bonus;
817+
}
818+
810819
// Step 7. Razoring (~1 Elo)
811820
if ( !rootNode // The required rootNode PV handling is not available in qsearch
812821
&& depth == 1
@@ -964,6 +973,7 @@ namespace {
964973
Move countermove = thisThread->counterMoves[pos.piece_on(prevSq)][prevSq];
965974

966975
MovePicker mp(pos, ttMove, depth, &thisThread->mainHistory,
976+
&thisThread->staticHistory,
967977
&thisThread->lowPlyHistory,
968978
&captureHistory,
969979
contHist,
@@ -1507,6 +1517,7 @@ namespace {
15071517
// queen and checking knight promotions, and other checks(only if depth >= DEPTH_QS_CHECKS)
15081518
// will be generated.
15091519
MovePicker mp(pos, ttMove, depth, &thisThread->mainHistory,
1520+
&thisThread->staticHistory,
15101521
&thisThread->captureHistory,
15111522
contHist,
15121523
to_sq((ss-1)->currentMove));

src/thread.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ void Thread::clear() {
5757

5858
counterMoves.fill(MOVE_NONE);
5959
mainHistory.fill(0);
60+
staticHistory.fill(0);
6061
lowPlyHistory.fill(0);
6162
captureHistory.fill(0);
6263

src/thread.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class Thread {
6969
Depth rootDepth, completedDepth;
7070
CounterMoveHistory counterMoves;
7171
ButterflyHistory mainHistory;
72+
ButterflyHistory staticHistory;
7273
LowPlyHistory lowPlyHistory;
7374
CapturePieceToHistory captureHistory;
7475
ContinuationHistory continuationHistory[2][2];

0 commit comments

Comments
 (0)