1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-04-30 16:53:09 +00:00

Move game_phase() to Position

It seems a more natural to place this
function there.

No functional change.
This commit is contained in:
Marco Costalba 2014-06-20 23:40:36 +02:00
parent f7926ea41e
commit 3b315c9ada
4 changed files with 14 additions and 16 deletions

View file

@ -136,7 +136,7 @@ Entry* probe(const Position& pos, Table& entries, Endgames& endgames) {
std::memset(e, 0, sizeof(Entry));
e->key = key;
e->factor[WHITE] = e->factor[BLACK] = (uint8_t)SCALE_FACTOR_NORMAL;
e->gamePhase = game_phase(pos);
e->gamePhase = pos.game_phase();
// Let's look if we have a specialized evaluation function for this particular
// material configuration. Firstly we look for a fixed configuration one, then
@ -245,18 +245,4 @@ Entry* probe(const Position& pos, Table& entries, Endgames& endgames) {
return e;
}
/// Material::game_phase() calculates the phase given the current
/// position. Because the phase is strictly a function of the material, it
/// is stored in MaterialEntry.
Phase game_phase(const Position& pos) {
Value npm = pos.non_pawn_material(WHITE) + pos.non_pawn_material(BLACK);
return npm >= MidgameLimit ? PHASE_MIDGAME
: npm <= EndgameLimit ? PHASE_ENDGAME
: Phase(((npm - EndgameLimit) * 128) / (MidgameLimit - EndgameLimit));
}
} // namespace Material

View file

@ -68,7 +68,6 @@ struct Entry {
typedef HashTable<Entry, 8192> Table;
Entry* probe(const Position& pos, Table& entries, Endgames& endgames);
Phase game_phase(const Position& pos);
} // namespace Material

View file

@ -465,6 +465,18 @@ const string Position::pretty(Move m) const {
}
/// Position::game_phase() calculates the game phase of the position
Phase Position::game_phase() const {
Value npm = st->npMaterial[WHITE] + st->npMaterial[BLACK];
return npm >= MidgameLimit ? PHASE_MIDGAME
: npm <= EndgameLimit ? PHASE_ENDGAME
: Phase(((npm - EndgameLimit) * 128) / (MidgameLimit - EndgameLimit));
}
/// Position::check_blockers() returns a bitboard of all the pieces with color
/// 'c' that are blocking check on the king with color 'kingColor'. A piece
/// blocks a check if removing that piece from the board would result in a

View file

@ -156,6 +156,7 @@ public:
// Other properties of the position
Color side_to_move() const;
Phase game_phase() const;
int game_ply() const;
bool is_chess960() const;
Thread* this_thread() const;