From b5dd36b8afca5eea694003e9b7f8ab4433de1aa6 Mon Sep 17 00:00:00 2001 From: Sandipsinh Rathod Date: Thu, 10 Oct 2024 19:26:14 -0400 Subject: [PATCH] add invalid move check in serialize --- main.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/main.cpp b/main.cpp index 28d5b3a..712b5f0 100644 --- a/main.cpp +++ b/main.cpp @@ -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);