From b6ab610e2f3d9148e2a75984800cebc0757b7f01 Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Thu, 15 Jul 2010 17:05:56 +0200 Subject: [PATCH] Remove redundant argument in think() 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 --- src/benchmark.cpp | 2 +- src/evaluate.cpp | 7 +++---- src/move.h | 4 ++-- src/position.h | 2 +- src/search.cpp | 9 ++++----- src/search.h | 8 +++----- src/uci.cpp | 16 ++++++++-------- 7 files changed, 22 insertions(+), 26 deletions(-) diff --git a/src/benchmark.cpp b/src/benchmark.cpp index ee262ba5..e23afb14 100644 --- a/src/benchmark.cpp +++ b/src/benchmark.cpp @@ -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(); } diff --git a/src/evaluate.cpp b/src/evaluate.cpp index 73ffcfb0..0249ee3b 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -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)); diff --git a/src/move.h b/src/move.h index 76532871..bbc2ec09 100644 --- a/src/move.h +++ b/src/move.h @@ -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); diff --git a/src/position.h b/src/position.h index be43c2e4..826fa13b 100644 --- a/src/position.h +++ b/src/position.h @@ -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 diff --git a/src/search.cpp b/src/search.cpp index fa544a17..d1642827 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -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 diff --git a/src/search.h b/src/search.h index d2dc6eba..61a33242 100644 --- a/src/search.h +++ b/src/search.h @@ -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) diff --git a/src/uci.cpp b/src/uci.cpp index db9e6220..60d10b0b 100644 --- a/src/uci.cpp +++ b/src/uci.cpp @@ -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) { -- 2.39.2