-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueen.cpp
More file actions
209 lines (188 loc) · 5.49 KB
/
Copy pathqueen.cpp
File metadata and controls
209 lines (188 loc) · 5.49 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
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#include "queen.h"
using namespace std;
string Queen::getName(){
return ("Królowa");
}
int Queen::getwhiteStartRow(){
return Queen::whiteStartRow;
}
int Queen::getwhiteStartColumn(){
return Queen::whiteStartColumn;
}
int Queen::getblackStartRow(){
return Queen::blackStartRow;
}
int Queen::getblackStartColumn(){
return Queen::blackStartColumn;
}
QString Queen::getIconName(){
if(Queen::getColor() == "white"){
return("queen1");
} else {
return("queen");
}
}
/*!
* \brief Queen::checkPossibleMove Function return possible movex of object
* \param position Current position of object
* \param ChessBoard Current position of all object on chess board
* \return List boolean, which field is possible to move on
*/
array<array<bool,8>,8> Queen::checkPossibleMove(array<int, 2> position, array<array<Pawn*,8>,8> ChessBoard){
array<array<bool,8>,8> possibleMoves;
int startRow = 0;
int startCol = 0;
int endRow = 7;
int endCol = 7;
string color = ChessBoard[position[0]][position[1]]->getColor();
string actualColor;
//prawo
for(int row=0; row<8; row++){
for(int col=0; col<8; col++){
possibleMoves[row][col] = false;
}
}
if ((position[0]+1) < 8){
for(int i = (position[0] + 1); i<8; i++){
actualColor = ChessBoard[i][position[1]]->getColor();
if(actualColor == ""){
} else if (actualColor == color){
endRow = i - 1;
break;
} else {
//zbijanie
endRow = i;
break;
}
}
}
//lewo
if ((position[0] - 1) >= 0){
for(int i = (position[0] - 1); i>=0; i--){
actualColor = ChessBoard[i][position[1]]->getColor();
if(actualColor == ""){
} else if (actualColor == color){
startRow = i + 1;
break;
} else {
//zbijanie
startRow = i;
break;
}
}
}
//przód
if((position[1] + 1) < 8) {
for(int i = (position[1] + 1); i<8; i++){
actualColor = ChessBoard[position[0]][i]->getColor();
if(actualColor == ""){
} else if (actualColor == color){
endCol = i - 1;
break;
} else {
//zbijanie
endCol = i;
break;
}
}
}
//tył
if((position[1] - 1) >= 0 ){
for(int i = (position[1] - 1); i>=0; i--){
actualColor = ChessBoard[position[0]][i]->getColor();
if(actualColor == ""){
} else if (actualColor == color){
startCol = i + 1;
break;
} else {
//zbijanie
startCol = i;
break;
}
}
}
//poziom
if(startRow != endRow){
for(int i=startRow; i<endRow; i++){
possibleMoves[i][position[1]] = true;
}
}
if(startCol != endCol){
for(int i=startCol; i<endCol; i++){
possibleMoves[position[0]][i] = true;
}
}
if ((position[0]+1) < 8 && (position[1]+1) < 8){
int col = position[1]+1;
for(int i = (position[0] + 1); i<8; i++){
if(col < 8){
actualColor = ChessBoard[i][col]->getColor();
if(actualColor == ""){
possibleMoves[i][col] = true;
} else if (actualColor == color){
break;
} else {
possibleMoves[i][col] = true;
break;
}
}
col++;
}
}
//lewy tył
if ((position[0] - 1) >= 0 && (position[1] - 1) >= 0){
int col = position[1] - 1;
for(int i = (position[0] - 1); i>=0; i--){
if(col >= 0){
actualColor = ChessBoard[i][col]->getColor();
if(actualColor == ""){
possibleMoves[i][col] = true;
} else if (actualColor == color){
break;
} else {
possibleMoves[i][col] = true;
break;
}
}
col--;
}
}
//przód
if((position[0] + 1) < 8 && (position[1] - 1) >= 0) {
int col = position[1] - 1;
for(int i = (position[0] + 1); i<8; i++){
if(col >= 0){
actualColor = ChessBoard[i][col]->getColor();
if(actualColor == ""){
possibleMoves[i][col] = true;
} else if (actualColor == color){
break;
} else {
possibleMoves[i][col] = true;
break;
}
}
col--;
}
}
//tył
if((position[0] - 1) >= 0 && (position[1]+1) < 8){
int col = position[1] + 1;
for(int i = (position[0] - 1); i>=0; i--){
if(col < 8){
actualColor = ChessBoard[i][col]->getColor();
if(actualColor == ""){
possibleMoves[i][col] = true;
} else if (actualColor == color){
break;
} else {
possibleMoves[i][col] = true;
break;
}
}
col++;
}
}
possibleMoves[position[0]][position[1]] = false;
return possibleMoves;
}