mirror of
https://github.com/sockspls/badfish
synced 2025-05-01 17:19:36 +00:00
Convert MaterialInfo and PawnInfo to use Score
No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
dda7e4639a
commit
4626ec2890
4 changed files with 17 additions and 19 deletions
|
@ -320,6 +320,7 @@ namespace {
|
||||||
void evaluate_trapped_bishop_a7h7(const Position& pos, Square s, Color us, 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);
|
void evaluate_trapped_bishop_a1h1(const Position& pos, Square s, Color us, EvalInfo& ei);
|
||||||
inline Value apply_weight(Value v, int w);
|
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[]);
|
Value scale_by_game_phase(const Score& v, Phase ph, const ScaleFactor sf[]);
|
||||||
int weight_option(const std::string& opt, int weight);
|
int weight_option(const std::string& opt, int weight);
|
||||||
void init_safety();
|
void init_safety();
|
||||||
|
@ -356,7 +357,7 @@ Value do_evaluate(const Position& pos, EvalInfo& ei, int threadID) {
|
||||||
|
|
||||||
// Probe the material hash table
|
// Probe the material hash table
|
||||||
ei.mi = MaterialTable[threadID]->get_material_info(pos);
|
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
|
// If we have a specialized evaluation function for the current material
|
||||||
// configuration, call it and return
|
// configuration, call it and return
|
||||||
|
@ -370,8 +371,7 @@ Value do_evaluate(const Position& pos, EvalInfo& ei, int threadID) {
|
||||||
|
|
||||||
// Probe the pawn hash table
|
// Probe the pawn hash table
|
||||||
ei.pi = PawnTable[threadID]->get_pawn_info(pos);
|
ei.pi = PawnTable[threadID]->get_pawn_info(pos);
|
||||||
ei.value += Score(apply_weight(ei.pi->mg_value(), WeightPawnStructureMidgame),
|
ei.value += apply_weight(ei.pi->value(), WeightPawnStructureMidgame, WeightPawnStructureEndgame);
|
||||||
apply_weight(ei.pi->eg_value(), WeightPawnStructureEndgame));
|
|
||||||
|
|
||||||
// Initialize king attack bitboards and king attack zones for both sides
|
// Initialize king attack bitboards and king attack zones for both sides
|
||||||
ei.attackedBy[WHITE][KING] = pos.attacks_from<KING>(pos.king_square(WHITE));
|
ei.attackedBy[WHITE][KING] = pos.attacks_from<KING>(pos.king_square(WHITE));
|
||||||
|
@ -436,8 +436,7 @@ Value do_evaluate(const Position& pos, EvalInfo& ei, int threadID) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mobility
|
// Mobility
|
||||||
ei.value += Score(apply_weight(ei.mgMobility, WeightMobilityMidgame),
|
ei.value += apply_weight(Score(ei.mgMobility, ei.egMobility), WeightMobilityMidgame, WeightMobilityEndgame);
|
||||||
apply_weight(ei.egMobility, WeightMobilityEndgame));
|
|
||||||
|
|
||||||
// If we don't already have an unusual scale factor, check for opposite
|
// If we don't already have an unusual scale factor, check for opposite
|
||||||
// colored bishop endgames, and use a lower scale for those
|
// colored bishop endgames, and use a lower scale for those
|
||||||
|
@ -789,7 +788,7 @@ namespace {
|
||||||
if (relative_rank(Us, s) <= RANK_4)
|
if (relative_rank(Us, s) <= RANK_4)
|
||||||
{
|
{
|
||||||
shelter = ei.pi->get_king_shelter(pos, Us, s);
|
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
|
// King safety. This is quite complicated, and is almost certainly far
|
||||||
|
@ -938,7 +937,7 @@ namespace {
|
||||||
// change far bigger than the value of the captured piece.
|
// change far bigger than the value of the captured piece.
|
||||||
Value v = apply_weight(SafetyTable[attackUnits], WeightKingSafety[Us]);
|
Value v = apply_weight(SafetyTable[attackUnits], WeightKingSafety[Us]);
|
||||||
|
|
||||||
ei.value -= Score(Sign[Us] * v, 0);
|
ei.value -= Sign[Us] * Score(v, 0);
|
||||||
|
|
||||||
if (Us == pos.side_to_move())
|
if (Us == pos.side_to_move())
|
||||||
ei.futilityMargin += v;
|
ei.futilityMargin += v;
|
||||||
|
@ -1240,6 +1239,10 @@ namespace {
|
||||||
return (v*w) / 0x100;
|
return (v*w) / 0x100;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline Score apply_weight(Score v, int wmg, int weg) {
|
||||||
|
return Score(v.mg()*wmg, v.eg()*weg) / 0x100;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// scale_by_game_phase() interpolates between a middle game and an endgame
|
// scale_by_game_phase() interpolates between a middle game and an endgame
|
||||||
// score, based on game phase. It also scales the return value by a
|
// score, based on game phase. It also scales the return value by a
|
||||||
|
|
|
@ -51,7 +51,7 @@ class MaterialInfo {
|
||||||
public:
|
public:
|
||||||
MaterialInfo() : key(0) { clear(); }
|
MaterialInfo() : key(0) { clear(); }
|
||||||
|
|
||||||
Value material_value() const;
|
Score material_value() const;
|
||||||
ScaleFactor scale_factor(const Position& pos, Color c) const;
|
ScaleFactor scale_factor(const Position& pos, Color c) const;
|
||||||
int space_weight() const;
|
int space_weight() const;
|
||||||
bool specialized_eval_exists() const;
|
bool specialized_eval_exists() const;
|
||||||
|
@ -95,9 +95,9 @@ private:
|
||||||
/// MaterialInfo::material_value simply returns the material balance
|
/// MaterialInfo::material_value simply returns the material balance
|
||||||
/// evaluation that is independent from game phase.
|
/// evaluation that is independent from game phase.
|
||||||
|
|
||||||
inline Value MaterialInfo::material_value() const {
|
inline Score MaterialInfo::material_value() const {
|
||||||
|
|
||||||
return Value(value);
|
return Score(value, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
11
src/pawns.h
11
src/pawns.h
|
@ -47,8 +47,7 @@ class PawnInfo {
|
||||||
public:
|
public:
|
||||||
PawnInfo() { clear(); }
|
PawnInfo() { clear(); }
|
||||||
|
|
||||||
Value mg_value() const;
|
Score value() const;
|
||||||
Value eg_value() const;
|
|
||||||
Value kingside_storm_value(Color c) const;
|
Value kingside_storm_value(Color c) const;
|
||||||
Value queenside_storm_value(Color c) const;
|
Value queenside_storm_value(Color c) const;
|
||||||
Bitboard pawn_attacks(Color c) const;
|
Bitboard pawn_attacks(Color c) const;
|
||||||
|
@ -99,12 +98,8 @@ private:
|
||||||
//// Inline functions
|
//// Inline functions
|
||||||
////
|
////
|
||||||
|
|
||||||
inline Value PawnInfo::mg_value() const {
|
inline Score PawnInfo::value() const {
|
||||||
return Value(mgValue);
|
return Score(mgValue, egValue);
|
||||||
}
|
|
||||||
|
|
||||||
inline Value PawnInfo::eg_value() const {
|
|
||||||
return Value(egValue);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard PawnInfo::passed_pawns() const {
|
inline Bitboard PawnInfo::passed_pawns() const {
|
||||||
|
|
|
@ -721,7 +721,7 @@ void Position::do_move(Move m, StateInfo& newSt, Bitboard dcCandidates) {
|
||||||
Key key, pawnKey, materialKey;
|
Key key, pawnKey, materialKey;
|
||||||
int castleRights, rule50, pliesFromNull;
|
int castleRights, rule50, pliesFromNull;
|
||||||
Square epSquare;
|
Square epSquare;
|
||||||
Value mgValue, egValue;
|
Value value;
|
||||||
Value npMaterial[2];
|
Value npMaterial[2];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue