From 3b315c9adab141830a81afbdff70c18336763e51 Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Fri, 20 Jun 2014 23:40:36 +0200 Subject: [PATCH] Move game_phase() to Position It seems a more natural to place this function there. No functional change. --- src/material.cpp | 16 +--------------- src/material.h | 1 - src/position.cpp | 12 ++++++++++++ src/position.h | 1 + 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/material.cpp b/src/material.cpp index 21b8ae33..b7db134b 100644 --- a/src/material.cpp +++ b/src/material.cpp @@ -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 diff --git a/src/material.h b/src/material.h index 91163610..f05541cc 100644 --- a/src/material.h +++ b/src/material.h @@ -68,7 +68,6 @@ struct Entry { typedef HashTable Table; Entry* probe(const Position& pos, Table& entries, Endgames& endgames); -Phase game_phase(const Position& pos); } // namespace Material diff --git a/src/position.cpp b/src/position.cpp index 2d511938..e2a59e5d 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -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 diff --git a/src/position.h b/src/position.h index 0f88944c..d950411f 100644 --- a/src/position.h +++ b/src/position.h @@ -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; -- 2.39.2