]> git.sesse.net Git - stockfish/commitdiff
Retire UCI_Chess960 option
authorMarco Costalba <mcostalba@gmail.com>
Sun, 22 Aug 2010 13:55:52 +0000 (14:55 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Sun, 22 Aug 2010 15:51:20 +0000 (16:51 +0100)
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 <mcostalba@gmail.com>
src/misc.cpp
src/misc.h
src/move.cpp
src/move.h
src/position.cpp
src/position.h
src/search.cpp
src/ucioption.cpp

index e03a0e2fa7302fbe4c1b4fa418a4b3be2fc8adbb..49b41b2f73eec3b35113d79f7cc033e05855f33e 100644 (file)
@@ -67,8 +67,6 @@ static const string AppTag  = "";
 //// Variables
 ////
 
-bool Chess960;
-
 uint64_t dbg_cnt0 = 0;
 uint64_t dbg_cnt1 = 0;
 
index c6b6ecfda51fa87465cbf48408d8063fa0f3267e..6fa86d734039297b4c3a4bddad787a2c9f69db9a 100644 (file)
 #define Max(x, y) (((x) < (y))? (y) : (x))
 
 
-////
-//// Variables
-////
-
-extern bool Chess960;
-
-
 ////
 //// Prototypes
 ////
index 7b06b0ecaf0e33a120a709dbe8ea4975e44d7bdd..31622c2d8bc06de2e081092c261a1bc3525d91b0 100644 (file)
@@ -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::ostreamoperator << (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);
 }
 
 
index bbc2ec099c1134163521a86e26fc1c3ea3d8c5cf..9df3277db775919672a88923e991ee82ffbf707c 100644 (file)
@@ -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);
 
 
index 10f0d8742d228a3d205a14ec087f6f28f66c5e3f..cbc64609641061c77b9f1e6dc34bdcdad1b2e77d 100644 (file)
@@ -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 += '-';
 
index 2c294f5479c612e5957c4969bf4869551fe45fd2..4e79a8fa33b878bfba50f02230f6b03aab79e087 100644 (file)
@@ -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 !
index 97b7a29ce4dce27735bc8ceb5c5c645bad79757c..8bd9f9bd4f2f3a25832cdfabcb00195f931f0245 100644 (file)
@@ -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()
index 33db4d15f476af9a5ff438aefdbeb44f2a155bd7..084e3d0b6a62d329336daf253bbd9ca6fc040f32 100644 (file)
@@ -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