From 78ea1d6464483de6d9e0148da77a4c1c705a48ea Mon Sep 17 00:00:00 2001 From: Adam Date: Sun, 26 Jul 2026 12:46:35 +0200 Subject: adding move repl --- src/main.cpp | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 57b7077..ccec7a1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,3 +1,5 @@ +#include +#include #include #include #include @@ -13,6 +15,20 @@ Piece NonePiece = { }; #include +bool isValidChessRank(char rank) { + if (rank >= '1' && rank <= '8') { + return true; + } else { + return false; + } +} +bool isValidChessFile(char rank) { + if (rank >= 'A' && rank <= 'H') { + return true; + } else { + return false; + } +} void PrintMoves(const std::vector &moves) { std::cout << "Moves (" << moves.size() << "):\n"; @@ -61,7 +77,40 @@ int main(int argc, char **argv) { std::cout << "Exiting...\n"; return 0; } - std::cout << command; + if (!isValidChessFile(command[0])) { + std::cout << "ERROR: Expected valid file at first place"; + std::println(); + continue; + } + + if (!isValidChessRank(command[1])) { + std::cout << "ERROR: Expected valid rank at second place"; + std::println(); + continue; + } + + if (!isValidChessFile(command[2])) { + std::cout << "ERROR: Expected valid file at third place"; + std::println(); + continue; + } + + if (!isValidChessRank(command[3])) { + std::cout << "ERROR: Expected valid rank at four place"; + std::println(); + continue; + } + + // we know its a valid chess pos + uint8_t fromFile = command[0] - 'A'; + uint8_t fromRank = command[1] - '0'; + uint8_t toFile = command[2] - 'A'; + uint8_t toRank = command[3] - '0'; + std::cout << fromFile << "\n"; + std::cout << fromRank << "\n"; + std::cout << toFile << "\n"; + std::cout << toRank << "\n"; + Move move = {fromRank, fromFile, toRank, toFile}; std::println(); } return EXIT_SUCCESS; -- cgit v1.2.3