Skip to content

Commit c14cd78

Browse files
committed
In official-stockfish#6391 multiple histories were changed together.
See if the ones indexed by move from_to() were better previously. bench: 3012156
1 parent 1d504b9 commit c14cd78

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

src/history.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,11 @@ using Stats = MultiArray<StatsEntry<T, D>, Sizes...>;
9898
// during the current search, and is used for reduction and move ordering decisions.
9999
// It uses 2 tables (one for each color) indexed by the move's from and to squares,
100100
// see https://www.chessprogramming.org/Butterfly_Boards
101-
using ButterflyHistory = Stats<std::int16_t, 7183, COLOR_NB, UINT_16_HISTORY_SIZE>;
101+
using ButterflyHistory = Stats<std::int16_t, 7183, COLOR_NB, int(SQUARE_NB) * int(SQUARE_NB)>;
102102

103103
// LowPlyHistory is addressed by play and move's from and to squares, used
104104
// to improve move ordering near the root
105-
using LowPlyHistory = Stats<std::int16_t, 7183, LOW_PLY_HISTORY_SIZE, UINT_16_HISTORY_SIZE>;
105+
using LowPlyHistory = Stats<std::int16_t, 7183, LOW_PLY_HISTORY_SIZE, int(SQUARE_NB) * int(SQUARE_NB)>;
106106

107107
// CapturePieceToHistory is addressed by a move's [piece][to][captured piece type]
108108
using CapturePieceToHistory = Stats<std::int16_t, 10692, PIECE_NB, SQUARE_NB, PIECE_TYPE_NB>;

src/movepick.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ ExtMove* MovePicker::score(MoveList<Type>& ml) {
158158
else if constexpr (Type == QUIETS)
159159
{
160160
// histories
161-
m.value = 2 * (*mainHistory)[us][m.raw()];
161+
m.value = 2 * (*mainHistory)[us][m.from_to()];
162162
m.value += 2 * (*pawnHistory)[pawn_history_index(pos)][pc][to];
163163
m.value += (*continuationHistory[0])[pc][to];
164164
m.value += (*continuationHistory[1])[pc][to];
@@ -176,7 +176,7 @@ ExtMove* MovePicker::score(MoveList<Type>& ml) {
176176

177177

178178
if (ply < LOW_PLY_HISTORY_SIZE)
179-
m.value += 8 * (*lowPlyHistory)[ply][m.raw()] / (1 + ply);
179+
m.value += 8 * (*lowPlyHistory)[ply][m.from_to()] / (1 + ply);
180180
}
181181

182182
else // Type == EVASIONS
@@ -185,9 +185,9 @@ ExtMove* MovePicker::score(MoveList<Type>& ml) {
185185
m.value = PieceValue[capturedPiece] + (1 << 28);
186186
else
187187
{
188-
m.value = (*mainHistory)[us][m.raw()] + (*continuationHistory[0])[pc][to];
188+
m.value = (*mainHistory)[us][m.from_to()] + (*continuationHistory[0])[pc][to];
189189
if (ply < LOW_PLY_HISTORY_SIZE)
190-
m.value += (*lowPlyHistory)[ply][m.raw()];
190+
m.value += (*lowPlyHistory)[ply][m.from_to()];
191191
}
192192
}
193193
}

src/search.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,7 @@ Value Search::Worker::search(
824824
if (((ss - 1)->currentMove).is_ok() && !(ss - 1)->inCheck && !priorCapture)
825825
{
826826
int evalDiff = std::clamp(-int((ss - 1)->staticEval + ss->staticEval), -200, 156) + 58;
827-
mainHistory[~us][((ss - 1)->currentMove).raw()] << evalDiff * 9;
827+
mainHistory[~us][((ss - 1)->currentMove).from_to()] << evalDiff * 9;
828828
if (!ttHit && type_of(pos.piece_on(prevSq)) != PAWN
829829
&& ((ss - 1)->currentMove).type_of() != PROMOTION)
830830
pawnHistory[pawn_history_index(pos)][pos.piece_on(prevSq)][prevSq] << evalDiff * 14;
@@ -1068,7 +1068,7 @@ Value Search::Worker::search(
10681068
if (history < -4312 * depth)
10691069
continue;
10701070

1071-
history += 76 * mainHistory[us][move.raw()] / 32;
1071+
history += 76 * mainHistory[us][move.from_to()] / 32;
10721072

10731073
// (*Scaler): Generally, lower divisors scales well
10741074
lmrDepth += history / 3220;
@@ -1198,7 +1198,7 @@ Value Search::Worker::search(
11981198
ss->statScore = 803 * int(PieceValue[pos.captured_piece()]) / 128
11991199
+ captureHistory[movedPiece][move.to_sq()][type_of(pos.captured_piece())];
12001200
else
1201-
ss->statScore = 2 * mainHistory[us][move.raw()]
1201+
ss->statScore = 2 * mainHistory[us][move.from_to()]
12021202
+ (*contHist[0])[movedPiece][move.to_sq()]
12031203
+ (*contHist[1])[movedPiece][move.to_sq()];
12041204

@@ -1415,7 +1415,7 @@ Value Search::Worker::search(
14151415
update_continuation_histories(ss - 1, pos.piece_on(prevSq), prevSq,
14161416
scaledBonus * 400 / 32768);
14171417

1418-
mainHistory[~us][((ss - 1)->currentMove).raw()] << scaledBonus * 220 / 32768;
1418+
mainHistory[~us][((ss - 1)->currentMove).from_to()] << scaledBonus * 220 / 32768;
14191419

14201420
if (type_of(pos.piece_on(prevSq)) != PAWN && ((ss - 1)->currentMove).type_of() != PROMOTION)
14211421
pawnHistory[pawn_history_index(pos)][pos.piece_on(prevSq)][prevSq]
@@ -1862,10 +1862,10 @@ void update_quiet_histories(
18621862
const Position& pos, Stack* ss, Search::Worker& workerThread, Move move, int bonus) {
18631863

18641864
Color us = pos.side_to_move();
1865-
workerThread.mainHistory[us][move.raw()] << bonus; // Untuned to prevent duplicate effort
1865+
workerThread.mainHistory[us][move.from_to()] << bonus; // Untuned to prevent duplicate effort
18661866

18671867
if (ss->ply < LOW_PLY_HISTORY_SIZE)
1868-
workerThread.lowPlyHistory[ss->ply][move.raw()] << bonus * 761 / 1024;
1868+
workerThread.lowPlyHistory[ss->ply][move.from_to()] << bonus * 761 / 1024;
18691869

18701870
update_continuation_histories(ss, pos.moved_piece(move), move.to_sq(), bonus * 955 / 1024);
18711871

src/types.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,8 @@ class Move {
448448
return Square(data & 0x3F);
449449
}
450450

451+
constexpr int from_to() const { return data & 0xFFF; }
452+
451453
constexpr MoveType type_of() const { return MoveType(data & (3 << 14)); }
452454

453455
constexpr PieceType promotion_type() const { return PieceType(((data >> 12) & 3) + KNIGHT); }

0 commit comments

Comments
 (0)