add check for impossible board sizes
This commit is contained in:
parent
cf468cfe08
commit
37f096170c
@ -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)
|
||||
|
21
main.cpp
21
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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user