mirror of
https://github.com/HChaZZY/Stockfish.git
synced 2025-12-21 01:27:16 +08:00
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.
This commit is contained in:
@@ -635,10 +635,10 @@ namespace {
|
|||||||
// space evaluation is a simple bonus based on the number of safe squares
|
// 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
|
// 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
|
// 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
|
// twice. Finally, the space bonus is multiplied by a weight. The aim is to
|
||||||
// material hash table. The aim is to improve play on game opening.
|
// improve play on game opening.
|
||||||
template<Color Us>
|
template<Color Us>
|
||||||
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);
|
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||||
|
|
||||||
@@ -659,7 +659,11 @@ namespace {
|
|||||||
assert(unsigned(safe >> (Us == WHITE ? 32 : 0)) == 0);
|
assert(unsigned(safe >> (Us == WHITE ? 32 : 0)) == 0);
|
||||||
|
|
||||||
// Count safe + (behind & safe) with a single popcount
|
// Count safe + (behind & safe) with a single popcount
|
||||||
return popcount<Full>((Us == WHITE ? safe << 32 : safe >> 32) | (behind & safe)) * weight;
|
int bonus = popcount<Full>((Us == WHITE ? safe << 32 : safe >> 32) | (behind & safe));
|
||||||
|
int weight = pos.count<KNIGHT>(Us) + pos.count<BISHOP>(Us)
|
||||||
|
+ pos.count<KNIGHT>(Them) + pos.count<BISHOP>(Them);
|
||||||
|
|
||||||
|
return make_score(bonus * weight * weight, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -731,12 +735,10 @@ namespace {
|
|||||||
score -= int(relative_rank(BLACK, frontmost_sq(BLACK, b))) * Unstoppable;
|
score -= int(relative_rank(BLACK, frontmost_sq(BLACK, b))) * Unstoppable;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Evaluate space for both sides, only in middlegame
|
// Evaluate space for both sides, only during opening
|
||||||
if (ei.mi->space_weight())
|
if (pos.non_pawn_material(WHITE) + pos.non_pawn_material(BLACK) >= 2 * QueenValueMg + 4 * RookValueMg + 2 * KnightValueMg)
|
||||||
{
|
{
|
||||||
Score s = evaluate_space<WHITE>(pos, ei, ei.mi->space_weight())
|
Score s = evaluate_space<WHITE>(pos, ei) - evaluate_space<BLACK>(pos, ei);
|
||||||
- evaluate_space<BLACK>(pos, ei, ei.mi->space_weight());
|
|
||||||
|
|
||||||
score += apply_weight(s, Weights[Space]);
|
score += apply_weight(s, Weights[Space]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -784,9 +786,8 @@ namespace {
|
|||||||
Tracing::write(PAWN, ei.pi->pawns_score());
|
Tracing::write(PAWN, ei.pi->pawns_score());
|
||||||
Tracing::write(Tracing::MOBILITY, apply_weight(mobility[WHITE], Weights[Mobility])
|
Tracing::write(Tracing::MOBILITY, apply_weight(mobility[WHITE], Weights[Mobility])
|
||||||
, apply_weight(mobility[BLACK], Weights[Mobility]));
|
, apply_weight(mobility[BLACK], Weights[Mobility]));
|
||||||
Score w = evaluate_space<WHITE>(pos, ei, ei.mi->space_weight());
|
Tracing::write(Tracing::SPACE, apply_weight(evaluate_space<WHITE>(pos, ei), Weights[Space])
|
||||||
Score b = evaluate_space<BLACK>(pos, ei, ei.mi->space_weight());
|
, apply_weight(evaluate_space<BLACK>(pos, ei), Weights[Space]));
|
||||||
Tracing::write(Tracing::SPACE, apply_weight(w, Weights[Space]), apply_weight(b, Weights[Space]));
|
|
||||||
Tracing::write(Tracing::TOTAL, score);
|
Tracing::write(Tracing::TOTAL, score);
|
||||||
Tracing::ei = ei;
|
Tracing::ei = ei;
|
||||||
Tracing::sf = sf;
|
Tracing::sf = sf;
|
||||||
|
|||||||
@@ -223,15 +223,6 @@ Entry* probe(const Position& pos, Table& entries, Endgames& endgames) {
|
|||||||
if (pos.count<PAWN>(BLACK) == 1 && npm_b - npm_w <= BishopValueMg)
|
if (pos.count<PAWN>(BLACK) == 1 && npm_b - npm_w <= BishopValueMg)
|
||||||
e->factor[BLACK] = (uint8_t) SCALE_FACTOR_ONEPAWN;
|
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<KNIGHT>(WHITE) + pos.count<BISHOP>(WHITE)
|
|
||||||
+ pos.count<KNIGHT>(BLACK) + pos.count<BISHOP>(BLACK);
|
|
||||||
|
|
||||||
e->spaceWeight = make_score(minorPieceCount * minorPieceCount, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Evaluate the material imbalance. We use PIECE_TYPE_NONE as a place holder
|
// 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
|
// for the bishop pair "extended piece", which allows us to be more flexible
|
||||||
// in defining bishop pair bonuses.
|
// in defining bishop pair bonuses.
|
||||||
|
|||||||
@@ -39,7 +39,6 @@ namespace Material {
|
|||||||
struct Entry {
|
struct Entry {
|
||||||
|
|
||||||
Score imbalance() const { return make_score(value, value); }
|
Score imbalance() const { return make_score(value, value); }
|
||||||
Score space_weight() const { return spaceWeight; }
|
|
||||||
Phase game_phase() const { return gamePhase; }
|
Phase game_phase() const { return gamePhase; }
|
||||||
bool specialized_eval_exists() const { return evaluationFunction != NULL; }
|
bool specialized_eval_exists() const { return evaluationFunction != NULL; }
|
||||||
Value evaluate(const Position& pos) const { return (*evaluationFunction)(pos); }
|
Value evaluate(const Position& pos) const { return (*evaluationFunction)(pos); }
|
||||||
@@ -61,7 +60,6 @@ struct Entry {
|
|||||||
uint8_t factor[COLOR_NB];
|
uint8_t factor[COLOR_NB];
|
||||||
EndgameBase<Value>* evaluationFunction;
|
EndgameBase<Value>* evaluationFunction;
|
||||||
EndgameBase<ScaleFactor>* scalingFunction[COLOR_NB];
|
EndgameBase<ScaleFactor>* scalingFunction[COLOR_NB];
|
||||||
Score spaceWeight;
|
|
||||||
Phase gamePhase;
|
Phase gamePhase;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user