diff options
Diffstat (limited to 'src/uci.cpp')
| -rw-r--r-- | src/uci.cpp | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/src/uci.cpp b/src/uci.cpp index b78ffea..b98e6ce 100644 --- a/src/uci.cpp +++ b/src/uci.cpp @@ -32,7 +32,24 @@ uint16_t UciToMove(const std::string &uci) { std::cout << "expected valid uci string\n"; exit(1); } - // TODO: validate before using + bool isValid = true; + if (uci[0] < 'a' || uci[0] > 'h') { + isValid = false; + } + if (uci[1] < '1' || uci[1] > '8') { + isValid = false; + } + if (uci[2] < 'a' || uci[2] > 'h') { + isValid = false; + } + if (uci[3] < '1' || uci[3] > '8') { + isValid = false; + } + if (!isValid) { + std::cout << "Move is not valid: " << uci << "\n"; + exit(1); + return 0; + } from.file = static_cast<uint8_t>(uci[0] - 'a'); from.rank = static_cast<uint8_t>(uci[1] - '1'); @@ -53,8 +70,7 @@ uint16_t UciToMove(const std::string &uci) { promotion = BISHOP; break; default: - assert(false && "Unexpected promotion type"); - std::cout << "Unexpected promotion type"; + std::cout << "Move is not valid: " << uci << "\n"; exit(1); } } |
