From e17fa64aec39c43708ed80eccb715e36da1cdd64 Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Sun, 22 Aug 2010 14:55:52 +0100 Subject: [PATCH] Retire UCI_Chess960 option We don't need that ! We can infere from starting fen string if we are in a Chess960 game or not. And note that this is a per-position property, not an application wide one. A nice trick is to use a custom manipulator (that is an enum actually) to keep using the handy operator<<() on the move when sending to std::cout, yes, I have indulged a bit here ;-) Signed-off-by: Marco Costalba --- src/misc.cpp | 2 -- src/misc.h | 7 ------- src/move.cpp | 21 ++++++++++----------- src/move.h | 2 +- src/position.cpp | 16 ++++++++-------- src/position.h | 7 +++++++ src/search.cpp | 19 +++++++++++++++++-- src/ucioption.cpp | 1 - 8 files changed, 43 insertions(+), 32 deletions(-) diff --git a/src/misc.cpp b/src/misc.cpp index e03a0e2f..49b41b2f 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -67,8 +67,6 @@ static const string AppTag = ""; //// Variables //// -bool Chess960; - uint64_t dbg_cnt0 = 0; uint64_t dbg_cnt1 = 0; diff --git a/src/misc.h b/src/misc.h index c6b6ecfd..6fa86d73 100644 --- a/src/misc.h +++ b/src/misc.h @@ -40,13 +40,6 @@ #define Max(x, y) (((x) < (y))? (y) : (x)) -//// -//// Variables -//// - -extern bool Chess960; - - //// //// Prototypes //// diff --git a/src/move.cpp b/src/move.cpp index 7b06b0ec..31622c2d 100644 --- a/src/move.cpp +++ b/src/move.cpp @@ -104,11 +104,11 @@ Move move_from_string(const Position& pos, const std::string& str) { /// move_to_string() converts a move to a string in coordinate notation -/// (g1f3, a7a8q, etc.). The only special case is castling moves, where we +/// (g1f3, a7a8q, etc.). The only special case is castling moves, where we /// print in the e1g1 notation in normal chess mode, and in e1h1 notation in /// Chess960 mode. -const std::string move_to_string(Move move) { +const std::string move_to_string(Move move, bool chess960) { std::string str; Square from = move_from(move); @@ -120,14 +120,12 @@ const std::string move_to_string(Move move) { str = "0000"; else { - if (!Chess960) - { - if (move_is_short_castle(move)) - return (from == SQ_E1 ? "e1g1" : "e8g8"); + if (move_is_short_castle(move) && !chess960) + return (from == SQ_E1 ? "e1g1" : "e8g8"); + + if (move_is_long_castle(move) && !chess960) + return (from == SQ_E1 ? "e1c1" : "e8c8"); - if (move_is_long_castle(move)) - return (from == SQ_E1 ? "e1c1" : "e8c8"); - } str = square_to_string(from) + square_to_string(to); if (move_is_promotion(move)) str += piece_type_to_char(move_promotion_piece(move), false); @@ -138,9 +136,10 @@ const std::string move_to_string(Move move) { /// Overload the << operator, to make it easier to print moves. -std::ostream &operator << (std::ostream& os, Move m) { +std::ostream& operator << (std::ostream& os, Move m) { - return os << move_to_string(m); + bool chess960 = (os.iword(0) != 0); // See set960() + return os << move_to_string(m, chess960); } diff --git a/src/move.h b/src/move.h index bbc2ec09..9df3277d 100644 --- a/src/move.h +++ b/src/move.h @@ -203,7 +203,7 @@ inline Move make_ep_move(Square from, Square to) { 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 const std::string move_to_string(Move m, bool chess960); extern bool move_is_ok(Move m); diff --git a/src/position.cpp b/src/position.cpp index 10f0d874..cbc64609 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -246,6 +246,10 @@ void Position::from_fen(const string& fen) { castleRightsMask[make_square(initialQRFile, RANK_1)] ^= WHITE_OOO; castleRightsMask[make_square(initialQRFile, RANK_8)] ^= BLACK_OOO; + isChess960 = initialKFile != FILE_E + || initialQRFile != FILE_A + || initialKRFile != FILE_H; + find_checkers(); st->key = compute_key(); @@ -352,21 +356,17 @@ const string Position::to_fen() const { if (st->castleRights != CASTLES_NONE) { - const bool Chess960 = initialKFile != FILE_E - || initialQRFile != FILE_A - || initialKRFile != FILE_H; - if (can_castle_kingside(WHITE)) - fen += Chess960 ? char(toupper(file_to_char(initialKRFile))) : 'K'; + fen += isChess960 ? char(toupper(file_to_char(initialKRFile))) : 'K'; if (can_castle_queenside(WHITE)) - fen += Chess960 ? char(toupper(file_to_char(initialQRFile))) : 'Q'; + fen += isChess960 ? char(toupper(file_to_char(initialQRFile))) : 'Q'; if (can_castle_kingside(BLACK)) - fen += Chess960 ? file_to_char(initialKRFile) : 'k'; + fen += isChess960 ? file_to_char(initialKRFile) : 'k'; if (can_castle_queenside(BLACK)) - fen += Chess960 ? file_to_char(initialQRFile) : 'q'; + fen += isChess960 ? file_to_char(initialQRFile) : 'q'; } else fen += '-'; diff --git a/src/position.h b/src/position.h index 2c294f54..4e79a8fa 100644 --- a/src/position.h +++ b/src/position.h @@ -272,6 +272,7 @@ public: // Other properties of the position bool opposite_colored_bishops() const; bool has_pawn_on_7th(Color c) const; + bool is_chess960() const; // Current thread ID searching on the position int thread() const; @@ -335,6 +336,7 @@ private: int castleRightsMask[64]; StateInfo startState; File initialKFile, initialKRFile, initialQRFile; + bool isChess960; int startPosPlyCounter; int threadID; StateInfo* st; @@ -555,6 +557,11 @@ inline bool Position::has_pawn_on_7th(Color c) const { return pieces(PAWN, c) & relative_rank_bb(c, RANK_7); } +inline bool Position::is_chess960() const { + + return isChess960; +} + inline bool Position::move_is_capture(Move m) const { // Move must not be MOVE_NONE ! diff --git a/src/search.cpp b/src/search.cpp index 97b7a29c..8bd9f9bd 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -161,6 +161,21 @@ namespace { }; + // When formatting a move for std::cout we must know if we are in Chess960 + // or not. To keep using the handy operator<<() on the move the trick is to + // embed this flag in the stream itself. Function-like named enum set960 is + // used as a custom manipulator and the stream internal general-purpose array, + // accessed through ios_base::iword(), is used to pass the flag to the move's + // operator<<() that will use it to properly format castling moves. + enum set960 {}; + + std::ostream& operator<< (std::ostream& os, const set960& m) { + + os.iword(0) = int(m); + return os; + } + + /// Adjustments // Step 6. Razoring @@ -448,7 +463,6 @@ bool think(const Position& pos, bool infinite, bool ponder, int time[], int incr MinimumSplitDepth = get_option_value_int("Minimum Split Depth") * ONE_PLY; MaxThreadsPerSplitPoint = get_option_value_int("Maximum Number of Threads per Split Point"); MultiPV = get_option_value_int("MultiPV"); - Chess960 = get_option_value_bool("UCI_Chess960"); UseLogFile = get_option_value_bool("Use Search Log"); if (UseLogFile) @@ -534,7 +548,8 @@ namespace { // Print RootMoveList startup scoring to the standard output, // so to output information also for iteration 1. - cout << "info depth " << 1 + cout << set960(p.is_chess960()) // Is enough to set once at the beginning + << "info depth " << 1 << "\ninfo depth " << 1 << " score " << value_to_uci(rml.get_move_score(0)) << " time " << current_search_time() diff --git a/src/ucioption.cpp b/src/ucioption.cpp index 33db4d15..084e3d0b 100644 --- a/src/ucioption.cpp +++ b/src/ucioption.cpp @@ -131,7 +131,6 @@ namespace { o["Emergency Base Time"] = Option(200, 0, 60000); o["Emergency Move Time"] = Option(70, 0, 5000); o["Minimum Thinking Time"] = Option(20, 0, 5000); - o["UCI_Chess960"] = Option(false); o["UCI_AnalyseMode"] = Option(false); // Any option should know its name so to be easily printed -- 2.39.2