add invalid move check in serialize

This commit is contained in:
Sandipsinh Rathod 2024-10-10 19:26:14 -04:00
parent 921d620830
commit b5dd36b8af

@ -121,13 +121,18 @@ Moves serialize(const string &s) {
throw invalid_argument(err);
}
result.x <<= 1;
result.y <<= 1;
result.x = (result.x << 1) - 1;
result.y = (result.y << 1) - 1;
string player;
int x, y;
while (iss >> player >> x >> y) {
if (player == "END") break;
if (x >= result.x || y >= result.y) {
string err = "Invalid move by: " + player + " (" + toString(x) + ", " + toString(y) + ")";
throw invalid_argument(err);
}
if (!isValidPlayer(player[0])) {
string err = "Invalid player: " + player;
throw invalid_argument(err);