Remove redundant argument in think()
authorMarco Costalba <mcostalba@gmail.com>
Thu, 15 Jul 2010 15:05:56 +0000 (17:05 +0200)
committerMarco Costalba <mcostalba@gmail.com>
Thu, 15 Jul 2010 16:14:30 +0000 (17:14 +0100)
We don't need to pass side_to_move because we can get
it directly from the position object.

Note that in benchmark we always used to pass '0' and
it was a bug, but with no effect because was used only
in time[] and increment[], set always to 0 for both
colors.

Also additional small cleanup while there.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>

src/benchmark.cpp
src/evaluate.cpp
src/move.h
src/position.h
src/search.cpp
src/search.h
src/uci.cpp

index ee262ba..e23afb1 100644 (file)
@@ -159,7 +159,7 @@ void benchmark(const string& commandLine) {
           cerr << "\nPerft " << maxDepth << " result (nodes searched): " << perftCnt << endl << endl;
           totalNodes += perftCnt;
       } else {
-          if (!think(pos, false, false, 0, dummy, dummy, 0, maxDepth, maxNodes, secsPerPos, moves))
+          if (!think(pos, false, false, dummy, dummy, 0, maxDepth, maxNodes, secsPerPos, moves))
               break;
           totalNodes += nodes_searched();
       }
index 73ffcfb..0249ee3 100644 (file)
@@ -1064,9 +1064,8 @@ namespace {
   }
 
 
-  // scale_by_game_phase() interpolates between a middle game and an endgame
-  // score, based on game phase.  It also scales the return value by a
-  // ScaleFactor array.
+  // scale_by_game_phase() interpolates between a middle game and an endgame score,
+  // based on game phase. It also scales the return value by a ScaleFactor array.
 
   Value scale_by_game_phase(const Score& v, Phase ph, const ScaleFactor sf[]) {
 
@@ -1076,7 +1075,7 @@ namespace {
 
     Value eg = eg_value(v);
     ScaleFactor f = sf[eg > Value(0) ? WHITE : BLACK];
-    Value ev = Value((eg * f) / int(SCALE_FACTOR_NORMAL));
+    Value ev = Value((eg * f) / SCALE_FACTOR_NORMAL);
 
     int result = (mg_value(v) * ph + ev * (128 - ph)) / 128;
     return Value(result & ~(GrainSize - 1));
index 7653287..bbc2ec0 100644 (file)
@@ -201,8 +201,8 @@ inline Move make_ep_move(Square from, Square to) {
 //// Prototypes
 ////
 
-extern std::ostream& operator<<(std::ostream &os, Move m);
-extern Move move_from_string(const Position &pos, const std::string &str);
+extern std::ostream& operator<<(std::ostream& os, Move m);
+extern Move move_from_string(const Position& pos, const std::string &str);
 extern const std::string move_to_string(Move m);
 extern bool move_is_ok(Move m);
 
index be43c2e..826fa13 100644 (file)
@@ -51,7 +51,7 @@
 ////
 
 /// FEN string for the initial position
-const std::string StartPosition = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
+const std::string StartPositionFEN = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
 
 /// Maximum number of plies per game (220 should be enough, because the
 /// maximum search depth is 100, and during position setup we reset the
index fa544a1..d164282 100644 (file)
@@ -411,9 +411,8 @@ int perft(Position& pos, Depth depth)
 /// search-related global variables, and calls root_search(). It returns false
 /// when a quit command is received during the search.
 
-bool think(const Position& pos, bool infinite, bool ponder, int side_to_move,
-           int time[], int increment[], int movesToGo, int maxDepth,
-           int maxNodes, int maxTime, Move searchMoves[]) {
+bool think(const Position& pos, bool infinite, bool ponder, int time[], int increment[],
+           int movesToGo, int maxDepth, int maxNodes, int maxTime, Move searchMoves[]) {
 
   // Initialize global search variables
   StopOnPonderhit = AbortSearch = Quit = AspirationFailLow = false;
@@ -486,8 +485,8 @@ bool think(const Position& pos, bool infinite, bool ponder, int side_to_move,
   TM.wake_sleeping_threads();
 
   // Set thinking time
-  int myTime = time[side_to_move];
-  int myIncrement = increment[side_to_move];
+  int myTime = time[pos.side_to_move()];
+  int myIncrement = increment[pos.side_to_move()];
   if (UseTimeManagement)
   {
       if (!movesToGo) // Sudden death time control
index d2dc6eb..61a3324 100644 (file)
@@ -72,11 +72,9 @@ struct SearchStack {
 extern void init_search();
 extern void init_threads();
 extern void exit_threads();
-extern bool think(const Position &pos, bool infinite, bool ponder, int side_to_move,
-                  int time[], int increment[], int movesToGo, int maxDepth,
-                  int maxNodes, int maxTime, Move searchMoves[]);
-extern int perft(Position &pos, Depth depth);
+extern int perft(Position& pos, Depth depth);
 extern int64_t nodes_searched();
-
+extern bool think(const Position& pos, bool infinite, bool ponder, int time[], int increment[],
+                  int movesToGo, int maxDepth, int maxNodes, int maxTime, Move searchMoves[]);
 
 #endif // !defined(SEARCH_H_INCLUDED)
index db9e622..60d10b0 100644 (file)
@@ -79,7 +79,7 @@ namespace {
 
 void uci_main_loop() {
 
-  RootPosition.from_fen(StartPosition);
+  RootPosition.from_fen(StartPositionFEN);
   string command;
 
   do {
@@ -127,7 +127,7 @@ namespace {
     {
         push_button("New Game");
         Position::init_piece_square_tables();
-        RootPosition.from_fen(StartPosition);
+        RootPosition.from_fen(StartPositionFEN);
     }
     else if (token == "isready")
         cout << "readyok" << endl;
@@ -149,9 +149,9 @@ namespace {
     else if (token == "eval")
     {
         EvalInfo ei;
-        cout << "Incremental mg: " << mg_value(RootPosition.value())
+        cout << "Incremental mg: "   << mg_value(RootPosition.value())
              << "\nIncremental eg: " << eg_value(RootPosition.value())
-             << "\nFull eval: " << evaluate(RootPosition, ei) << endl;
+             << "\nFull eval: "      << evaluate(RootPosition, ei) << endl;
     }
     else if (token == "key")
         cout << "key: " << hex << RootPosition.get_key()
@@ -180,7 +180,7 @@ namespace {
         return;
 
     if (token == "startpos")
-        RootPosition.from_fen(StartPosition);
+        RootPosition.from_fen(StartPositionFEN);
     else if (token == "fen")
     {
         string fen;
@@ -209,7 +209,7 @@ namespace {
                     RootPosition.reset_game_ply();
             }
             // Our StateInfo st is about going out of scope so copy
-            // its content inside RootPosition before they disappear.
+            // its content inside RootPosition before it disappears.
             RootPosition.detach();
         }
     }
@@ -300,8 +300,8 @@ namespace {
 
     assert(RootPosition.is_ok());
 
-    return think(RootPosition, infinite, ponder, RootPosition.side_to_move(),
-                 time, inc, movesToGo, depth, nodes, moveTime, searchMoves);
+    return think(RootPosition, infinite, ponder, time, inc, movesToGo,
+                 depth, nodes, moveTime, searchMoves);
   }
 
   void perft(UCIInputParser& uip) {