-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfacade.cpp
More file actions
94 lines (84 loc) · 2.26 KB
/
facade.cpp
File metadata and controls
94 lines (84 loc) · 2.26 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
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
#include <string.h>
#include "facade.h"
using namespace std;
void Facade::changeColor(bool value) { black = value; }
bool Facade::getColor() { return black; }
void Facade::start() {
setbuf(stdin, NULL);
setbuf(stdout, NULL);
initialize();
int result = 1;
while(result) {
result = newGame();
delete game;
game = new Game();
changeColor(true);
}
}
void Facade::initialize() {
readIrrelevantLines(3);
cout << "feature sigint=0 san=0 name=Hello\n";
readIrrelevantLines(7);
}
int Facade::newGame() {
readIrrelevantLines(7);
char *input = (char *) calloc(1000, sizeof(char));
cin >> input;
while(strcmp(input, "quit") != 0) {
if(!strcmp(input, "force")) {
if(pauseGame()) {
free(input);
return 1;
}
else
cout << game->getNextMove(!black) << endl;
}
if(!strcmp(input, "time")) {
readIrrelevantLines(3);
cin >> input;
game->updateBoardForEnemy(input, black);
cout << game->getNextMove(!black) << endl;
}
else if(!strcmp(input, "white") || !strcmp(input, "black")) {
changeColor(!getColor());
readIrrelevantLines(6);
cout << game->getNextMove(!black) << endl;
}
cin >> input;
}
free(input);
return 0;
}
int Facade::pauseGame() {
char *input = (char *) calloc(1000, sizeof(char));
cin >> input;
while(strcmp(input, "go") && strcmp(input, "new") && strcmp(input, "quit")) {
if(!strcmp(input, "white")) {
changeColor(true);
readIrrelevantLines(5);
}
else if (!strcmp(input, "black")) {
changeColor(false);
readIrrelevantLines(5);
}
if(game->updateBoardForEnemy(input, black) == 1)
black = !black;
cin >> input;
}
if(!strcmp(input, "quit")) {
free(input);
exit(0);
}
if(!strcmp(input, "go")) {
free(input);
return 0;
}
free(input);
return 1;
}
void Facade::readIrrelevantLines(int noLines) {
char *input = (char *) calloc(1000, sizeof(char));
for(int i = 0; i < noLines; ++i)
cin >> input;
free(input);
}