Skip to content

Commit b9768b8

Browse files
zamarmcostalba
authored andcommitted
Reintroduce gains
This seems a die hard idea :-) Passed both short TC LLR: 2.97 (-2.94,2.94) [-1.50,4.50] Total: 17485 W: 3307 L: 3156 D: 11022 And long TC LLR: 2.97 (-2.94,2.94) [0.00,6.00] Total: 38181 W: 6002 L: 5729 D: 26450 bench: 8659830
1 parent 4ef6b2c commit b9768b8

File tree

2 files changed

+31
-14
lines changed

2 files changed

+31
-14
lines changed

src/movepick.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,14 @@
3030

3131

3232
/// The Stats struct stores moves statistics. According to the template parameter
33-
/// the class can store History and Countermoves. History records how often
33+
/// the class can store History, Gains and Countermoves. History records how often
3434
/// different moves have been successful or unsuccessful during the current search
35-
/// and is used for reduction and move ordering decisions.
35+
/// and is used for reduction and move ordering decisions. Gains records the move's
36+
/// best evaluation gain from one ply to the next and is used for pruning decisions.
3637
/// Countermoves store the move that refute a previous one. Entries are stored
3738
/// according only to moving piece and destination square, hence two moves with
3839
/// different origin but same destination and piece will be considered identical.
39-
template<typename T>
40+
template<bool Gain, typename T>
4041
struct Stats {
4142

4243
static const Value Max = Value(2000);
@@ -55,16 +56,20 @@ struct Stats {
5556

5657
void update(Piece p, Square to, Value v) {
5758

58-
if (abs(table[p][to] + v) < Max)
59+
if (Gain)
60+
table[p][to] = std::max(v, table[p][to] - 1);
61+
62+
else if (abs(table[p][to] + v) < Max)
5963
table[p][to] += v;
6064
}
6165

6266
private:
6367
T table[PIECE_NB][SQUARE_NB];
6468
};
6569

66-
typedef Stats<Value> HistoryStats;
67-
typedef Stats<std::pair<Move, Move> > CountermovesStats;
70+
typedef Stats< true, Value> GainsStats;
71+
typedef Stats<false, Value> HistoryStats;
72+
typedef Stats<false, std::pair<Move, Move> > CountermovesStats;
6873

6974

7075
/// MovePicker class is used to pick one pseudo legal move at a time from the

src/search.cpp

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ namespace {
8282
double BestMoveChanges;
8383
Value DrawValue[COLOR_NB];
8484
HistoryStats History;
85+
GainsStats Gains;
8586
CountermovesStats Countermoves;
8687

8788
template <NodeType NT>
@@ -293,6 +294,7 @@ namespace {
293294
Value bestValue, alpha, beta, delta;
294295

295296
std::memset(ss-2, 0, 5 * sizeof(Stack));
297+
(ss-1)->currentMove = MOVE_NULL; // Hack to skip update gains
296298

297299
depth = 0;
298300
BestMoveChanges = 0;
@@ -301,6 +303,7 @@ namespace {
301303

302304
TT.new_search();
303305
History.clear();
306+
Gains.clear();
304307
Countermoves.clear();
305308

306309
PVSize = Options["MultiPV"];
@@ -487,9 +490,8 @@ namespace {
487490
SplitPoint* splitPoint;
488491
Key posKey;
489492
Move ttMove, move, excludedMove, bestMove, threatMove;
490-
Depth ext, newDepth;
491-
Value bestValue, value, ttValue;
492-
Value eval, nullValue;
493+
Depth ext, newDepth, predictedDepth;
494+
Value bestValue, value, ttValue, eval, nullValue, futilityValue;
493495
bool inCheck, givesCheck, pvMove, singularExtensionNode, improving;
494496
bool captureOrPromotion, dangerous, doFullDepthSearch;
495497
int moveCount, quietCount;
@@ -601,6 +603,16 @@ namespace {
601603
TT.store(posKey, VALUE_NONE, BOUND_NONE, DEPTH_NONE, MOVE_NONE, ss->staticEval);
602604
}
603605

606+
if ( !pos.captured_piece_type()
607+
&& ss->staticEval != VALUE_NONE
608+
&& (ss-1)->staticEval != VALUE_NONE
609+
&& (move = (ss-1)->currentMove) != MOVE_NULL
610+
&& type_of(move) == NORMAL)
611+
{
612+
Square to = to_sq(move);
613+
Gains.update(pos.piece_on(to), to, -(ss-1)->staticEval - ss->staticEval);
614+
}
615+
604616
// Step 6. Razoring (skipped when in check)
605617
if ( !PvNode
606618
&& depth < 4 * ONE_PLY
@@ -847,12 +859,13 @@ namespace {
847859
continue;
848860
}
849861

850-
Depth predictedDepth = newDepth - reduction<PvNode>(improving, depth, moveCount);
862+
predictedDepth = newDepth - reduction<PvNode>(improving, depth, moveCount);
851863

852864
// Futility pruning: parent node
853865
if (predictedDepth < 7 * ONE_PLY)
854866
{
855-
Value futilityValue = ss->staticEval + futility_margin(predictedDepth) + Value(128);
867+
futilityValue = ss->staticEval + futility_margin(predictedDepth)
868+
+ Value(128) + Gains[pos.moved_piece(move)][to_sq(move)];
856869

857870
if (futilityValue <= alpha)
858871
{
@@ -869,8 +882,7 @@ namespace {
869882
}
870883

871884
// Prune moves with negative SEE at low depths
872-
if ( predictedDepth < 4 * ONE_PLY
873-
&& pos.see_sign(move) < 0)
885+
if (predictedDepth < 4 * ONE_PLY && pos.see_sign(move) < 0)
874886
{
875887
if (SpNode)
876888
splitPoint->mutex.lock();
@@ -883,7 +895,7 @@ namespace {
883895
// Check for legality only before to do the move
884896
if (!RootNode && !SpNode && !pos.legal(move, ci.pinned))
885897
{
886-
--moveCount;
898+
moveCount--;
887899
continue;
888900
}
889901

0 commit comments

Comments
 (0)