Support UCI-cyclone protocol
authorFabian Fichter <ianfab@users.noreply.github.com>
Thu, 14 Jan 2021 21:51:01 +0000 (22:51 +0100)
committerFabian Fichter <ianfab@users.noreply.github.com>
Thu, 14 Jan 2021 21:51:01 +0000 (22:51 +0100)
Closes #194.

.travis.yml
src/uci.cpp
src/ucioption.cpp
tests/protocol.sh

index 5130655..bc0d828 100644 (file)
@@ -49,7 +49,9 @@ script:
   - make clean && make -j2 ARCH=x86-64 nnue=yes debug=yes build && ./stockfish bench > /dev/null 2>&1
 
   # Check perft of large-board version
-  - make clean && make -j2 ARCH=x86-64 largeboards=yes all=yes debug=yes build && ../tests/perft.sh largeboard
+  - make clean && make -j2 ARCH=x86-64 largeboards=yes all=yes debug=yes build
+  - ../tests/perft.sh largeboard
+  - ../tests/protocol.sh
   - ./stockfish bench xiangqi > /dev/null 2>&1
   - ./stockfish bench shogi > /dev/null 2>&1
   - ./stockfish bench capablanca > /dev/null 2>&1
@@ -96,7 +98,6 @@ script:
   - make clean && make -j2 ARCH=x86-64-modern build
   - ../tests/perft.sh
   - ../tests/reprosearch.sh
-  - ../tests/protocol.sh
 
   #
   # Valgrind
index 2b0c6a4..0ac6123 100644 (file)
@@ -307,11 +307,17 @@ void UCI::loop(int argc, char* argv[]) {
       else if (token == "uci" || token == "usi" || token == "ucci" || token == "xboard")
       {
           Options["Protocol"].set_default(token);
-          string defaultVariant = string(  token == "usi"  ? "shogi"
+          string defaultVariant = string(
+#ifdef LARGEBOARDS
+                                           token == "usi"  ? "shogi"
                                          : token == "ucci" ? "xiangqi"
+#else
+                                           token == "usi"  ? "minishogi"
+                                         : token == "ucci" ? "minixiangqi"
+#endif
                                                            : "chess");
           Options["UCI_Variant"].set_default(defaultVariant);
-          if (token != "xboard")
+          if (token == "uci" || token == "usi" || token == "ucci")
               sync_cout << "id name " << engine_info(true)
                           << "\n" << Options
                           << "\n" << token << "ok"  << sync_endl;
@@ -339,6 +345,19 @@ void UCI::loop(int argc, char* argv[]) {
       else if (token == "compiler") sync_cout << compiler_info() << sync_endl;
       else if (token == "load")     { load(is); argc = 1; } // continue reading stdin
       else if (token == "check")    check(is);
+      // UCI-Cyclone omits the "position" keyword
+      else if (token == "fen" || token == "startpos")
+      {
+#ifdef LARGEBOARDS
+          if (Options["Protocol"] == "uci" && Options["UCI_Variant"] == "chess")
+          {
+              Options["Protocol"].set_default("ucicyclone");
+              Options["UCI_Variant"].set_default("xiangqi");
+          }
+#endif
+          is.seekg(0);
+          position(pos, is, states);
+      }
       else
           sync_cout << "Unknown command: " << cmd << sync_endl;
 
@@ -404,7 +423,7 @@ std::string UCI::square(const Position& pos, Square s) {
                                   : std::string{ char('0' + (pos.max_file() - file_of(s) + 1) / 10),
                                                  char('0' + (pos.max_file() - file_of(s) + 1) % 10),
                                                  char('a' + pos.max_rank() - rank_of(s)) };
-  else if ((Options["Protocol"] == "xboard" || Options["Protocol"] == "ucci") && pos.max_rank() == RANK_10)
+  else if (pos.max_rank() == RANK_10 && Options["Protocol"] != "uci")
       return std::string{ char('a' + file_of(s)), char('0' + rank_of(s)) };
   else
       return rank_of(s) < RANK_10 ? std::string{ char('a' + file_of(s)), char('1' + (rank_of(s) % 10)) }
index 4a7820a..cf923b0 100644 (file)
@@ -156,7 +156,7 @@ void init(OptionsMap& o) {
 
   constexpr int MaxHashMB = Is64Bit ? 33554432 : 2048;
 
-  o["Protocol"]              << Option("uci", {"uci", "usi", "ucci", "xboard"});
+  o["Protocol"]              << Option("uci", {"uci", "usi", "ucci", "ucicyclone", "xboard"});
   o["Debug Log File"]        << Option("", on_logger);
   o["Contempt"]              << Option(24, -100, 100);
   o["Analysis Contempt"]     << Option("Both", {"Both", "Off", "White", "Black"});
index 8b54a1c..5382afa 100755 (executable)
@@ -11,14 +11,16 @@ trap 'error ${LINENO}' ERR
 echo "protocol testing started"
 
 cat << EOF > uci.exp
-   set timeout 5
    spawn ./stockfish
    send "uci\\n"
    expect "default chess"
    expect "uciok"
-   send "usi\\n"
-   expect "default shogi"
-   expect "usiok"
+   send "quit\\n"
+   expect eof
+EOF
+
+cat << EOF > ucci.exp
+   spawn ./stockfish
    send "ucci\\n"
    expect "option UCI_Variant"
    expect "default xiangqi"
@@ -27,8 +29,27 @@ cat << EOF > uci.exp
    expect eof
 EOF
 
+cat << EOF > usi.exp
+   spawn ./stockfish
+   send "usi\\n"
+   expect "default shogi"
+   expect "usiok"
+   send "quit\\n"
+   expect eof
+EOF
+
+cat << EOF > ucicyclone.exp
+   spawn ./stockfish
+   send "uci\\n"
+   expect "uciok"
+   send "startpos\\n"
+   send "d\\n"
+   expect "rnbakabnr/9/1c5c1/p1p1p1p1p/9/9/P1P1P1P1P/1C5C1/9/RNBAKABNR w - - 0 1"
+   send "quit\\n"
+   expect eof
+EOF
+
 cat << EOF > xboard.exp
-   set timeout 5
    spawn ./stockfish
    send "xboard\\n"
    send "protover 2\\n"
@@ -41,9 +62,10 @@ cat << EOF > xboard.exp
    expect eof
 EOF
 
-for exp in uci.exp xboard.exp
+for exp in uci.exp ucci.exp usi.exp ucicyclone.exp xboard.exp
 do
-  expect $exp > /dev/null
+  echo "Testing $exp"
+  timeout 5 expect $exp > /dev/null
   rm $exp
 done