From: Fabian Fichter Date: Thu, 14 Jan 2021 21:51:01 +0000 (+0100) Subject: Support UCI-cyclone protocol X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=6f7a56d71948a507836ade8d549e444393e9adf0;p=fairystockfish.git Support UCI-cyclone protocol Closes #194. --- diff --git a/.travis.yml b/.travis.yml index 5130655..bc0d828 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/src/uci.cpp b/src/uci.cpp index 2b0c6a4..0ac6123 100644 --- a/src/uci.cpp +++ b/src/uci.cpp @@ -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)) } diff --git a/src/ucioption.cpp b/src/ucioption.cpp index 4a7820a..cf923b0 100644 --- a/src/ucioption.cpp +++ b/src/ucioption.cpp @@ -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"}); diff --git a/tests/protocol.sh b/tests/protocol.sh index 8b54a1c..5382afa 100755 --- a/tests/protocol.sh +++ b/tests/protocol.sh @@ -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