aboutsummaryrefslogtreecommitdiff
path: root/src/uci.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/uci.cpp')
-rw-r--r--src/uci.cpp24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/uci.cpp b/src/uci.cpp
index 0266aa6..92c7072 100644
--- a/src/uci.cpp
+++ b/src/uci.cpp
@@ -22,7 +22,7 @@
static const std::string starting_fen =
"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
-Move UciToMove(const std::string &uci) {
+uint16_t UciToMove(const std::string &uci) {
Position from;
Position to;
PieceType promotion = NONEPIECE;
@@ -32,6 +32,7 @@ Move UciToMove(const std::string &uci) {
std::cout << "expected valid uci string\n";
exit(1);
}
+ // TODO: validate before using
from.file = static_cast<uint8_t>(uci[0] - 'a');
from.rank = static_cast<uint8_t>(uci[1] - '1');
@@ -58,7 +59,8 @@ Move UciToMove(const std::string &uci) {
}
}
- return {.From = from, .To = to, .promotion = promotion};
+ return CreateMove(static_cast<uint8_t>(PositionToIndex(from)),
+ static_cast<uint8_t>(PositionToIndex(to)), promotion);
}
Game initBoard(
@@ -207,13 +209,21 @@ static void GoCommand(Game *game, std::string &cmd) {
.wncr = wncr,
.bncr = bncr,
};
- Move best = GetBestMove(game, depth, options);
+ uint16_t best = GetBestMove(game, depth, options);
+
+ Piece piece = game->pieces[getFromValueFromMove(best)];
+
+ Position from = IndexToPosition(getFromValueFromMove(best));
+ Position to = IndexToPosition(getToValueFromMove(best));
+ PieceType promotion = getPromotionTypeFromMove(best);
std::cout << "bestmove ";
- std::cout << static_cast<char>(best.From.file + 'a') << 1 + best.From.rank
- << static_cast<char>(best.To.file + 'a') << 1 + best.To.rank;
+ std::cout << static_cast<char>(from.file + 'a') << 1 + from.rank
+ << static_cast<char>(to.file + 'a') << 1 + to.rank;
- printPromotionLetter(best.promotion);
+ if ((to.rank == 0 || to.rank == 7) && piece.type == PAWN) {
+ printPromotionLetter(promotion);
+ }
std::cout << "\n";
std::cout.flush();
@@ -252,7 +262,7 @@ static void positionCommnad(Game *game, std::string &cmd) {
}
while (ss >> token) {
- Move move = UciToMove(token);
+ uint16_t move = UciToMove(token);
MakeMove(move, game);
}