void evaluate_passed_pawns(const Position& pos, EvalInfo& ei);
void evaluate_trapped_bishop_a7h7(const Position& pos, Square s, Color us, EvalInfo& ei);
void evaluate_trapped_bishop_a1h1(const Position& pos, Square s, Color us, EvalInfo& ei);
- inline Value apply_weight(Value v, int w);
+ inline Score apply_weight(Score v, int wmg, int weg);
Value scale_by_game_phase(const Score& v, Phase ph, const ScaleFactor sf[]);
int weight_option(const std::string& opt, int weight);
void init_safety();
// Initialize by reading the incrementally updated scores included in the
// position object (material + piece square tables)
- ei.value = Score(pos.mg_value(), pos.eg_value());
+ ei.value = pos.value();
// Probe the material hash table
ei.mi = MaterialTable[threadID]->get_material_info(pos);
- ei.value += Score(ei.mi->material_value(), ei.mi->material_value());
+ ei.value += ei.mi->material_value();
// If we have a specialized evaluation function for the current material
// configuration, call it and return
// Probe the pawn hash table
ei.pi = PawnTable[threadID]->get_pawn_info(pos);
- ei.value += Score(apply_weight(ei.pi->mg_value(), WeightPawnStructureMidgame),
- apply_weight(ei.pi->eg_value(), WeightPawnStructureEndgame));
+ ei.value += apply_weight(ei.pi->value(), WeightPawnStructureMidgame, WeightPawnStructureEndgame);
// Initialize king attack bitboards and king attack zones for both sides
ei.attackedBy[WHITE][KING] = pos.attacks_from<KING>(pos.king_square(WHITE));
}
// Mobility
- ei.value += Score(apply_weight(ei.mgMobility, WeightMobilityMidgame),
- apply_weight(ei.egMobility, WeightMobilityEndgame));
+ ei.value += apply_weight(Score(ei.mgMobility, ei.egMobility), WeightMobilityMidgame, WeightMobilityEndgame);
// If we don't already have an unusual scale factor, check for opposite
// colored bishop endgames, and use a lower scale for those
static const
ScaleFactor sf[2] = {SCALE_FACTOR_NORMAL, SCALE_FACTOR_NORMAL};
- Score v = Score(pos.mg_value(), pos.eg_value());
Phase ph = pos.game_phase();
Color stm = pos.side_to_move();
- return Sign[stm] * scale_by_game_phase(v, ph, sf);
+ return Sign[stm] * scale_by_game_phase(pos.value(), ph, sf);
}
if (relative_rank(Us, s) <= RANK_4)
{
shelter = ei.pi->get_king_shelter(pos, Us, s);
- ei.value += Score(Sign[Us] * Value(shelter), 0);
+ ei.value += Sign[Us] * Score(shelter, 0);
}
// King safety. This is quite complicated, and is almost certainly far
// that the king safety scores can sometimes be very big, and that
// capturing a single attacking piece can therefore result in a score
// change far bigger than the value of the captured piece.
- Value v = apply_weight(SafetyTable[attackUnits], WeightKingSafety[Us]);
+ Score v = apply_weight(Score(SafetyTable[attackUnits], 0), WeightKingSafety[Us], 0);
- ei.value -= Score(Sign[Us] * v, 0);
+ ei.value -= Sign[Us] * v;
if (Us == pos.side_to_move())
- ei.futilityMargin += v;
+ ei.futilityMargin += v.mg();
}
}
}
// Add the scores for this pawn to the middle game and endgame eval.
- ei.value += Score(apply_weight(Sign[Us] * mbonus, WeightPassedPawnsMidgame),
- apply_weight(Sign[Us] * ebonus, WeightPassedPawnsEndgame));
+ ei.value += Sign[Us] * apply_weight(Score(mbonus, ebonus), WeightPassedPawnsMidgame, WeightPassedPawnsEndgame);
} // while
}
int space = count_1s_max_15<HasPopCnt>(safeSquares)
+ count_1s_max_15<HasPopCnt>(behindFriendlyPawns & safeSquares);
- ei.value += Sign[Us] * Score(apply_weight(Value(space * ei.mi->space_weight()), WeightSpace), 0);
+ ei.value += Sign[Us] * apply_weight(Score(space * ei.mi->space_weight(), 0), WeightSpace, 0);
}
// apply_weight() applies an evaluation weight to a value
- inline Value apply_weight(Value v, int w) {
- return (v*w) / 0x100;
+ inline Score apply_weight(Score v, int wmg, int weg) {
+ return Score(v.mg() * wmg, v.eg() * weg) / 0x100;
}