mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 08:43:09 +00:00
Move game phase computation to MaterialInfo
Game phase is a strictly function of the material combination so its natural place is MaterialInfo, not position. No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
314faa905a
commit
71e852ea81
4 changed files with 40 additions and 24 deletions
|
@ -370,7 +370,7 @@ Value do_evaluate(const Position& pos, EvalInfo& ei, int threadID) {
|
||||||
if (ei.pi->passed_pawns())
|
if (ei.pi->passed_pawns())
|
||||||
evaluate_passed_pawns(pos, ei);
|
evaluate_passed_pawns(pos, ei);
|
||||||
|
|
||||||
Phase phase = pos.game_phase();
|
Phase phase = ei.mi->game_phase();
|
||||||
|
|
||||||
// Middle-game specific evaluation terms
|
// Middle-game specific evaluation terms
|
||||||
if (phase > PHASE_ENDGAME)
|
if (phase > PHASE_ENDGAME)
|
||||||
|
@ -444,13 +444,10 @@ Value quick_evaluate(const Position &pos) {
|
||||||
|
|
||||||
assert(pos.is_ok());
|
assert(pos.is_ok());
|
||||||
|
|
||||||
static const
|
static const ScaleFactor sf[2] = {SCALE_FACTOR_NORMAL, SCALE_FACTOR_NORMAL};
|
||||||
ScaleFactor sf[2] = {SCALE_FACTOR_NORMAL, SCALE_FACTOR_NORMAL};
|
|
||||||
|
|
||||||
Phase ph = pos.game_phase();
|
Value v = scale_by_game_phase(pos.value(), MaterialInfoTable::game_phase(pos), sf);
|
||||||
Color stm = pos.side_to_move();
|
return (pos.side_to_move() == WHITE ? v : -v);
|
||||||
|
|
||||||
return Sign[stm] * scale_by_game_phase(pos.value(), ph, sf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,10 @@ using namespace std;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
// Values modified by Joona Kiiski
|
||||||
|
const Value MidgameLimit = Value(15581);
|
||||||
|
const Value EndgameLimit = Value(3998);
|
||||||
|
|
||||||
// Polynomial material balance parameters
|
// Polynomial material balance parameters
|
||||||
const Value RedundantQueenPenalty = Value(320);
|
const Value RedundantQueenPenalty = Value(320);
|
||||||
const Value RedundantRookPenalty = Value(554);
|
const Value RedundantRookPenalty = Value(554);
|
||||||
|
@ -129,6 +133,22 @@ MaterialInfoTable::~MaterialInfoTable() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// 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,
|
/// MaterialInfoTable::get_material_info() takes a position object as input,
|
||||||
/// computes or looks up a MaterialInfo object, and returns a pointer to it.
|
/// 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
|
/// If the material configuration is not already present in the table, it
|
||||||
|
@ -151,6 +171,9 @@ MaterialInfo* MaterialInfoTable::get_material_info(const Position& pos) {
|
||||||
mi->clear();
|
mi->clear();
|
||||||
mi->key = key;
|
mi->key = key;
|
||||||
|
|
||||||
|
// Calculate game phase
|
||||||
|
mi->gamePhase = MaterialInfoTable::game_phase(pos);
|
||||||
|
|
||||||
// Let's look if we have a specialized evaluation function for this
|
// Let's look if we have a specialized evaluation function for this
|
||||||
// particular material configuration. First we look for a fixed
|
// particular material configuration. First we look for a fixed
|
||||||
// configuration one, then a generic one if previous search failed.
|
// configuration one, then a generic one if previous search failed.
|
||||||
|
|
|
@ -54,6 +54,7 @@ public:
|
||||||
Score 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;
|
||||||
|
Phase game_phase() const;
|
||||||
bool specialized_eval_exists() const;
|
bool specialized_eval_exists() const;
|
||||||
Value evaluate(const Position& pos) const;
|
Value evaluate(const Position& pos) const;
|
||||||
|
|
||||||
|
@ -66,6 +67,7 @@ private:
|
||||||
EndgameEvaluationFunctionBase* evaluationFunction;
|
EndgameEvaluationFunctionBase* evaluationFunction;
|
||||||
EndgameScalingFunctionBase* scalingFunction[2];
|
EndgameScalingFunctionBase* scalingFunction[2];
|
||||||
int spaceWeight;
|
int spaceWeight;
|
||||||
|
Phase gamePhase;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The MaterialInfoTable class represents a pawn hash table. It is basically
|
/// The MaterialInfoTable class represents a pawn hash table. It is basically
|
||||||
|
@ -81,6 +83,8 @@ public:
|
||||||
~MaterialInfoTable();
|
~MaterialInfoTable();
|
||||||
MaterialInfo* get_material_info(const Position& pos);
|
MaterialInfo* get_material_info(const Position& pos);
|
||||||
|
|
||||||
|
static Phase game_phase(const Position& pos);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
unsigned size;
|
unsigned size;
|
||||||
MaterialInfo* entries;
|
MaterialInfo* entries;
|
||||||
|
@ -92,6 +96,7 @@ private:
|
||||||
//// Inline functions
|
//// Inline functions
|
||||||
////
|
////
|
||||||
|
|
||||||
|
|
||||||
/// 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.
|
||||||
|
|
||||||
|
@ -141,6 +146,14 @@ inline int MaterialInfo::space_weight() const {
|
||||||
return spaceWeight;
|
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
|
/// MaterialInfo::specialized_eval_exists decides whether there is a
|
||||||
/// specialized evaluation function for the current material configuration,
|
/// specialized evaluation function for the current material configuration,
|
||||||
|
|
|
@ -255,7 +255,6 @@ public:
|
||||||
// Incremental evaluation
|
// Incremental evaluation
|
||||||
Score value() const;
|
Score value() const;
|
||||||
Value non_pawn_material(Color c) const;
|
Value non_pawn_material(Color c) const;
|
||||||
Phase game_phase() const;
|
|
||||||
Score pst_delta(Piece piece, Square from, Square to) const;
|
Score pst_delta(Piece piece, Square from, Square to) const;
|
||||||
|
|
||||||
// Game termination checks
|
// Game termination checks
|
||||||
|
@ -526,22 +525,6 @@ inline Value Position::non_pawn_material(Color c) const {
|
||||||
return st->npMaterial[c];
|
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 {
|
inline bool Position::move_is_passed_pawn_push(Move m) const {
|
||||||
|
|
||||||
Color c = side_to_move();
|
Color c = side_to_move();
|
||||||
|
|
Loading…
Add table
Reference in a new issue