-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_set.cpp
139 lines (125 loc) · 2.42 KB
/
get_set.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#pragma once
#include "table.hpp"
Table::Table()
{
constructor();
}
char Table::getBoard(coor c)
{
try
{
if (isOnBoard(c))
return board[c.row][c.col];
else
throw "getBoard: Invalid row or column\n";
}
catch (const char *msg)
{
std::cerr << msg;
}
return '\0';
}
bool Table::getGuidance()
{
return this->guidance;
}
GameMode Table::getGameMode()
{
return this->gameMode;
}
char Table::getTurn()
{
return this->turn;
}
char Table::getOpponent()
{
return this->opponent;
}
char Table::getUserSide()
{
return this->userSide;
}
void Table::setBoard(coor c, char value)
{
try
{
if (isOnBoard(c) && (value == BLACK ||
value == WHITE ||
value == EMPTY ||
value == LEGAL))
board[c.row][c.col] = value;
else
throw "setBoard: Invalid row or column or value\n";
}
catch (const char *msg)
{
std::cerr << msg;
}
}
void Table::setGuidance(bool m)
{
this->guidance = m;
}
void Table::setGameMode(GameMode gm)
{
try
{
if (gm == HUMAN_VS_HUMAN || gm == HUMAN_VS_CPU || gm == CPU_VS_CPU || gm == LOAD_GAME)
this->gameMode = gm;
else
throw "setGameMode: Invalid game mode\n";
}
catch (const char *msg)
{
std::cerr << msg;
}
}
void Table::setTurn(char t)
{
try
{
if (t == BLACK)
{
this->turn = BLACK;
this->opponent = WHITE;
}
else if (t == WHITE)
{
this->turn = WHITE;
this->opponent = BLACK;
}
else
throw "setTurn: Invalid turn\n";
}
catch (const char *msg)
{
std::cerr << msg;
}
}
void Table::switchTurn()
{
if (getTurn() == BLACK)
{
setTurn(WHITE);
}
else
{
setTurn(BLACK);
}
// update legal moves after switching turns
marker();
}
void Table::setUserSide(char s)
{
try
{
if (s == BLACK || s == WHITE)
this->userSide = s;
else
throw "setUserSide: Invalid side\n";
}
catch (const char *msg)
{
std::cerr << msg;
}
}