1 | /* |
---|
2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
3 | * > www.orxonox.net < |
---|
4 | * |
---|
5 | * |
---|
6 | * License notice: |
---|
7 | * |
---|
8 | * This program is free software; you can redistribute it and/or |
---|
9 | * modify it under the terms of the GNU General Public License |
---|
10 | * as published by the Free Software Foundation; either version 2 |
---|
11 | * of the License, or (at your option) any later version. |
---|
12 | * |
---|
13 | * This program is distributed in the hope that it will be useful, |
---|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | * GNU General Public License for more details. |
---|
17 | * |
---|
18 | * You should have received a copy of the GNU General Public License |
---|
19 | * along with this program; if not, write to the Free Software |
---|
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
21 | * |
---|
22 | * Author: |
---|
23 | * Fabian 'x3n' Landau |
---|
24 | * Co-authors: |
---|
25 | * ... |
---|
26 | * |
---|
27 | */ |
---|
28 | |
---|
29 | /** |
---|
30 | @file PongBall.cc |
---|
31 | @brief Implementation of the PongBall class. |
---|
32 | */ |
---|
33 | |
---|
34 | #include "Mini4DgameBoard.h" |
---|
35 | |
---|
36 | #include "core/CoreIncludes.h" |
---|
37 | #include "core/GameMode.h" |
---|
38 | |
---|
39 | #include "gametypes/Gametype.h" |
---|
40 | |
---|
41 | #include "core/XMLPort.h" |
---|
42 | |
---|
43 | #include "Mini4Dgame.h" |
---|
44 | |
---|
45 | namespace orxonox |
---|
46 | { |
---|
47 | RegisterClass(Mini4DgameBoard); |
---|
48 | |
---|
49 | /** |
---|
50 | @brief |
---|
51 | Constructor. Registers and initializes the object. |
---|
52 | */ |
---|
53 | Mini4DgameBoard::Mini4DgameBoard(Context* context) : StaticEntity(context) |
---|
54 | { |
---|
55 | RegisterObject(Mini4DgameBoard); |
---|
56 | |
---|
57 | //this->registerVariables(); |
---|
58 | |
---|
59 | //initialize sound |
---|
60 | for(int i=0;i<4;i++){ |
---|
61 | for(int j=0;j<4;j++){ |
---|
62 | for(int k=0;k<4;k++){ |
---|
63 | for(int l=0;l<4;l++){ |
---|
64 | this->board[i][j][k][l]=mini4DgamePlayerColor::none; |
---|
65 | } |
---|
66 | } |
---|
67 | } |
---|
68 | } |
---|
69 | } |
---|
70 | |
---|
71 | /** |
---|
72 | @brief |
---|
73 | Destructor. |
---|
74 | */ |
---|
75 | Mini4DgameBoard::~Mini4DgameBoard() |
---|
76 | { |
---|
77 | if (this->isInitialized()) |
---|
78 | { |
---|
79 | |
---|
80 | } |
---|
81 | } |
---|
82 | |
---|
83 | //xml port for loading sounds |
---|
84 | void Mini4DgameBoard::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
85 | { |
---|
86 | SUPER(Mini4DgameBoard, XMLPort, xmlelement, mode); |
---|
87 | } |
---|
88 | |
---|
89 | /** |
---|
90 | @brief |
---|
91 | Register variables to synchronize over the network. |
---|
92 | |
---|
93 | void Mini4DgameBoard::registerVariables() |
---|
94 | { |
---|
95 | registerVariable( this->fieldWidth_ ); |
---|
96 | registerVariable( this->fieldHeight_ ); |
---|
97 | registerVariable( this->batlength_ ); |
---|
98 | registerVariable( this->speed_ ); |
---|
99 | registerVariable( this->relMercyOffset_ ); |
---|
100 | registerVariable( this->batID_[0] ); |
---|
101 | registerVariable( this->batID_[1], VariableDirection::ToClient, new NetworkCallback<PongBall>( this, &PongBall::applyBats) ); |
---|
102 | } |
---|
103 | */ |
---|
104 | |
---|
105 | /** |
---|
106 | @brief checks if the move is valid |
---|
107 | @param the position where to put the stone plus the player who makes the move |
---|
108 | */ |
---|
109 | bool Mini4DgameBoard::isValidMove(const Vector4 move) |
---|
110 | { |
---|
111 | return (this->board[(int)move.x][(int)move.y][(int)move.z][(int)move.w] == mini4DgamePlayerColor::none); |
---|
112 | } |
---|
113 | |
---|
114 | |
---|
115 | |
---|
116 | /** |
---|
117 | @brief makes a move on the logic playboard |
---|
118 | @param the position where to put the stone plus the player who makes the move |
---|
119 | */ |
---|
120 | void Mini4DgameBoard::makeMove(const Vector4 move, const int playerColor) |
---|
121 | { |
---|
122 | if(this->isValidMove(move)) |
---|
123 | { |
---|
124 | this->board[(int)move.x][(int)move.y][(int)move.z][(int)move.w] = (mini4DgamePlayerColor::color) playerColor; |
---|
125 | //BlinkingBillboard* bb = new BlinkingBillboard(this->getContext()); |
---|
126 | //bb->setPosition(0,0,0); |
---|
127 | Mini4DgameWinner winner = this->getWinner(); |
---|
128 | if(winner.color_ != mini4DgamePlayerColor::none) |
---|
129 | { |
---|
130 | //win(winner); |
---|
131 | } |
---|
132 | } |
---|
133 | } |
---|
134 | |
---|
135 | Mini4DgameWinner Mini4DgameBoard::getWinner() |
---|
136 | { |
---|
137 | Mini4DgameWinner winner; |
---|
138 | winner.color_ = mini4DgamePlayerColor::none; |
---|
139 | |
---|
140 | //check diagonals rows-columns-height-numbers |
---|
141 | for(int i=1; i<4; i++) |
---|
142 | { |
---|
143 | if(this->board[i][i][i][i]==mini4DgamePlayerColor::none || this->board[0][0][0][0] != this->board[i][i][i][i]) |
---|
144 | break; |
---|
145 | if(i==3) |
---|
146 | { |
---|
147 | winner.color_ = this->board[0][0][0][0]; |
---|
148 | for(int x=0; x<4; x++){ |
---|
149 | winner.winningRow[x] = x; |
---|
150 | winner.winningColumn[x] = x; |
---|
151 | winner.winningHeight[x] = x; |
---|
152 | winner.winningNumber[x] = x; |
---|
153 | } |
---|
154 | return winner; |
---|
155 | } |
---|
156 | } |
---|
157 | for(int i=1; i<4; i++) |
---|
158 | { |
---|
159 | if(this->board[3-i][i][i][i]==mini4DgamePlayerColor::none || this->board[3][0][0][0] != this->board[3-i][i][i][i]) |
---|
160 | break; |
---|
161 | if(i==3) |
---|
162 | { |
---|
163 | winner.color_ = this->board[3][0][0][0]; |
---|
164 | for(int x=0; x<4; x++){ |
---|
165 | winner.winningRow[x] = 3-x; |
---|
166 | winner.winningColumn[x] = x; |
---|
167 | winner.winningHeight[x] = x; |
---|
168 | winner.winningNumber[x] = x; |
---|
169 | } |
---|
170 | return winner; |
---|
171 | } |
---|
172 | } |
---|
173 | for(int i=1; i<4; i++) |
---|
174 | { |
---|
175 | if(this->board[i][3-i][i][i]==mini4DgamePlayerColor::none || this->board[0][3][0][0] != this->board[i][3-i][i][i]) |
---|
176 | break; |
---|
177 | if(i==3) |
---|
178 | { |
---|
179 | winner.color_ = this->board[0][3][0][0]; |
---|
180 | for(int x=0; x<4; x++){ |
---|
181 | winner.winningRow[x] = x; |
---|
182 | winner.winningColumn[x] = 3-x; |
---|
183 | winner.winningHeight[x] = x; |
---|
184 | winner.winningNumber[x] = x; |
---|
185 | } |
---|
186 | return winner; |
---|
187 | } |
---|
188 | } |
---|
189 | for(int i=1; i<4; i++) |
---|
190 | { |
---|
191 | if(this->board[i][i][3-i][i]==mini4DgamePlayerColor::none || this->board[0][0][3][0] != this->board[i][i][3-i][i]) |
---|
192 | break; |
---|
193 | if(i==3) |
---|
194 | { |
---|
195 | winner.color_ = this->board[0][0][3][0]; |
---|
196 | for(int x=0; x<4; x++){ |
---|
197 | winner.winningRow[x] = x; |
---|
198 | winner.winningColumn[x] = x; |
---|
199 | winner.winningHeight[x] = 3-x; |
---|
200 | winner.winningNumber[x] = x; |
---|
201 | } |
---|
202 | return winner; |
---|
203 | } |
---|
204 | } |
---|
205 | for(int i=1; i<4; i++) |
---|
206 | { |
---|
207 | if(this->board[i][i][i][3-i]==mini4DgamePlayerColor::none || this->board[0][0][0][3] != this->board[i][i][i][3-i]) |
---|
208 | break; |
---|
209 | if(i==3) |
---|
210 | { |
---|
211 | winner.color_ = this->board[0][0][0][3]; |
---|
212 | for(int x=0; x<4; x++){ |
---|
213 | winner.winningRow[x] = x; |
---|
214 | winner.winningColumn[x] = x; |
---|
215 | winner.winningHeight[x] = x; |
---|
216 | winner.winningNumber[x] = 3-x; |
---|
217 | } |
---|
218 | return winner; |
---|
219 | } |
---|
220 | } |
---|
221 | for(int i=1; i<4; i++) |
---|
222 | { |
---|
223 | if(this->board[3-i][3-i][i][i]==mini4DgamePlayerColor::none || this->board[3][3][0][0] != this->board[3-i][3-i][i][i]) |
---|
224 | break; |
---|
225 | if(i==3) |
---|
226 | { |
---|
227 | winner.color_ = this->board[3][3][0][0]; |
---|
228 | for(int x=0; x<4; x++){ |
---|
229 | winner.winningRow[x] = 3-x; |
---|
230 | winner.winningColumn[x] = 3-x; |
---|
231 | winner.winningHeight[x] = x; |
---|
232 | winner.winningNumber[x] = x; |
---|
233 | } |
---|
234 | return winner; |
---|
235 | } |
---|
236 | } |
---|
237 | for(int i=1; i<4; i++) |
---|
238 | { |
---|
239 | if(this->board[3-i][i][3-i][i]==mini4DgamePlayerColor::none || this->board[3][0][3][0] != this->board[3-i][i][3-i][i]) |
---|
240 | break; |
---|
241 | if(i==3) |
---|
242 | { |
---|
243 | winner.color_ = this->board[3][0][3][0]; |
---|
244 | for(int x=0; x<4; x++){ |
---|
245 | winner.winningRow[x] = 3-x; |
---|
246 | winner.winningColumn[x] = x; |
---|
247 | winner.winningHeight[x] = 3-x; |
---|
248 | winner.winningNumber[x] = x; |
---|
249 | } |
---|
250 | return winner; |
---|
251 | } |
---|
252 | } |
---|
253 | for(int i=1; i<4; i++) |
---|
254 | { |
---|
255 | if(this->board[3-i][i][i][3-i]==mini4DgamePlayerColor::none || this->board[3][0][0][3] != this->board[3-i][i][i][3-i]) |
---|
256 | break; |
---|
257 | if(i==3) |
---|
258 | { |
---|
259 | winner.color_ = this->board[3][0][0][3]; |
---|
260 | for(int x=0; x<4; x++){ |
---|
261 | winner.winningRow[x] = 3-x; |
---|
262 | winner.winningColumn[x] = x; |
---|
263 | winner.winningHeight[x] = x; |
---|
264 | winner.winningNumber[x] = 3-x; |
---|
265 | } |
---|
266 | return winner; |
---|
267 | } |
---|
268 | } |
---|
269 | |
---|
270 | //check diagonals rows-columns-height |
---|
271 | for(int l=0; l<4; l++) |
---|
272 | { |
---|
273 | for(int i=1; i<4; i++) |
---|
274 | { |
---|
275 | if(this->board[i][i][i][l]==mini4DgamePlayerColor::none || this->board[0][0][0][l] != this->board[i][i][i][l]) |
---|
276 | break; |
---|
277 | if(i==3) |
---|
278 | { |
---|
279 | winner.color_ = this->board[0][0][0][l]; |
---|
280 | for(int x=0; x<4; x++){ |
---|
281 | winner.winningRow[x] = x; |
---|
282 | winner.winningColumn[x] = x; |
---|
283 | winner.winningHeight[x] = x; |
---|
284 | winner.winningNumber[x] = l; |
---|
285 | } |
---|
286 | return winner; |
---|
287 | } |
---|
288 | } |
---|
289 | for(int i=1; i<4; i++) |
---|
290 | { |
---|
291 | if(this->board[3-i][i][i][l]==mini4DgamePlayerColor::none || this->board[3][0][0][l] != this->board[3-i][i][i][l]) |
---|
292 | break; |
---|
293 | if(i==3) |
---|
294 | { |
---|
295 | winner.color_ = this->board[3][0][0][l]; |
---|
296 | for(int x=0; x<4; x++){ |
---|
297 | winner.winningRow[x] = 3-x; |
---|
298 | winner.winningColumn[x] = x; |
---|
299 | winner.winningHeight[x] = x; |
---|
300 | winner.winningNumber[x] = l; |
---|
301 | } |
---|
302 | return winner; |
---|
303 | } |
---|
304 | } |
---|
305 | for(int i=1; i<4; i++) |
---|
306 | { |
---|
307 | if(this->board[i][3-i][i][l]==mini4DgamePlayerColor::none || this->board[0][3][0][l] != this->board[i][3-i][i][l]) |
---|
308 | break; |
---|
309 | if(i==3) |
---|
310 | { |
---|
311 | winner.color_ = this->board[0][3][0][l]; |
---|
312 | for(int x=0; x<4; x++){ |
---|
313 | winner.winningRow[x] = x; |
---|
314 | winner.winningColumn[x] = 3-x; |
---|
315 | winner.winningHeight[x] = x; |
---|
316 | winner.winningNumber[x] = l; |
---|
317 | } |
---|
318 | return winner; |
---|
319 | } |
---|
320 | } |
---|
321 | for(int i=1; i<4; i++) |
---|
322 | { |
---|
323 | if(this->board[i][i][3-i][l]==mini4DgamePlayerColor::none || this->board[0][0][3][l] != this->board[i][i][3-i][l]) |
---|
324 | break; |
---|
325 | if(i==3) |
---|
326 | { |
---|
327 | winner.color_ = this->board[0][0][3][l]; |
---|
328 | for(int x=0; x<4; x++){ |
---|
329 | winner.winningRow[x] = x; |
---|
330 | winner.winningColumn[x] = x; |
---|
331 | winner.winningHeight[x] = 3-x; |
---|
332 | winner.winningNumber[x] = l; |
---|
333 | } |
---|
334 | return winner; |
---|
335 | } |
---|
336 | } |
---|
337 | } |
---|
338 | |
---|
339 | //check diagonals rows-columns-numbers |
---|
340 | for(int l=0; l<4; l++) |
---|
341 | { |
---|
342 | for(int i=1; i<4; i++) |
---|
343 | { |
---|
344 | if(this->board[i][i][l][i]==mini4DgamePlayerColor::none || this->board[0][0][l][0] != this->board[i][i][l][i]) |
---|
345 | break; |
---|
346 | if(i==3) |
---|
347 | { |
---|
348 | winner.color_ = this->board[0][0][l][0]; |
---|
349 | for(int x=0; x<4; x++){ |
---|
350 | winner.winningRow[x] = x; |
---|
351 | winner.winningColumn[x] = x; |
---|
352 | winner.winningHeight[x] = l; |
---|
353 | winner.winningNumber[x] = x; |
---|
354 | } |
---|
355 | return winner; |
---|
356 | } |
---|
357 | } |
---|
358 | for(int i=1; i<4; i++) |
---|
359 | { |
---|
360 | if(this->board[3-i][i][l][i]==mini4DgamePlayerColor::none || this->board[3][0][l][0] != this->board[3-i][i][l][i]) |
---|
361 | break; |
---|
362 | if(i==3) |
---|
363 | { |
---|
364 | winner.color_ = this->board[3][0][l][0]; |
---|
365 | for(int x=0; x<4; x++){ |
---|
366 | winner.winningRow[x] = 3-x; |
---|
367 | winner.winningColumn[x] = x; |
---|
368 | winner.winningHeight[x] = l; |
---|
369 | winner.winningNumber[x] = x; |
---|
370 | } |
---|
371 | return winner; |
---|
372 | } |
---|
373 | } |
---|
374 | for(int i=1; i<4; i++) |
---|
375 | { |
---|
376 | if(this->board[i][3-i][l][i]==mini4DgamePlayerColor::none || this->board[0][3][l][0] != this->board[i][3-i][l][i]) |
---|
377 | break; |
---|
378 | if(i==3) |
---|
379 | { |
---|
380 | winner.color_ = this->board[0][3][l][0]; |
---|
381 | for(int x=0; x<4; x++){ |
---|
382 | winner.winningRow[x] = x; |
---|
383 | winner.winningColumn[x] = 3-x; |
---|
384 | winner.winningHeight[x] = l; |
---|
385 | winner.winningNumber[x] = x; |
---|
386 | } |
---|
387 | return winner; |
---|
388 | } |
---|
389 | } |
---|
390 | for(int i=1; i<4; i++) |
---|
391 | { |
---|
392 | if(this->board[i][i][l][3-i]==mini4DgamePlayerColor::none || this->board[0][0][l][3] != this->board[i][i][l][3-i]) |
---|
393 | break; |
---|
394 | if(i==3) |
---|
395 | { |
---|
396 | winner.color_ = this->board[0][0][l][3]; |
---|
397 | for(int x=0; x<4; x++){ |
---|
398 | winner.winningRow[x] = x; |
---|
399 | winner.winningColumn[x] = x; |
---|
400 | winner.winningHeight[x] = l; |
---|
401 | winner.winningNumber[x] = 3-x; |
---|
402 | } |
---|
403 | return winner; |
---|
404 | } |
---|
405 | } |
---|
406 | } |
---|
407 | |
---|
408 | //check diagonals rows-height-numbers |
---|
409 | for(int l=0; l<4; l++) |
---|
410 | { |
---|
411 | for(int i=1; i<4; i++) |
---|
412 | { |
---|
413 | if(this->board[i][l][i][i]==mini4DgamePlayerColor::none || this->board[0][l][0][0] != this->board[i][l][i][i]) |
---|
414 | break; |
---|
415 | if(i==3) |
---|
416 | { |
---|
417 | winner.color_ = this->board[0][l][0][0]; |
---|
418 | for(int x=0; x<4; x++){ |
---|
419 | winner.winningRow[x] = x; |
---|
420 | winner.winningColumn[x] = l; |
---|
421 | winner.winningHeight[x] = x; |
---|
422 | winner.winningNumber[x] = x; |
---|
423 | } |
---|
424 | return winner; |
---|
425 | } |
---|
426 | } |
---|
427 | for(int i=1; i<4; i++) |
---|
428 | { |
---|
429 | if(this->board[3-i][l][i][i]==mini4DgamePlayerColor::none || this->board[3][l][0][0] != this->board[3-i][l][i][i]) |
---|
430 | break; |
---|
431 | if(i==3) |
---|
432 | { |
---|
433 | winner.color_ = this->board[3][l][0][0]; |
---|
434 | for(int x=0; x<4; x++){ |
---|
435 | winner.winningRow[x] = 3-x; |
---|
436 | winner.winningColumn[x] = l; |
---|
437 | winner.winningHeight[x] = x; |
---|
438 | winner.winningNumber[x] = x; |
---|
439 | } |
---|
440 | return winner; |
---|
441 | } |
---|
442 | } |
---|
443 | for(int i=1; i<4; i++) |
---|
444 | { |
---|
445 | if(this->board[i][l][3-i][i]==mini4DgamePlayerColor::none || this->board[0][l][3][0] != this->board[i][l][3-i][i]) |
---|
446 | break; |
---|
447 | if(i==3) |
---|
448 | { |
---|
449 | winner.color_ = this->board[0][l][3][0]; |
---|
450 | for(int x=0; x<4; x++){ |
---|
451 | winner.winningRow[x] = x; |
---|
452 | winner.winningColumn[x] = l; |
---|
453 | winner.winningHeight[x] = 3-x; |
---|
454 | winner.winningNumber[x] = x; |
---|
455 | } |
---|
456 | return winner; |
---|
457 | } |
---|
458 | } |
---|
459 | for(int i=1; i<4; i++) |
---|
460 | { |
---|
461 | if(this->board[i][l][i][3-i]==mini4DgamePlayerColor::none || this->board[0][l][0][3] != this->board[i][l][i][3-i]) |
---|
462 | break; |
---|
463 | if(i==3) |
---|
464 | { |
---|
465 | winner.color_ = this->board[0][l][0][3]; |
---|
466 | for(int x=0; x<4; x++){ |
---|
467 | winner.winningRow[x] = x; |
---|
468 | winner.winningColumn[x] = l; |
---|
469 | winner.winningHeight[x] = x; |
---|
470 | winner.winningNumber[x] = 3-x; |
---|
471 | } |
---|
472 | return winner; |
---|
473 | } |
---|
474 | } |
---|
475 | } |
---|
476 | |
---|
477 | //check diagonals columns-height-numbers |
---|
478 | for(int l=0; l<4; l++) |
---|
479 | { |
---|
480 | for(int i=1; i<4; i++) |
---|
481 | { |
---|
482 | if(this->board[l][i][i][i]==mini4DgamePlayerColor::none || this->board[l][0][0][0] != this->board[l][i][i][i]) |
---|
483 | break; |
---|
484 | if(i==3) |
---|
485 | { |
---|
486 | winner.color_ = this->board[l][0][0][0]; |
---|
487 | for(int x=0; x<4; x++){ |
---|
488 | winner.winningRow[x] = l; |
---|
489 | winner.winningColumn[x] = x; |
---|
490 | winner.winningHeight[x] = x; |
---|
491 | winner.winningNumber[x] = x; |
---|
492 | } |
---|
493 | return winner; |
---|
494 | } |
---|
495 | } |
---|
496 | for(int i=1; i<4; i++) |
---|
497 | { |
---|
498 | if(this->board[l][3-i][i][i]==mini4DgamePlayerColor::none || this->board[l][3][0][0] != this->board[l][3-i][i][i]) |
---|
499 | break; |
---|
500 | if(i==3) |
---|
501 | { |
---|
502 | winner.color_ = this->board[l][3][0][0]; |
---|
503 | for(int x=0; x<4; x++){ |
---|
504 | winner.winningRow[x] = l; |
---|
505 | winner.winningColumn[x] = 3-x; |
---|
506 | winner.winningHeight[x] = x; |
---|
507 | winner.winningNumber[x] = x; |
---|
508 | } |
---|
509 | return winner; |
---|
510 | } |
---|
511 | } |
---|
512 | for(int i=1; i<4; i++) |
---|
513 | { |
---|
514 | if(this->board[l][i][3-i][i]==mini4DgamePlayerColor::none || this->board[l][0][3][0] != this->board[l][i][3-i][i]) |
---|
515 | break; |
---|
516 | if(i==3) |
---|
517 | { |
---|
518 | winner.color_ = this->board[l][0][3][0]; |
---|
519 | for(int x=0; x<4; x++){ |
---|
520 | winner.winningRow[x] = l; |
---|
521 | winner.winningColumn[x] = x; |
---|
522 | winner.winningHeight[x] = 3-x; |
---|
523 | winner.winningNumber[x] = x; |
---|
524 | } |
---|
525 | return winner; |
---|
526 | } |
---|
527 | } |
---|
528 | for(int i=1; i<4; i++) |
---|
529 | { |
---|
530 | if(this->board[l][i][i][3-i]==mini4DgamePlayerColor::none || this->board[l][0][0][3] != this->board[l][i][i][3-i]) |
---|
531 | break; |
---|
532 | if(i==3) |
---|
533 | { |
---|
534 | winner.color_ = this->board[l][0][0][3]; |
---|
535 | for(int x=0; x<4; x++){ |
---|
536 | winner.winningRow[x] = l; |
---|
537 | winner.winningColumn[x] = x; |
---|
538 | winner.winningHeight[x] = x; |
---|
539 | winner.winningNumber[x] = 3-x; |
---|
540 | } |
---|
541 | return winner; |
---|
542 | } |
---|
543 | } |
---|
544 | } |
---|
545 | |
---|
546 | //check 2d diagonals |
---|
547 | for(int k=0;k<4;k++){ |
---|
548 | for(int l=0;l<4;l++){ |
---|
549 | //rows-columns |
---|
550 | for(int i=1; i<4; i++) |
---|
551 | { |
---|
552 | if(this->board[i][i][k][l]==mini4DgamePlayerColor::none || this->board[0][0][k][l] != this->board[i][i][k][l]) |
---|
553 | break; |
---|
554 | if(i==3) |
---|
555 | { |
---|
556 | winner.color_ = this->board[0][0][k][l]; |
---|
557 | for(int x=0; x<4; x++){ |
---|
558 | winner.winningRow[x] = x; |
---|
559 | winner.winningColumn[x] = x; |
---|
560 | winner.winningHeight[x] = k; |
---|
561 | winner.winningNumber[x] = l; |
---|
562 | } |
---|
563 | return winner; |
---|
564 | } |
---|
565 | } |
---|
566 | for(int i=1; i<4; i++) |
---|
567 | { |
---|
568 | if(this->board[3-i][i][k][l]==mini4DgamePlayerColor::none || this->board[3][0][k][l] != this->board[3-i][i][k][l]) |
---|
569 | break; |
---|
570 | if(i==3) |
---|
571 | { |
---|
572 | winner.color_ = this->board[3][0][k][l]; |
---|
573 | for(int x=0; x<4; x++){ |
---|
574 | winner.winningRow[x] = 3-x; |
---|
575 | winner.winningColumn[x] = x; |
---|
576 | winner.winningHeight[x] = k; |
---|
577 | winner.winningNumber[x] = l; |
---|
578 | } |
---|
579 | return winner; |
---|
580 | } |
---|
581 | } |
---|
582 | //rows-height |
---|
583 | for(int i=1; i<4; i++) |
---|
584 | { |
---|
585 | if(this->board[i][k][i][l]==mini4DgamePlayerColor::none || this->board[0][k][0][l] != this->board[i][k][i][l]) |
---|
586 | break; |
---|
587 | if(i==3) |
---|
588 | { |
---|
589 | winner.color_ = this->board[0][k][0][l]; |
---|
590 | for(int x=0; x<4; x++){ |
---|
591 | winner.winningRow[x] = x; |
---|
592 | winner.winningColumn[x] = k; |
---|
593 | winner.winningHeight[x] = x; |
---|
594 | winner.winningNumber[x] = l; |
---|
595 | } |
---|
596 | return winner; |
---|
597 | } |
---|
598 | } |
---|
599 | for(int i=1; i<4; i++) |
---|
600 | { |
---|
601 | if(this->board[3-i][k][i][l]==mini4DgamePlayerColor::none || this->board[3][k][0][l] != this->board[3-i][k][i][l]) |
---|
602 | break; |
---|
603 | if(i==3) |
---|
604 | { |
---|
605 | winner.color_ = this->board[3][k][0][l]; |
---|
606 | for(int x=0; x<4; x++){ |
---|
607 | winner.winningRow[x] = 3-x; |
---|
608 | winner.winningColumn[x] = k; |
---|
609 | winner.winningHeight[x] = x; |
---|
610 | winner.winningNumber[x] = l; |
---|
611 | } |
---|
612 | return winner; |
---|
613 | } |
---|
614 | } |
---|
615 | //rows-numbers |
---|
616 | for(int i=1; i<4; i++) |
---|
617 | { |
---|
618 | if(this->board[i][k][l][i]==mini4DgamePlayerColor::none || this->board[0][k][l][0] != this->board[i][k][l][i]) |
---|
619 | break; |
---|
620 | if(i==3) |
---|
621 | { |
---|
622 | winner.color_ = this->board[0][k][l][0]; |
---|
623 | for(int x=0; x<4; x++){ |
---|
624 | winner.winningRow[x] = x; |
---|
625 | winner.winningColumn[x] = k; |
---|
626 | winner.winningHeight[x] = l; |
---|
627 | winner.winningNumber[x] = x; |
---|
628 | } |
---|
629 | return winner; |
---|
630 | } |
---|
631 | } |
---|
632 | for(int i=1; i<4; i++) |
---|
633 | { |
---|
634 | if(this->board[3-i][k][l][i]==mini4DgamePlayerColor::none || this->board[3][k][l][0] != this->board[3-i][k][l][i]) |
---|
635 | break; |
---|
636 | if(i==3) |
---|
637 | { |
---|
638 | winner.color_ = this->board[3][k][l][0]; |
---|
639 | for(int x=0; x<4; x++){ |
---|
640 | winner.winningRow[x] = 3-x; |
---|
641 | winner.winningColumn[x] = k; |
---|
642 | winner.winningHeight[x] = l; |
---|
643 | winner.winningNumber[x] = x; |
---|
644 | } |
---|
645 | return winner; |
---|
646 | } |
---|
647 | } |
---|
648 | //column-height |
---|
649 | for(int i=1; i<4; i++) |
---|
650 | { |
---|
651 | if(this->board[k][i][i][l]==mini4DgamePlayerColor::none || this->board[k][0][0][l] != this->board[k][i][i][l]) |
---|
652 | break; |
---|
653 | if(i==3) |
---|
654 | { |
---|
655 | winner.color_ = this->board[k][0][0][l]; |
---|
656 | for(int x=0; x<4; x++){ |
---|
657 | winner.winningRow[x] = k; |
---|
658 | winner.winningColumn[x] = x; |
---|
659 | winner.winningHeight[x] = x; |
---|
660 | winner.winningNumber[x] = l; |
---|
661 | } |
---|
662 | return winner; |
---|
663 | } |
---|
664 | } |
---|
665 | for(int i=1; i<4; i++) |
---|
666 | { |
---|
667 | if(this->board[k][3-i][i][l]==mini4DgamePlayerColor::none || this->board[k][3][0][l] != this->board[k][3-i][i][l]) |
---|
668 | break; |
---|
669 | if(i==3) |
---|
670 | { |
---|
671 | winner.color_ = this->board[k][3][0][l]; |
---|
672 | for(int x=0; x<4; x++){ |
---|
673 | winner.winningRow[x] = k; |
---|
674 | winner.winningColumn[x] = 3-x; |
---|
675 | winner.winningHeight[x] = x; |
---|
676 | winner.winningNumber[x] = l; |
---|
677 | } |
---|
678 | return winner; |
---|
679 | } |
---|
680 | } |
---|
681 | //column-numbers |
---|
682 | for(int i=1; i<4; i++) |
---|
683 | { |
---|
684 | if(this->board[k][i][l][i]==mini4DgamePlayerColor::none || this->board[k][0][l][0] != this->board[k][i][l][i]) |
---|
685 | break; |
---|
686 | if(i==3) |
---|
687 | { |
---|
688 | winner.color_ = this->board[k][0][l][0]; |
---|
689 | for(int x=0; x<4; x++){ |
---|
690 | winner.winningRow[x] = k; |
---|
691 | winner.winningColumn[x] = x; |
---|
692 | winner.winningHeight[x] = l; |
---|
693 | winner.winningNumber[x] = x; |
---|
694 | } |
---|
695 | return winner; |
---|
696 | } |
---|
697 | } |
---|
698 | for(int i=1; i<4; i++) |
---|
699 | { |
---|
700 | if(this->board[k][3-i][l][i]==mini4DgamePlayerColor::none || this->board[k][3][l][0] != this->board[k][3-i][l][i]) |
---|
701 | break; |
---|
702 | if(i==3) |
---|
703 | { |
---|
704 | winner.color_ = this->board[k][3][l][0]; |
---|
705 | for(int x=0; x<4; x++){ |
---|
706 | winner.winningRow[x] = k; |
---|
707 | winner.winningColumn[x] = 3-x; |
---|
708 | winner.winningHeight[x] = l; |
---|
709 | winner.winningNumber[x] = x; |
---|
710 | } |
---|
711 | return winner; |
---|
712 | } |
---|
713 | } |
---|
714 | //height-numbers |
---|
715 | for(int i=1; i<4; i++) |
---|
716 | { |
---|
717 | if(this->board[k][l][i][i]==mini4DgamePlayerColor::none || this->board[k][l][0][0] != this->board[k][l][i][i]) |
---|
718 | break; |
---|
719 | if(i==3) |
---|
720 | { |
---|
721 | winner.color_ = this->board[k][l][0][0]; |
---|
722 | for(int x=0; x<4; x++){ |
---|
723 | winner.winningRow[x] = k; |
---|
724 | winner.winningColumn[x] = l; |
---|
725 | winner.winningHeight[x] = x; |
---|
726 | winner.winningNumber[x] = x; |
---|
727 | } |
---|
728 | return winner; |
---|
729 | } |
---|
730 | } |
---|
731 | for(int i=1; i<4; i++) |
---|
732 | { |
---|
733 | if(this->board[k][l][3-i][i]==mini4DgamePlayerColor::none || this->board[k][l][3][0] != this->board[k][l][3-i][i]) |
---|
734 | break; |
---|
735 | if(i==3) |
---|
736 | { |
---|
737 | winner.color_ = this->board[k][l][3][0]; |
---|
738 | for(int x=0; x<4; x++){ |
---|
739 | winner.winningRow[x] = k; |
---|
740 | winner.winningColumn[x] = l; |
---|
741 | winner.winningHeight[x] = 3-x; |
---|
742 | winner.winningNumber[x] = x; |
---|
743 | } |
---|
744 | return winner; |
---|
745 | } |
---|
746 | } |
---|
747 | } |
---|
748 | } |
---|
749 | |
---|
750 | //check rows |
---|
751 | for(int j=0;j<4;j++){ |
---|
752 | for(int k=0;k<4;k++){ |
---|
753 | for(int l=0;l<4;l++){ |
---|
754 | if(this->board[0][j][k][l]!= mini4DgamePlayerColor::none |
---|
755 | && this->board[0][j][k][l]==this->board[1][j][k][l] |
---|
756 | && this->board[1][j][k][l]==this->board[2][j][k][l] |
---|
757 | && this->board[2][j][k][l]==this->board[3][j][k][l]) |
---|
758 | { |
---|
759 | winner.color_ = this->board[0][j][k][l]; |
---|
760 | for(int x=0; x<4; x++){ |
---|
761 | winner.winningRow[x] = x; |
---|
762 | winner.winningColumn[x] = j; |
---|
763 | winner.winningHeight[x] = k; |
---|
764 | winner.winningNumber[x] = l; |
---|
765 | } |
---|
766 | return winner; |
---|
767 | } |
---|
768 | } |
---|
769 | } |
---|
770 | } |
---|
771 | |
---|
772 | //check columns |
---|
773 | for(int i=0;i<4;i++){ |
---|
774 | for(int k=0;k<4;k++){ |
---|
775 | for(int l=0;l<4;l++){ |
---|
776 | if(this->board[i][0][k][l]!= mini4DgamePlayerColor::none |
---|
777 | && this->board[i][0][k][l]==this->board[i][1][k][l] |
---|
778 | && this->board[i][1][k][l]==this->board[i][2][k][l] |
---|
779 | && this->board[i][2][k][l]==this->board[i][3][k][l]) |
---|
780 | { |
---|
781 | winner.color_ = this->board[i][0][k][l]; |
---|
782 | for(int x=0; x<4; x++){ |
---|
783 | winner.winningRow[x] = i; |
---|
784 | winner.winningColumn[x] = x; |
---|
785 | winner.winningHeight[x] = k; |
---|
786 | winner.winningNumber[x] = l; |
---|
787 | } |
---|
788 | return winner; |
---|
789 | } |
---|
790 | } |
---|
791 | } |
---|
792 | } |
---|
793 | |
---|
794 | //check height |
---|
795 | for(int i=0;i<4;i++){ |
---|
796 | for(int j=0;j<4;j++){ |
---|
797 | for(int l=0;l<4;l++){ |
---|
798 | if(this->board[i][j][0][l]!= mini4DgamePlayerColor::none |
---|
799 | && this->board[i][j][0][l]==this->board[i][j][1][l] |
---|
800 | && this->board[i][j][1][l]==this->board[i][j][2][l] |
---|
801 | && this->board[i][j][2][l]==this->board[i][j][3][l]) |
---|
802 | { |
---|
803 | winner.color_ = this->board[i][j][0][l]; |
---|
804 | for(int x=0; x<4; x++){ |
---|
805 | winner.winningRow[x] = i; |
---|
806 | winner.winningColumn[x] = j; |
---|
807 | winner.winningHeight[x] = x; |
---|
808 | winner.winningNumber[x] = l; |
---|
809 | } |
---|
810 | return winner; |
---|
811 | } |
---|
812 | } |
---|
813 | } |
---|
814 | } |
---|
815 | |
---|
816 | //check numbers |
---|
817 | for(int i=0;i<4;i++){ |
---|
818 | for(int j=0;j<4;j++){ |
---|
819 | for(int k=0;k<4;k++){ |
---|
820 | if(this->board[i][j][k][0]!= mini4DgamePlayerColor::none |
---|
821 | && this->board[i][j][k][0]==this->board[i][j][k][1] |
---|
822 | && this->board[i][j][k][1]==this->board[i][j][k][2] |
---|
823 | && this->board[i][j][k][2]==this->board[i][j][k][3]) |
---|
824 | { |
---|
825 | winner.color_ = this->board[i][j][k][0]; |
---|
826 | for(int x=0; x<4; x++){ |
---|
827 | winner.winningRow[x] = i; |
---|
828 | winner.winningColumn[x] = j; |
---|
829 | winner.winningHeight[x] = k; |
---|
830 | winner.winningNumber[x] = x; |
---|
831 | } |
---|
832 | return winner; |
---|
833 | } |
---|
834 | } |
---|
835 | } |
---|
836 | } |
---|
837 | return winner; |
---|
838 | } |
---|
839 | } |
---|