Skip to content

Commit eed508b

Browse files
lucasartmcostalba
authored andcommitted
Futility pruning simplification
1/ eval margin and gains removed: 16bit are now free on TT entries, due to the removal of eval margin. may be useful in the future :) gains removed: use instead by Value(128). search() and qsearch() are now consistent in this regard. 2/ futility_margin() linear formula instead of complex (log(depth), movecount) formula. 3/ unify pre & post futility pruning pre futility pruning used depth < 7 plies, while post futility pruning used depth < 4 plies. Now it's always depth < 7. Tested with fixed number of games both at short TC: ELO: 0.82 +-2.1 (95%) LOS: 77.3% Total: 40000 W: 7939 L: 7845 D: 24216 And long TC ELO: 0.59 +-2.0 (95%) LOS: 71.9% Total: 40000 W: 6876 L: 6808 D: 26316 bench 7243575
1 parent 343544f commit eed508b

File tree

7 files changed

+59
-116
lines changed

7 files changed

+59
-116
lines changed

src/evaluate.cpp

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ namespace {
229229

230230
// Function prototypes
231231
template<bool Trace>
232-
Value do_evaluate(const Position& pos, Value& margin);
232+
Value do_evaluate(const Position& pos);
233233

234234
template<Color Us>
235235
void init_eval_info(const Position& pos, EvalInfo& ei);
@@ -238,7 +238,7 @@ namespace {
238238
Score evaluate_pieces_of_color(const Position& pos, EvalInfo& ei, Score* mobility);
239239

240240
template<Color Us, bool Trace>
241-
Score evaluate_king(const Position& pos, const EvalInfo& ei, Value margins[]);
241+
Score evaluate_king(const Position& pos, const EvalInfo& ei);
242242

243243
template<Color Us, bool Trace>
244244
Score evaluate_threats(const Position& pos, const EvalInfo& ei);
@@ -264,8 +264,8 @@ namespace Eval {
264264
/// values, an endgame score and a middle game score, and interpolates
265265
/// between them based on the remaining material.
266266

267-
Value evaluate(const Position& pos, Value& margin) {
268-
return do_evaluate<false>(pos, margin);
267+
Value evaluate(const Position& pos) {
268+
return do_evaluate<false>(pos);
269269
}
270270

271271

@@ -307,19 +307,14 @@ namespace Eval {
307307
namespace {
308308

309309
template<bool Trace>
310-
Value do_evaluate(const Position& pos, Value& margin) {
310+
Value do_evaluate(const Position& pos) {
311311

312312
assert(!pos.checkers());
313313

314314
EvalInfo ei;
315-
Value margins[COLOR_NB];
316315
Score score, mobility[2] = { SCORE_ZERO, SCORE_ZERO };
317316
Thread* th = pos.this_thread();
318317

319-
// margins[] store the uncertainty estimation of position's evaluation
320-
// that typically is used by the search for pruning decisions.
321-
margins[WHITE] = margins[BLACK] = VALUE_ZERO;
322-
323318
// Initialize score by reading the incrementally updated scores included
324319
// in the position object (material + piece square tables) and adding
325320
// Tempo bonus. Score is computed from the point of view of white.
@@ -332,10 +327,7 @@ Value do_evaluate(const Position& pos, Value& margin) {
332327
// If we have a specialized evaluation function for the current material
333328
// configuration, call it and return.
334329
if (ei.mi->specialized_eval_exists())
335-
{
336-
margin = VALUE_ZERO;
337330
return ei.mi->evaluate(pos);
338-
}
339331

340332
// Probe the pawn hash table
341333
ei.pi = Pawns::probe(pos, th->pawnsTable);
@@ -353,8 +345,8 @@ Value do_evaluate(const Position& pos, Value& margin) {
353345

354346
// Evaluate kings after all other pieces because we need complete attack
355347
// information when computing the king safety evaluation.
356-
score += evaluate_king<WHITE, Trace>(pos, ei, margins)
357-
- evaluate_king<BLACK, Trace>(pos, ei, margins);
348+
score += evaluate_king<WHITE, Trace>(pos, ei)
349+
- evaluate_king<BLACK, Trace>(pos, ei);
358350

359351
// Evaluate tactical threats, we need full attack information including king
360352
score += evaluate_threats<WHITE, Trace>(pos, ei)
@@ -401,7 +393,6 @@ Value do_evaluate(const Position& pos, Value& margin) {
401393
sf = ScaleFactor(50);
402394
}
403395

404-
margin = margins[pos.side_to_move()];
405396
Value v = interpolate(score, ei.mi->game_phase(), sf);
406397

407398
// In case of tracing add all single evaluation contributions for both white and black
@@ -414,9 +405,7 @@ Value do_evaluate(const Position& pos, Value& margin) {
414405
Score b = ei.mi->space_weight() * evaluate_space<BLACK>(pos, ei);
415406
Tracing::add(SPACE, apply_weight(w, Weights[Space]), apply_weight(b, Weights[Space]));
416407
Tracing::add(TOTAL, score);
417-
Tracing::stream << "\nUncertainty margin: White: " << to_cp(margins[WHITE])
418-
<< ", Black: " << to_cp(margins[BLACK])
419-
<< "\nScaling: " << std::noshowpos
408+
Tracing::stream << "\nScaling: " << std::noshowpos
420409
<< std::setw(6) << 100.0 * ei.mi->game_phase() / 128.0 << "% MG, "
421410
<< std::setw(6) << 100.0 * (1.0 - ei.mi->game_phase() / 128.0) << "% * "
422411
<< std::setw(6) << (100.0 * sf) / SCALE_FACTOR_NORMAL << "% EG.\n"
@@ -640,7 +629,7 @@ Value do_evaluate(const Position& pos, Value& margin) {
640629
// evaluate_king() assigns bonuses and penalties to a king of a given color
641630

642631
template<Color Us, bool Trace>
643-
Score evaluate_king(const Position& pos, const EvalInfo& ei, Value margins[]) {
632+
Score evaluate_king(const Position& pos, const EvalInfo& ei) {
644633

645634
const Color Them = (Us == WHITE ? BLACK : WHITE);
646635

@@ -735,12 +724,8 @@ Value do_evaluate(const Position& pos, Value& margin) {
735724
attackUnits = std::min(99, std::max(0, attackUnits));
736725

737726
// Finally, extract the king danger score from the KingDanger[]
738-
// array and subtract the score from evaluation. Set also margins[]
739-
// value that will be used for pruning because this value can sometimes
740-
// be very big, and so capturing a single attacking piece can therefore
741-
// result in a score change far bigger than the value of the captured piece.
727+
// array and subtract the score from evaluation.
742728
score -= KingDanger[Us == Search::RootColor][attackUnits];
743-
margins[Us] += mg_value(KingDanger[Us == Search::RootColor][attackUnits]);
744729
}
745730

746731
if (Trace)
@@ -1024,8 +1009,7 @@ Value do_evaluate(const Position& pos, Value& margin) {
10241009
stream << std::showpoint << std::showpos << std::fixed << std::setprecision(2);
10251010
std::memset(scores, 0, 2 * (TOTAL + 1) * sizeof(Score));
10261011

1027-
Value margin;
1028-
do_evaluate<true>(pos, margin);
1012+
do_evaluate<true>(pos);
10291013

10301014
std::string totals = stream.str();
10311015
stream.str("");

src/evaluate.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Position;
2727
namespace Eval {
2828

2929
extern void init();
30-
extern Value evaluate(const Position& pos, Value& margin);
30+
extern Value evaluate(const Position& pos);
3131
extern std::string trace(const Position& pos);
3232

3333
}

src/movepick.h

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

3131

3232
/// The Stats struct stores moves statistics. According to the template parameter
33-
/// the class can store History, Gains and Countermoves. History records how often
33+
/// the class can store History 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. Gains records the move's
36-
/// best evaluation gain from one ply to the next and is used for pruning decisions.
35+
/// and is used for reduction and move ordering decisions.
3736
/// Countermoves store the move that refute a previous one. Entries are stored
3837
/// according only to moving piece and destination square, hence two moves with
3938
/// different origin but same destination and piece will be considered identical.
40-
template<bool Gain, typename T>
39+
template<typename T>
4140
struct Stats {
4241

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

5756
void update(Piece p, Square to, Value v) {
5857

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

6662
private:
6763
T table[PIECE_NB][SQUARE_NB];
6864
};
6965

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

7469

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

0 commit comments

Comments
 (0)