Skip to content

Commit 8fd34d7

Browse files
VoyagerOneglinscott
authored andcommitted
Combination of two ideas:
Apply bonus for the prior CMH that caused a fail low. Balance Stats: CMH and History bonuses are updated differently. This eliminates the "fudge" factor weight when scoring moves. Also eliminated discontinuity in the gravity history stat formula. (i.e. stat scores will no longer inverse when depth exceeds 22) STC: LLR: 2.96 (-2.94,2.94) [0.00,5.00] Total: 21802 W: 4107 L: 3887 D: 13808 LTC: LLR: 2.96 (-2.94,2.94) [0.00,5.00] Total: 46036 W: 7046 L: 6756 D: 32234 Bench: 7677367
1 parent 55b46ff commit 8fd34d7

File tree

3 files changed

+33
-10
lines changed

3 files changed

+33
-10
lines changed

src/movepick.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ void MovePicker::score<QUIETS>() {
146146

147147
for (auto& m : *this)
148148
m.value = history[pos.moved_piece(m)][to_sq(m)]
149-
+ cmh[pos.moved_piece(m)][to_sq(m)] * 3;
149+
+ cmh[pos.moved_piece(m)][to_sq(m)];
150150
}
151151

152152
template<>

src/movepick.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
template<typename T>
4040
struct Stats {
4141

42-
static const Value Max = Value(1 << 28);
42+
static const Value Max = Value(1<<28);
4343

4444
const T* operator[](Piece pc) const { return table[pc]; }
4545
T* operator[](Piece pc) { return table[pc]; }
@@ -51,10 +51,20 @@ struct Stats {
5151
table[pc][to] = m;
5252
}
5353

54-
void update(Piece pc, Square to, Value v) {
54+
void updateH(Piece pc, Square to, Value v) {
5555

56-
table[pc][to] -= table[pc][to] * std::min(abs(v), 512) / 512;
57-
table[pc][to] += v * 64;
56+
if (abs(int(v)) >= 324)
57+
return;
58+
table[pc][to] -= table[pc][to] * abs(int(v)) / 324;
59+
table[pc][to] += int(v) * 32;
60+
}
61+
62+
void updateCMH(Piece pc, Square to, Value v) {
63+
64+
if (abs(int(v)) >= 324)
65+
return;
66+
table[pc][to] -= table[pc][to] * abs(int(v)) / 512;
67+
table[pc][to] += int(v) * 64;
5868
}
5969

6070
private:

src/search.cpp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,19 @@ namespace {
11321132
else if (bestMove && !pos.capture_or_promotion(bestMove))
11331133
update_stats(pos, ss, bestMove, depth, quietsSearched, quietCount);
11341134

1135+
// Bonus for prior countermove that caused the fail low
1136+
else if (!bestMove)
1137+
{
1138+
if (is_ok((ss - 2)->currentMove) && is_ok((ss - 1)->currentMove) && !pos.captured_piece_type() && !inCheck && depth>=3*ONE_PLY)
1139+
{
1140+
Value bonus = Value((depth / ONE_PLY) * (depth / ONE_PLY));
1141+
Square prevSq = to_sq((ss - 1)->currentMove);
1142+
Square prevPrevSq = to_sq((ss - 2)->currentMove);
1143+
HistoryStats& flMoveCmh = CounterMovesHistory[pos.piece_on(prevPrevSq)][prevPrevSq];
1144+
flMoveCmh.updateCMH(pos.piece_on(prevSq), prevSq, bonus);
1145+
}
1146+
}
1147+
11351148
tte->save(posKey, value_to_tt(bestValue, ss->ply),
11361149
bestValue >= beta ? BOUND_LOWER :
11371150
PvNode && bestMove ? BOUND_EXACT : BOUND_UPPER,
@@ -1405,29 +1418,29 @@ namespace {
14051418
Square prevSq = to_sq((ss-1)->currentMove);
14061419
HistoryStats& cmh = CounterMovesHistory[pos.piece_on(prevSq)][prevSq];
14071420

1408-
History.update(pos.moved_piece(move), to_sq(move), bonus);
1421+
History.updateH(pos.moved_piece(move), to_sq(move), bonus);
14091422

14101423
if (is_ok((ss-1)->currentMove))
14111424
{
14121425
Countermoves.update(pos.piece_on(prevSq), prevSq, move);
1413-
cmh.update(pos.moved_piece(move), to_sq(move), bonus);
1426+
cmh.updateCMH(pos.moved_piece(move), to_sq(move), bonus);
14141427
}
14151428

14161429
// Decrease all the other played quiet moves
14171430
for (int i = 0; i < quietsCnt; ++i)
14181431
{
1419-
History.update(pos.moved_piece(quiets[i]), to_sq(quiets[i]), -bonus);
1432+
History.updateH(pos.moved_piece(quiets[i]), to_sq(quiets[i]), -bonus);
14201433

14211434
if (is_ok((ss-1)->currentMove))
1422-
cmh.update(pos.moved_piece(quiets[i]), to_sq(quiets[i]), -bonus);
1435+
cmh.updateCMH(pos.moved_piece(quiets[i]), to_sq(quiets[i]), -bonus);
14231436
}
14241437

14251438
// Extra penalty for PV move in previous ply when it gets refuted
14261439
if (is_ok((ss-2)->currentMove) && (ss-1)->moveCount == 1 && !pos.captured_piece_type())
14271440
{
14281441
Square prevPrevSq = to_sq((ss-2)->currentMove);
14291442
HistoryStats& ttMoveCmh = CounterMovesHistory[pos.piece_on(prevPrevSq)][prevPrevSq];
1430-
ttMoveCmh.update(pos.piece_on(prevSq), prevSq, -bonus - 2 * depth / ONE_PLY - 1);
1443+
ttMoveCmh.updateCMH(pos.piece_on(prevSq), prevSq, -bonus - 2 * depth / ONE_PLY - 1);
14311444
}
14321445
}
14331446

0 commit comments

Comments
 (0)