From 4c9b42316112efc7383c27570102d5d528d6af0a Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Wed, 31 Dec 2014 10:41:20 +0100 Subject: [PATCH] Retire Material::space_weight() Move all in evaluation. Simplify the code and concentrate in a single place all the logic behind space evaluation, making it much more clear. Verified also at STC it does not regress due to a possible slow down: LLR: 3.91 (-2.94,2.94) [-3.00,1.00] Total: 65744 W: 13285 L: 13194 D: 39265 No functional change. --- src/evaluate.cpp | 25 +++++++++++++------------ src/material.cpp | 9 --------- src/material.h | 2 -- 3 files changed, 13 insertions(+), 23 deletions(-) diff --git a/src/evaluate.cpp b/src/evaluate.cpp index 85ac0dab..e4c2bbcb 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -635,10 +635,10 @@ namespace { // space evaluation is a simple bonus based on the number of safe squares // available for minor pieces on the central four files on ranks 2--4. Safe // squares one, two or three squares behind a friendly pawn are counted - // twice. Finally, the space bonus is scaled by a weight taken from the - // material hash table. The aim is to improve play on game opening. + // twice. Finally, the space bonus is multiplied by a weight. The aim is to + // improve play on game opening. template - Score evaluate_space(const Position& pos, const EvalInfo& ei, Score weight) { + Score evaluate_space(const Position& pos, const EvalInfo& ei) { const Color Them = (Us == WHITE ? BLACK : WHITE); @@ -659,7 +659,11 @@ namespace { assert(unsigned(safe >> (Us == WHITE ? 32 : 0)) == 0); // Count safe + (behind & safe) with a single popcount - return popcount((Us == WHITE ? safe << 32 : safe >> 32) | (behind & safe)) * weight; + int bonus = popcount((Us == WHITE ? safe << 32 : safe >> 32) | (behind & safe)); + int weight = pos.count(Us) + pos.count(Us) + + pos.count(Them) + pos.count(Them); + + return make_score(bonus * weight * weight, 0); } @@ -731,12 +735,10 @@ namespace { score -= int(relative_rank(BLACK, frontmost_sq(BLACK, b))) * Unstoppable; } - // Evaluate space for both sides, only in middlegame - if (ei.mi->space_weight()) + // Evaluate space for both sides, only during opening + if (pos.non_pawn_material(WHITE) + pos.non_pawn_material(BLACK) >= 2 * QueenValueMg + 4 * RookValueMg + 2 * KnightValueMg) { - Score s = evaluate_space(pos, ei, ei.mi->space_weight()) - - evaluate_space(pos, ei, ei.mi->space_weight()); - + Score s = evaluate_space(pos, ei) - evaluate_space(pos, ei); score += apply_weight(s, Weights[Space]); } @@ -784,9 +786,8 @@ namespace { Tracing::write(PAWN, ei.pi->pawns_score()); Tracing::write(Tracing::MOBILITY, apply_weight(mobility[WHITE], Weights[Mobility]) , apply_weight(mobility[BLACK], Weights[Mobility])); - Score w = evaluate_space(pos, ei, ei.mi->space_weight()); - Score b = evaluate_space(pos, ei, ei.mi->space_weight()); - Tracing::write(Tracing::SPACE, apply_weight(w, Weights[Space]), apply_weight(b, Weights[Space])); + Tracing::write(Tracing::SPACE, apply_weight(evaluate_space(pos, ei), Weights[Space]) + , apply_weight(evaluate_space(pos, ei), Weights[Space])); Tracing::write(Tracing::TOTAL, score); Tracing::ei = ei; Tracing::sf = sf; diff --git a/src/material.cpp b/src/material.cpp index 7047afb1..6aeb117a 100644 --- a/src/material.cpp +++ b/src/material.cpp @@ -223,15 +223,6 @@ Entry* probe(const Position& pos, Table& entries, Endgames& endgames) { if (pos.count(BLACK) == 1 && npm_b - npm_w <= BishopValueMg) e->factor[BLACK] = (uint8_t) SCALE_FACTOR_ONEPAWN; - // Compute the space weight - if (npm_w + npm_b >= 2 * QueenValueMg + 4 * RookValueMg + 2 * KnightValueMg) - { - int minorPieceCount = pos.count(WHITE) + pos.count(WHITE) - + pos.count(BLACK) + pos.count(BLACK); - - e->spaceWeight = make_score(minorPieceCount * minorPieceCount, 0); - } - // Evaluate the material imbalance. We use PIECE_TYPE_NONE as a place holder // for the bishop pair "extended piece", which allows us to be more flexible // in defining bishop pair bonuses. diff --git a/src/material.h b/src/material.h index 754d0523..581e7585 100644 --- a/src/material.h +++ b/src/material.h @@ -39,7 +39,6 @@ namespace Material { struct Entry { Score imbalance() const { return make_score(value, value); } - Score space_weight() const { return spaceWeight; } Phase game_phase() const { return gamePhase; } bool specialized_eval_exists() const { return evaluationFunction != NULL; } Value evaluate(const Position& pos) const { return (*evaluationFunction)(pos); } @@ -61,7 +60,6 @@ struct Entry { uint8_t factor[COLOR_NB]; EndgameBase* evaluationFunction; EndgameBase* scalingFunction[COLOR_NB]; - Score spaceWeight; Phase gamePhase; }; -- 2.39.2