diff --git a/CMakeLists.txt b/CMakeLists.txt index 1594c9a..3cc12d4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.29) project(cmpsc330hw2) -set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD 11) add_executable(cmpsc330hw2 main.cpp) diff --git a/main.cpp b/main.cpp index 9798ac0..93e1776 100644 --- a/main.cpp +++ b/main.cpp @@ -98,12 +98,29 @@ bool isValidPlayer(char c) { return c >= 'A' && c <= 'Z' && c != 'X'; } -Moves serialize(const string &s) { - // TODO: add check for impossible board sizes +string toString(int x) { + string result; + while (x) { + result.push_back(x % 10 + '0'); + x /= 10; + } + reverse(result.begin(), result.end()); + return result; +} +Moves serialize(const string &s) { Moves result; istringstream iss(s); iss >> result.x >> result.y; + if (result.x < 2 || result.y < 2) { + string err = "Invalid board size: "; + err.append(toString(result.x)); + err.append("x"); + err.append(toString(result.y)); + + throw invalid_argument(err); + } + result.x <<= 1; result.y <<= 1;