diff options
Diffstat (limited to 'src/main.cpp')
| -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; |
