-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame-check.cpp
More file actions
42 lines (40 loc) · 1.09 KB
/
Copy pathgame-check.cpp
File metadata and controls
42 lines (40 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "Board.h"
#include "Errors.h"
#include "Move.h"
#include <iostream>
int main() {
Board game;
int move_num = 1;
bool ongoing = true;
std::string str;
while(std::getline(std::cin, str)) {
try {
Move move(str);
try {
if (!ongoing) {
throw InvalidMove("game has ended");
}
if (move.number != move_num) {
throw InvalidMove("invalid move number");
}
game.enter_move(move.player, move.row, move.column);
ongoing = game.checkgame();
}
catch(const InvalidMove& error) {
std::cout << "Invalid move.\n";
return 2;
}
}
catch(const ParseError& e) {
std::cout << "Parse error.\n";
return 1;
}
move_num++;
}
if (game.get_current_state().empty()) {
std::cout << "Game in progress: New game.\n";
return 0;
}
std::cout << game.get_current_state();
return 0;
}