]> git.sesse.net Git - stockfish/commitdiff
Move game_phase() to Position
authorMarco Costalba <mcostalba@gmail.com>
Fri, 20 Jun 2014 21:40:36 +0000 (23:40 +0200)
committerMarco Costalba <mcostalba@gmail.com>
Fri, 20 Jun 2014 21:44:46 +0000 (23:44 +0200)
It seems a more natural to place this
function there.

No functional change.

src/material.cpp
src/material.h
src/position.cpp
src/position.h

index 21b8ae3304a01bad8c52ce5e97399f1feb60a21d..b7db134b9aa35d0a43dae7d4355f71af34a65327 100644 (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
index 91163610e708ce7c1bbd4e222f7f6115dee60f57..f05541cc3b24e6fd52c1c9265ce69d09048ecdd6 100644 (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
 
index 2d5119389b989c0719c1514dd330ad7ddbeeca81..e2a59e5df3b44eee261e530261a1134bd3ea738f 100644 (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
index 0f88944c106c24ba1571decc2fa4702ed9b3657a..d950411f6fe63cfac676e83d9e748f11f4c925fd 100644 (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;