Skip to content

Commit

Permalink
Move game_phase() to Position
Browse files Browse the repository at this point in the history
It seems a more natural to place this
function there.

No functional change.
  • Loading branch information
mcostalba committed Jun 20, 2014
1 parent f7926ea commit 3b315c9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 16 deletions.
16 changes: 1 addition & 15 deletions src/material.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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
1 change: 0 additions & 1 deletion src/material.h
Expand Up @@ -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

Expand Down
12 changes: 12 additions & 0 deletions src/position.cpp
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/position.h
Expand Up @@ -156,6 +156,7 @@ class Position {

// 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;
Expand Down

0 comments on commit 3b315c9

Please sign in to comment.