if (ei.pi->passed_pawns())
evaluate_passed_pawns(pos, ei);
- Phase phase = pos.game_phase();
+ Phase phase = ei.mi->game_phase();
// Middle-game specific evaluation terms
if (phase > PHASE_ENDGAME)
assert(pos.is_ok());
- static const
- ScaleFactor sf[2] = {SCALE_FACTOR_NORMAL, SCALE_FACTOR_NORMAL};
+ static const ScaleFactor sf[2] = {SCALE_FACTOR_NORMAL, SCALE_FACTOR_NORMAL};
- Phase ph = pos.game_phase();
- Color stm = pos.side_to_move();
-
- return Sign[stm] * scale_by_game_phase(pos.value(), ph, sf);
+ Value v = scale_by_game_phase(pos.value(), MaterialInfoTable::game_phase(pos), sf);
+ return (pos.side_to_move() == WHITE ? v : -v);
}
namespace {
+ // Values modified by Joona Kiiski
+ const Value MidgameLimit = Value(15581);
+ const Value EndgameLimit = Value(3998);
+
// Polynomial material balance parameters
const Value RedundantQueenPenalty = Value(320);
const Value RedundantRookPenalty = Value(554);
}
+/// MaterialInfoTable::game_phase() calculate the phase given the current
+/// position. Because the phase is strictly a function of the material, it
+/// is stored in MaterialInfo.
+
+Phase MaterialInfoTable::game_phase(const Position& pos) {
+
+ Value npm = pos.non_pawn_material(WHITE) + pos.non_pawn_material(BLACK);
+
+ if (npm >= MidgameLimit)
+ return PHASE_MIDGAME;
+ else if (npm <= EndgameLimit)
+ return PHASE_ENDGAME;
+
+ return Phase(((npm - EndgameLimit) * 128) / (MidgameLimit - EndgameLimit));
+}
+
/// MaterialInfoTable::get_material_info() takes a position object as input,
/// computes or looks up a MaterialInfo object, and returns a pointer to it.
/// If the material configuration is not already present in the table, it
mi->clear();
mi->key = key;
+ // Calculate game phase
+ mi->gamePhase = MaterialInfoTable::game_phase(pos);
+
// Let's look if we have a specialized evaluation function for this
// particular material configuration. First we look for a fixed
// configuration one, then a generic one if previous search failed.
Score material_value() const;
ScaleFactor scale_factor(const Position& pos, Color c) const;
int space_weight() const;
+ Phase game_phase() const;
bool specialized_eval_exists() const;
Value evaluate(const Position& pos) const;
EndgameEvaluationFunctionBase* evaluationFunction;
EndgameScalingFunctionBase* scalingFunction[2];
int spaceWeight;
+ Phase gamePhase;
};
/// The MaterialInfoTable class represents a pawn hash table. It is basically
~MaterialInfoTable();
MaterialInfo* get_material_info(const Position& pos);
+ static Phase game_phase(const Position& pos);
+
private:
unsigned size;
MaterialInfo* entries;
//// Inline functions
////
+
/// MaterialInfo::material_value simply returns the material balance
/// evaluation that is independent from game phase.
return spaceWeight;
}
+/// MaterialInfo::game_phase() returns the game phase according
+/// to this material configuration.
+
+inline Phase MaterialInfo::game_phase() const {
+
+ return gamePhase;
+}
+
/// MaterialInfo::specialized_eval_exists decides whether there is a
/// specialized evaluation function for the current material configuration,
// Incremental evaluation
Score value() const;
Value non_pawn_material(Color c) const;
- Phase game_phase() const;
Score pst_delta(Piece piece, Square from, Square to) const;
// Game termination checks
return st->npMaterial[c];
}
-inline Phase Position::game_phase() const {
-
- // Values modified by Joona Kiiski
- static const Value MidgameLimit = Value(15581);
- static const Value EndgameLimit = Value(3998);
-
- Value npm = non_pawn_material(WHITE) + non_pawn_material(BLACK);
-
- if (npm >= MidgameLimit)
- return PHASE_MIDGAME;
- else if(npm <= EndgameLimit)
- return PHASE_ENDGAME;
- else
- return Phase(((npm - EndgameLimit) * 128) / (MidgameLimit - EndgameLimit));
-}
-
inline bool Position::move_is_passed_pawn_push(Move m) const {
Color c = side_to_move();