完成 UCI::move(Move m) 函数并全面应用

This commit is contained in:
Calcitem 2020-09-07 00:05:14 +08:00
parent dd10fcb8d3
commit e1ecfcc2df
3 changed files with 14 additions and 28 deletions

View File

@ -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)
{

View File

@ -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();

View File

@ -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;
}