diff options
| author | Adam <adammegarules1@gmail.com> | 2026-07-26 12:46:35 +0200 |
|---|---|---|
| committer | Adam <adammegarules1@gmail.com> | 2026-07-26 12:46:35 +0200 |
| commit | 78ea1d6464483de6d9e0148da77a4c1c705a48ea (patch) | |
| tree | b225e6d6d33bb34f69bf1c1c7fa8a81bd87c145a | |
| parent | 7609c9d8e614d02c7ad532171c361f012857e3d8 (diff) | |
adding move repl
| -rw-r--r-- | src/main.cpp | 51 |
1 files changed, 50 insertions, 1 deletions
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 <cctype> +#include <cstdint> #include <cstdio> #include <cstdlib> #include <print> @@ -13,6 +15,20 @@ Piece NonePiece = { }; #include <iostream> +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<Move> &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; |
