add invalid move check in serialize
This commit is contained in:
parent
921d620830
commit
b5dd36b8af
9
main.cpp
9
main.cpp
@ -121,13 +121,18 @@ Moves serialize(const string &s) {
|
|||||||
throw invalid_argument(err);
|
throw invalid_argument(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
result.x <<= 1;
|
result.x = (result.x << 1) - 1;
|
||||||
result.y <<= 1;
|
result.y = (result.y << 1) - 1;
|
||||||
|
|
||||||
string player;
|
string player;
|
||||||
int x, y;
|
int x, y;
|
||||||
while (iss >> player >> x >> y) {
|
while (iss >> player >> x >> y) {
|
||||||
if (player == "END") break;
|
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])) {
|
if (!isValidPlayer(player[0])) {
|
||||||
string err = "Invalid player: " + player;
|
string err = "Invalid player: " + player;
|
||||||
throw invalid_argument(err);
|
throw invalid_argument(err);
|
||||||
|
Loading…
Reference in New Issue
Block a user