-
Notifications
You must be signed in to change notification settings - Fork 0
/
gobl.m.cpp
95 lines (70 loc) · 2.07 KB
/
gobl.m.cpp
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// gobl.m.cpp
#include <goblb_board.h>
#include <goblb_space_state.h>
#include <gobls_parser.h>
#include <iostream>
#include <sstream>
namespace {
void handleInput(goblb::Board& board, bool& black, const std::string& input)
{
std::istringstream stream(input);
unsigned int i;
unsigned int j;
if(!(stream >> i >> j))
{
std::cout << "Failed to parse move in the form \"i j\"."
<< std::endl;
return;
}
if(goblb::SpaceState::EMPTY != board.state(i, j))
{
std::cout << "There is already a stone at " << i
<< ' ' << j << std::endl;
return;
}
if(board.ko() && i == board.ko()->i() && j == board.ko()->j())
{
std::cout << "It is against the rules to play within a ko."
<< std::endl;
return;
}
board.play(
i
, j
, black ? goblb::SpaceState::BLACK : goblb::SpaceState::WHITE
);
black = !black;
}
} // Close anonymous
int main(int argc, char* argv[])
{
if(argc > 2 && "--parse" == std::string(argv[1]))
{
gobls::Sgf::Ptr sgf = gobls::Parser::parseFile(argv[2]);
std::cout << "PARSED" << std::endl << *sgf << std::endl;
return 0;
}
goblb::Board board;
std::string line;
bool black = true;
std::cout << board << std::endl << std::endl
<< "BLACK'S TURN" << std::endl;
while(std::getline(std::cin, line))
{
handleInput(board, black, line);
std::cout << std::endl << board << std::endl;
if(board.ko())
{
std::cout << "KO AT " << board.ko()->i()
<< ' ' << board.ko()->j()
<< std::endl;
}
std::cout << (black ? "BLACK" : "WHITE")
<< "'S TURN" << std::endl;
}
std::cout << "---------------------------------" << std::endl
<< "---------- FINAL BOARD ----------" << std::endl
<< "---------------------------------" << std::endl
<< std::endl << board << std::endl;
return 0;
}