Skip to content

Commit

Permalink
Better value clipping in game_phase()
Browse files Browse the repository at this point in the history
No functional change.
  • Loading branch information
mcostalba committed Jun 20, 2014
1 parent 3b315c9 commit 43efd7f
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/position.cpp
Expand Up @@ -465,15 +465,16 @@ const string Position::pretty(Move m) const {
}


/// Position::game_phase() calculates the game phase of the position
/// Position::game_phase() calculates the game phase interpolating total non-pawn
/// material between endgame and midgame limits.

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));
npm = std::max(EndgameLimit, std::min(npm, MidgameLimit));

return Phase(((npm - EndgameLimit) * 128) / (MidgameLimit - EndgameLimit));
}


Expand Down

0 comments on commit 43efd7f

Please sign in to comment.