From 4eb36e67eca586a662298bfe8cc5392fbfa698e0 Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 15 Aug 2026 17:01:54 +0200 Subject: implementing memory optimazied move using uint16_t instead of a four integers and one byte --- src/uci.cpp | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'src/uci.cpp') 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(uci[0] - 'a'); from.rank = static_cast(uci[1] - '1'); @@ -58,7 +59,8 @@ Move UciToMove(const std::string &uci) { } } - return {.From = from, .To = to, .promotion = promotion}; + return CreateMove(static_cast(PositionToIndex(from)), + static_cast(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(best.From.file + 'a') << 1 + best.From.rank - << static_cast(best.To.file + 'a') << 1 + best.To.rank; + std::cout << static_cast(from.file + 'a') << 1 + from.rank + << static_cast(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); } -- cgit v1.2.3