]> git.sesse.net Git - stockfish/commitdiff
Another attempt at fixing Chess960
authorMarco Costalba <mcostalba@gmail.com>
Mon, 3 Jan 2011 11:50:49 +0000 (12:50 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Mon, 3 Jan 2011 21:50:38 +0000 (22:50 +0100)
Keep the isChess960 flag inside Position so that is
copied with the Position, but esplicitly highlight the
fact that a FEN string has not enough information to detect
Chess960 in general case. To do this add a boolean argument
isChess960 to from_fen() function so to self document this
shortcoming of FEN notation.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
src/benchmark.cpp
src/evaluate.cpp
src/material.cpp
src/position.cpp
src/position.h
src/uci.cpp

index d0afee898695b50616b951987136d987e8af401d..cbb62d29d111d9dae122cded936ba98a604f46e8 100644 (file)
@@ -125,7 +125,7 @@ void benchmark(int argc, char* argv[]) {
   {
       Move moves[1] = { MOVE_NONE };
       int dummy[2] = { 0, 0 };
   {
       Move moves[1] = { MOVE_NONE };
       int dummy[2] = { 0, 0 };
-      Position pos(*it, 0);
+      Position pos(*it, false, 0);
       cerr << "\nBench position: " << cnt << '/' << positions.size() << endl << endl;
       if (valType == "perft")
       {
       cerr << "\nBench position: " << cnt << '/' << positions.size() << endl << endl;
       if (valType == "perft")
       {
index 58feae39c470b57406c1305c4c43d3ddc9e593b1..fe964935c828282490b53a3927cc18c471f263d1 100644 (file)
@@ -562,7 +562,7 @@ namespace {
         }
 
         // Special extra evaluation for bishops
         }
 
         // Special extra evaluation for bishops
-        if (Piece == BISHOP)
+        if (Piece == BISHOP && pos.is_chess960())
         {
             // An important Chess960 pattern: A cornered bishop blocked by
             // a friendly pawn diagonally in front of it is a very serious
         {
             // An important Chess960 pattern: A cornered bishop blocked by
             // a friendly pawn diagonally in front of it is a very serious
index bd9d5e8a3e8d653b8d288ccc0f2dd2746e4cb41d..0098b39c949cc30fa6ddc1ef21196e209d7983c2 100644 (file)
@@ -407,7 +407,7 @@ Key EndgameFunctions::buildKey(const string& keyCode) {
     }
     fen += char(8 - keyCode.length() + '0');
     fen += "/8/8/8/8/8/8/8 w - -";
     }
     fen += char(8 - keyCode.length() + '0');
     fen += "/8/8/8/8/8/8/8 w - -";
-    return Position(fen, 0).get_material_key();
+    return Position(fen, false, 0).get_material_key();
 }
 
 const string EndgameFunctions::swapColors(const string& keyCode) {
 }
 
 const string EndgameFunctions::swapColors(const string& keyCode) {
index f0301e4ec9308af1a78394c5728b0246b1af30a3..bc6efb7f646d05bb242b94b3f3d5eea48b426eb6 100644 (file)
@@ -152,9 +152,9 @@ Position::Position(const Position& pos, int th) {
   nodes = 0;
 }
 
   nodes = 0;
 }
 
-Position::Position(const string& fen, int th) {
+Position::Position(const string& fen, bool isChess960, int th) {
 
 
-  from_fen(fen);
+  from_fen(fen, isChess960);
   threadID = th;
 }
 
   threadID = th;
 }
 
@@ -175,7 +175,7 @@ void Position::detach() {
 /// string. This function is not very robust - make sure that input FENs are
 /// correct (this is assumed to be the responsibility of the GUI).
 
 /// string. This function is not very robust - make sure that input FENs are
 /// correct (this is assumed to be the responsibility of the GUI).
 
-void Position::from_fen(const string& fen) {
+void Position::from_fen(const string& fen, bool c960) {
 /*
    A FEN string defines a particular position using only the ASCII character set.
 
 /*
    A FEN string defines a particular position using only the ASCII character set.
 
@@ -274,10 +274,7 @@ void Position::from_fen(const string& fen) {
   castleRightsMask[make_square(initialQRFile, RANK_1)] ^= WHITE_OOO;
   castleRightsMask[make_square(initialQRFile, RANK_8)] ^= BLACK_OOO;
 
   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;
-
+  isChess960 = c960;
   find_checkers();
 
   st->key = compute_key();
   find_checkers();
 
   st->key = compute_key();
index 5b1bc664be7782f713f1b8641e8aafe9058dc8e4..600c1648205f2d7cf9e6c4e8a7d7032c004de921 100644 (file)
@@ -134,10 +134,10 @@ public:
 
   // Constructors
   Position(const Position& pos, int threadID);
 
   // Constructors
   Position(const Position& pos, int threadID);
-  Position(const std::string& fen, int threadID);
+  Position(const std::string& fen, bool isChess960, int threadID);
 
   // Text input/output
 
   // Text input/output
-  void from_fen(const std::string& fen);
+  void from_fen(const std::string& fen, bool isChess960);
   const std::string to_fen() const;
   void print(Move m = MOVE_NONE) const;
 
   const std::string to_fen() const;
   void print(Move m = MOVE_NONE) const;
 
index 5e85098504d30c3a4ecbc8d7cce412f265e28ac5..1b10c7b418697c969f00d8f8b9a4e0ed938db3db 100644 (file)
@@ -63,7 +63,7 @@ namespace {
 
 bool execute_uci_command(const string& cmd) {
 
 
 bool execute_uci_command(const string& cmd) {
 
-  static Position pos(StartPositionFEN, 0); // The root position
+  static Position pos(StartPositionFEN, false, 0); // The root position
   UCIParser up(cmd);
   string token;
 
   UCIParser up(cmd);
   string token;
 
@@ -84,7 +84,7 @@ bool execute_uci_command(const string& cmd) {
       cout << "uciok" << endl;
   }
   else if (token == "ucinewgame")
       cout << "uciok" << endl;
   }
   else if (token == "ucinewgame")
-      pos.from_fen(StartPositionFEN);
+      pos.from_fen(StartPositionFEN, false);
 
   else if (token == "isready")
       cout << "readyok" << endl;
 
   else if (token == "isready")
       cout << "readyok" << endl;
@@ -147,7 +147,7 @@ namespace {
 
     if (token == "startpos")
     {
 
     if (token == "startpos")
     {
-        pos.from_fen(StartPositionFEN);
+        pos.from_fen(StartPositionFEN, false);
         if (!(up >> token))
             return;
     }
         if (!(up >> token))
             return;
     }
@@ -159,7 +159,7 @@ namespace {
             fen += token;
             fen += ' ';
         }
             fen += token;
             fen += ' ';
         }
-        pos.from_fen(fen);
+        pos.from_fen(fen, Options["UCI_Chess960"].value<bool>());
     }
 
     if (token != "moves")
     }
 
     if (token != "moves")