-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCheckersPiece.cc
149 lines (133 loc) · 4.25 KB
/
CheckersPiece.cc
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
140
141
142
143
144
145
146
147
148
149
#include "CheckersPiece.h"
#include <iostream>
CheckersPosition CheckersPiece::get_position() {
return pos;
}
void CheckersPiece::set_position(CheckersPosition df) {
pos = df;
}
bool CheckersPiece::is_none_piece() {
if (get_position().get_row() == -1) {
return true;
} else {
return false;
}
}
bool CheckersPiece::is_captured() {
return capt;
}
bool CheckersPiece::is_crowned() {
return crown;
}
bool CheckersPiece::is_dark() {
return dark;
}
void CheckersPiece::set_captured() {
capt = true;
pos.set_row(-1);
pos.set_col(-1);
}
void CheckersPiece::set_crowned() {
crown = true;
}
void CheckersPiece::set_dark(bool a) {
dark = a;
}
// CheckersPiece piece_init(CheckersPiece ax) {
// ax.set_crowned(false);
// ax.set_captured(false);
// ax.set_dark(false);
// ax.set_position({0, 0});
// return ax;
// }
std::vector<CheckersPosition>
piece_positions_in_direction(CheckersPiece yo, int m) {
std::vector<CheckersPosition> wutt(0);
int t = 0;
if ((m == 0 && yo.is_dark() == false) || (m == 0 && yo.is_crowned())) {
t = 1;
yo.set_position({yo.get_position().get_row() + 1,
yo.get_position().get_col() + 1});
} else if ((m == 1 && yo.is_dark() == false) || (m == 1 &&
yo.is_crowned())) {
t = 1;
yo.set_position({yo.get_position().get_row() + 1,
yo.get_position().get_col() - 1});
} else if ((m == 2 && yo.is_dark()) || (m == 2 && yo.is_crowned())) {
t = 1;
yo.set_position({yo.get_position().get_row() - 1,
yo.get_position().get_col() - 1});
} else if ((m == 3 && yo.is_dark()) || (m == 3 && yo.is_crowned())) {
t = 1;
yo.set_position({yo.get_position().get_row() - 1,
yo.get_position().get_col() + 1});
}
if (yo.get_position().get_row() >= 0 && yo.get_position().get_row() < 8 &&
yo.get_position().get_col() >= 0 && yo.get_position().get_col()
< 8 && t ==1) {
CheckersPosition dude;
dude.set_row(yo.get_position().get_row());
dude.set_col(yo.get_position().get_row());
wutt.push_back(dude); // First time stored here
// Second time begins here
if ((m == 0 && yo.is_dark() == false) || (m == 0 && yo.is_crowned())) {
yo.set_position({yo.get_position().get_row() + 1,
yo.get_position().get_col() + 1});
} else if ((m == 1 && yo.is_dark() == false) || (m == 1 &&
yo.is_crowned())) {
t = 1;
yo.set_position({yo.get_position().get_row() + 1,
yo.get_position().get_col() - 1});
} else if ((m == 2 && yo.is_dark()) || (m == 2 && yo.is_crowned())) {
t = 1;
yo.set_position({yo.get_position().get_row() - 1,
yo.get_position().get_col() - 1});
} else if ((m == 3 && yo.is_dark()) || (m == 3 && yo.is_crowned())) {
t = 1;
yo.set_position({yo.get_position().get_row() - 1,
yo.get_position().get_col() + 1});
}
if (yo.get_position().get_row() >= 0 && yo.get_position().get_row() < 8 &&
yo.get_position().get_col() >= 0 &&
yo.get_position().get_col() < 8) {
CheckersPosition thisone;
thisone.set_row(yo.get_position().get_row());
thisone.set_col(yo.get_position().get_col());
wutt.push_back(thisone);
}
}
return wutt;
}
std::vector<std::vector<CheckersPosition>> piece_neighbors(CheckersPiece dm) {
std::vector<std::vector<CheckersPosition>> dq;
int df;
for (df = 3; df >= 0; df--) {
dq.push_back(piece_positions_in_direction(dm, df));
}
return dq;
}
bool piece_isnonepiece(CheckersPiece ax) {
if (ax.get_position().get_row() == -1) {
return true;
} else {
return false;
}
}
std::ostream& operator<<(std::ostream & tv, CheckersPiece az) {
if (az.is_captured() || piece_isnonepiece(az)) {
tv << '.';
} else if (az.is_dark() == false) {
if (az.is_crowned() == false) {
tv << 'w';
} else if (az.is_crowned() == true) {
tv << 'W';
}
} else if (az.is_dark() == true) {
if (az.is_crowned() == false) {
tv << 'b';
} else if (az.is_crowned() == true) {
tv << 'B';
}
}
return tv;
}