From e1ecfcc2df07c3aab7090b288dc55d3668717636 Mon Sep 17 00:00:00 2001 From: Calcitem Date: Mon, 7 Sep 2020 00:05:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=20UCI::move(Move=20m)=20?= =?UTF-8?q?=E5=87=BD=E6=95=B0=E5=B9=B6=E5=85=A8=E9=9D=A2=E5=BA=94=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/search.cpp | 24 +++--------------------- src/search.h | 3 --- src/uci.cpp | 15 +++++++++++---- 3 files changed, 14 insertions(+), 28 deletions(-) diff --git a/src/search.cpp b/src/search.cpp index 17fd7123..ef29e005 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -524,7 +524,7 @@ int AIAlgorithm::search() #ifdef ALPHABETA_AI const char* AIAlgorithm::nextMove() { - return moveToCommand(bestMove); + return UCI::move(bestMove).c_str(); #if 0 char charSelect = '*'; @@ -545,7 +545,7 @@ const char* AIAlgorithm::nextMove() loggerDebug("[%.2d] %d\t%s\t%d\t%u %c\n", moveIndex, root->children[i]->move, - moveToCommand(root->children[i]->move), + UCI::move(root->children[i]->move).c_str(); root->children[i]->value, #ifdef HOSTORY_HEURISTIC root->children[i]->score, @@ -597,29 +597,11 @@ const char* AIAlgorithm::nextMove() loggerDebug("Warning: Best Move NOT Found\n"); } - return moveToCommand(bestMove); + return UCI::move(bestMove).c_str(); #endif } #endif // ALPHABETA_AI -const char *AIAlgorithm::moveToCommand(Move move) -{ - File file2 = file_of(to_sq(move)); - Rank rank2 = rank_of(to_sq(move)); - - if (move < 0) { - sprintf(cmdline, "-(%1u,%1u)", file2, rank2); - } else if (move & 0x7f00) { - File file1 = file_of(from_sq(move)); - Rank rank1 = rank_of(from_sq(move)); - sprintf(cmdline, "(%1u,%1u)->(%1u,%1u)", file1, rank1, file2, rank2); - } else { - sprintf(cmdline, "(%1u,%1u)", file2, rank2); - } - - return cmdline; -} - #ifdef ENDGAME_LEARNING bool AIAlgorithm::findEndgameHash(key_t posKey, Endgame &endgame) { diff --git a/src/search.h b/src/search.h index 5e70d29d..c0ead9fe 100644 --- a/src/search.h +++ b/src/search.h @@ -168,9 +168,6 @@ public: static void loadEndgameFileToHashMap(); #endif // ENDGAME_LEARNING -public: /* TODO: Move to private or protected */ - const char *moveToCommand(Move move); - protected: Depth changeDepth(); diff --git a/src/uci.cpp b/src/uci.cpp index 713984f6..664d5c5b 100644 --- a/src/uci.cpp +++ b/src/uci.cpp @@ -272,11 +272,11 @@ string UCI::value(Value v) } -/// UCI::square() converts a Square to a string in algebraic notation (c1, a7, etc.) +/// UCI::square() converts a Square to a string in algebraic notation ((1,2), etc.) std::string UCI::square(Square s) { - return std::string{ char('a' + file_of(s)), char('1' + rank_of(s)) }; + return std::string{ char('('), char('0' + file_of(s)), char(','), char('0' + rank_of(s)), char(')') }; } @@ -287,8 +287,8 @@ std::string UCI::square(Square s) string UCI::move(Move m) { + string move; - Square from = from_sq(m); Square to = to_sq(m); if (m == MOVE_NONE) @@ -297,7 +297,14 @@ string UCI::move(Move m) if (m == MOVE_NULL) return "0000"; - string move = UCI::square(from) + UCI::square(to); + if (m < 0) { + move = "-" + UCI::square(to); + } else if (m & 0x7f00) { + Square from = from_sq(m); + move = UCI::square(from) + "->" + UCI::square(to); + } else { + move = UCI::square(to); + } return move; }