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 | #include "graphics/BlinkingBillboard.h" |
---|
41 | |
---|
42 | #include "Mini4Dgame.h" |
---|
43 | |
---|
44 | namespace orxonox |
---|
45 | { |
---|
46 | RegisterClass(Mini4DgameBoard); |
---|
47 | |
---|
48 | /** |
---|
49 | @brief |
---|
50 | Constructor. Registers and initializes the object. |
---|
51 | */ |
---|
52 | Mini4DgameBoard::Mini4DgameBoard(Context* context) : StaticEntity(context) |
---|
53 | { |
---|
54 | RegisterObject(Mini4DgameBoard); |
---|
55 | |
---|
56 | //this->registerVariables(); |
---|
57 | |
---|
58 | //initialize board |
---|
59 | for(int i=0;i<4;i++){ |
---|
60 | for(int j=0;j<4;j++){ |
---|
61 | for(int k=0;k<4;k++){ |
---|
62 | for(int l=0;l<4;l++){ |
---|
63 | this->board[i][j][k][l]=Mini4DgamePlayerColor::none; |
---|
64 | this->blinkingBillboards[i][j][k][l] = nullptr; |
---|
65 | } |
---|
66 | } |
---|
67 | } |
---|
68 | } |
---|
69 | this->player_toggle_ = false; |
---|
70 | this->checkGametype(); |
---|
71 | } |
---|
72 | |
---|
73 | /** |
---|
74 | @brief Checks if the move is valid |
---|
75 | @param move The position where to put the stone |
---|
76 | */ |
---|
77 | bool Mini4DgameBoard::isValidMove(const Mini4DgamePosition& move) |
---|
78 | { |
---|
79 | return (move.x<4 && move.y<4 && move.z<4 && move.w<4 |
---|
80 | && move.x>=0 && move.y>=0 && move.z>=0 && move.w>=0 |
---|
81 | && this->board[move.x][move.y][move.z][move.w] == Mini4DgamePlayerColor::none); |
---|
82 | } |
---|
83 | |
---|
84 | void Mini4DgameBoard::undoMove() |
---|
85 | { |
---|
86 | const Mini4DgamePosition& move = moves.back(); |
---|
87 | moves.pop_back(); |
---|
88 | this->board[move.x][move.y][move.z][move.w] = Mini4DgamePlayerColor::none; |
---|
89 | this->blinkingBillboards[move.x][move.y][move.z][move.w]->destroy(); |
---|
90 | this->blinkingBillboards[move.x][move.y][move.z][move.w] = nullptr; |
---|
91 | if(player_toggle_){ |
---|
92 | this->player_toggle_ = false; |
---|
93 | }else{ |
---|
94 | this->player_toggle_ = true; |
---|
95 | } |
---|
96 | } |
---|
97 | |
---|
98 | /** |
---|
99 | @brief makes a move on the logic playboard |
---|
100 | @param move The position where to put the stone |
---|
101 | */ |
---|
102 | void Mini4DgameBoard::makeMove(const Mini4DgamePosition& move) |
---|
103 | { |
---|
104 | if(this->isValidMove(move)) |
---|
105 | { |
---|
106 | if(!moves.empty()) |
---|
107 | { |
---|
108 | //stop blinking of last move |
---|
109 | const Mini4DgamePosition& lastMove = moves.back(); |
---|
110 | this->blinkingBillboards[lastMove.x][lastMove.y][lastMove.z][lastMove.w] |
---|
111 | ->setActive(false); |
---|
112 | this->blinkingBillboards[lastMove.x][lastMove.y][lastMove.z][lastMove.w] |
---|
113 | ->setScale(0.1); |
---|
114 | } |
---|
115 | |
---|
116 | moves.push_back(move); |
---|
117 | Mini4DgamePlayerColor playerColor = Mini4DgamePlayerColor::none; |
---|
118 | if(player_toggle_){ |
---|
119 | playerColor = Mini4DgamePlayerColor::blue; |
---|
120 | this->player_toggle_ = false; |
---|
121 | }else{ |
---|
122 | playerColor = Mini4DgamePlayerColor::green; |
---|
123 | this->player_toggle_ = true; |
---|
124 | } |
---|
125 | |
---|
126 | this->board[move.x][move.y][move.z][move.w] = playerColor; |
---|
127 | |
---|
128 | BlinkingBillboard* bb = new BlinkingBillboard(this->getContext()); |
---|
129 | bb->setFrequency(0.3); |
---|
130 | bb->setAmplitude(0.1); |
---|
131 | |
---|
132 | switch(move.w){ |
---|
133 | case 0: bb->setMaterial("Numbers/One"); |
---|
134 | bb->setPosition(60.0f*move.x-95,60.0f*move.y-95,60.0f*move.z-95); |
---|
135 | break; |
---|
136 | case 1: bb->setMaterial("Numbers/Two"); |
---|
137 | bb->setPosition(60.0f*move.x-85,60.0f*move.y-85,60.0f*move.z-95); |
---|
138 | break; |
---|
139 | case 2: bb->setMaterial("Numbers/Three"); |
---|
140 | bb->setPosition(60.0f*move.x-85,60.0f*move.y-95,60.0f*move.z-85); |
---|
141 | break; |
---|
142 | case 3: bb->setMaterial("Numbers/Four"); |
---|
143 | bb->setPosition(60.0f*move.x-85,60.0f*move.y-85,60.0f*move.z-85); |
---|
144 | break; |
---|
145 | } |
---|
146 | |
---|
147 | switch(playerColor){ |
---|
148 | case Mini4DgamePlayerColor::red: |
---|
149 | bb->setColour(ColourValue(1,0,0)); break; |
---|
150 | case Mini4DgamePlayerColor::green: |
---|
151 | bb->setColour(ColourValue(0,1,0)); break; |
---|
152 | case Mini4DgamePlayerColor::blue: |
---|
153 | bb->setColour(ColourValue(0,0,1)); break; |
---|
154 | default: break; |
---|
155 | } |
---|
156 | |
---|
157 | this->attach(bb); |
---|
158 | this->blinkingBillboards[move.x][move.y][move.z][move.w] = bb; |
---|
159 | |
---|
160 | |
---|
161 | Mini4DgameWinner winner = this->getWinner(); |
---|
162 | if(winner.color_ != Mini4DgamePlayerColor::none) |
---|
163 | { |
---|
164 | orxout(user_status) << "Mini4Dgame: win!!!!!!!" << endl; |
---|
165 | for(int i=0;i<4;i++){ |
---|
166 | BlinkingBillboard* redFlare = new BlinkingBillboard(this->getContext()); |
---|
167 | redFlare->setFrequency(0.5); |
---|
168 | redFlare->setAmplitude(3); |
---|
169 | redFlare->setPosition(60.0f*(int)winner.winningRow[i]-90, |
---|
170 | 60.0f*(int)winner.winningColumn[i]-90, |
---|
171 | 60.0f*(int)winner.winningHeight[i]-90); |
---|
172 | redFlare->setMaterial("Flares/lensflare"); |
---|
173 | redFlare->setColour(ColourValue(1,0,0)); |
---|
174 | this->attach(redFlare); |
---|
175 | BlinkingBillboard* bb = this->blinkingBillboards[winner.winningRow[i]] |
---|
176 | [winner.winningColumn[i]] |
---|
177 | [winner.winningHeight[i]] |
---|
178 | [winner.winningNumber[i]]; |
---|
179 | bb->setActive(true);//start blinking |
---|
180 | } |
---|
181 | } |
---|
182 | }else{ |
---|
183 | orxout(internal_error) << "Mini4Dgame: not a valid move"<< endl; |
---|
184 | } |
---|
185 | } |
---|
186 | |
---|
187 | Mini4DgameWinner Mini4DgameBoard::getWinner() |
---|
188 | { |
---|
189 | Mini4DgameWinner winner; |
---|
190 | winner.color_ = Mini4DgamePlayerColor::none; |
---|
191 | |
---|
192 | //check diagonals rows-columns-height-numbers |
---|
193 | for(int i=1; i<4; i++) |
---|
194 | { |
---|
195 | if(this->board[i][i][i][i]==Mini4DgamePlayerColor::none || this->board[0][0][0][0] != this->board[i][i][i][i]) |
---|
196 | break; |
---|
197 | if(i==3) |
---|
198 | { |
---|
199 | winner.color_ = this->board[0][0][0][0]; |
---|
200 | for(int x=0; x<4; x++){ |
---|
201 | winner.winningRow[x] = x; |
---|
202 | winner.winningColumn[x] = x; |
---|
203 | winner.winningHeight[x] = x; |
---|
204 | winner.winningNumber[x] = x; |
---|
205 | } |
---|
206 | return winner; |
---|
207 | } |
---|
208 | } |
---|
209 | for(int i=1; i<4; i++) |
---|
210 | { |
---|
211 | if(this->board[3-i][i][i][i]==Mini4DgamePlayerColor::none || this->board[3][0][0][0] != this->board[3-i][i][i][i]) |
---|
212 | break; |
---|
213 | if(i==3) |
---|
214 | { |
---|
215 | winner.color_ = this->board[3][0][0][0]; |
---|
216 | for(int x=0; x<4; x++){ |
---|
217 | winner.winningRow[x] = 3-x; |
---|
218 | winner.winningColumn[x] = x; |
---|
219 | winner.winningHeight[x] = x; |
---|
220 | winner.winningNumber[x] = x; |
---|
221 | } |
---|
222 | return winner; |
---|
223 | } |
---|
224 | } |
---|
225 | for(int i=1; i<4; i++) |
---|
226 | { |
---|
227 | if(this->board[i][3-i][i][i]==Mini4DgamePlayerColor::none || this->board[0][3][0][0] != this->board[i][3-i][i][i]) |
---|
228 | break; |
---|
229 | if(i==3) |
---|
230 | { |
---|
231 | winner.color_ = this->board[0][3][0][0]; |
---|
232 | for(int x=0; x<4; x++){ |
---|
233 | winner.winningRow[x] = x; |
---|
234 | winner.winningColumn[x] = 3-x; |
---|
235 | winner.winningHeight[x] = x; |
---|
236 | winner.winningNumber[x] = x; |
---|
237 | } |
---|
238 | return winner; |
---|
239 | } |
---|
240 | } |
---|
241 | for(int i=1; i<4; i++) |
---|
242 | { |
---|
243 | if(this->board[i][i][3-i][i]==Mini4DgamePlayerColor::none || this->board[0][0][3][0] != this->board[i][i][3-i][i]) |
---|
244 | break; |
---|
245 | if(i==3) |
---|
246 | { |
---|
247 | winner.color_ = this->board[0][0][3][0]; |
---|
248 | for(int x=0; x<4; x++){ |
---|
249 | winner.winningRow[x] = x; |
---|
250 | winner.winningColumn[x] = x; |
---|
251 | winner.winningHeight[x] = 3-x; |
---|
252 | winner.winningNumber[x] = x; |
---|
253 | } |
---|
254 | return winner; |
---|
255 | } |
---|
256 | } |
---|
257 | for(int i=1; i<4; i++) |
---|
258 | { |
---|
259 | if(this->board[i][i][i][3-i]==Mini4DgamePlayerColor::none || this->board[0][0][0][3] != this->board[i][i][i][3-i]) |
---|
260 | break; |
---|
261 | if(i==3) |
---|
262 | { |
---|
263 | winner.color_ = this->board[0][0][0][3]; |
---|
264 | for(int x=0; x<4; x++){ |
---|
265 | winner.winningRow[x] = x; |
---|
266 | winner.winningColumn[x] = x; |
---|
267 | winner.winningHeight[x] = x; |
---|
268 | winner.winningNumber[x] = 3-x; |
---|
269 | } |
---|
270 | return winner; |
---|
271 | } |
---|
272 | } |
---|
273 | for(int i=1; i<4; i++) |
---|
274 | { |
---|
275 | 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]) |
---|
276 | break; |
---|
277 | if(i==3) |
---|
278 | { |
---|
279 | winner.color_ = this->board[3][3][0][0]; |
---|
280 | for(int x=0; x<4; x++){ |
---|
281 | winner.winningRow[x] = 3-x; |
---|
282 | winner.winningColumn[x] = 3-x; |
---|
283 | winner.winningHeight[x] = x; |
---|
284 | winner.winningNumber[x] = x; |
---|
285 | } |
---|
286 | return winner; |
---|
287 | } |
---|
288 | } |
---|
289 | for(int i=1; i<4; i++) |
---|
290 | { |
---|
291 | 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]) |
---|
292 | break; |
---|
293 | if(i==3) |
---|
294 | { |
---|
295 | winner.color_ = this->board[3][0][3][0]; |
---|
296 | for(int x=0; x<4; x++){ |
---|
297 | winner.winningRow[x] = 3-x; |
---|
298 | winner.winningColumn[x] = x; |
---|
299 | winner.winningHeight[x] = 3-x; |
---|
300 | winner.winningNumber[x] = x; |
---|
301 | } |
---|
302 | return winner; |
---|
303 | } |
---|
304 | } |
---|
305 | for(int i=1; i<4; i++) |
---|
306 | { |
---|
307 | 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]) |
---|
308 | break; |
---|
309 | if(i==3) |
---|
310 | { |
---|
311 | winner.color_ = this->board[3][0][0][3]; |
---|
312 | for(int x=0; x<4; x++){ |
---|
313 | winner.winningRow[x] = 3-x; |
---|
314 | winner.winningColumn[x] = x; |
---|
315 | winner.winningHeight[x] = x; |
---|
316 | winner.winningNumber[x] = 3-x; |
---|
317 | } |
---|
318 | return winner; |
---|
319 | } |
---|
320 | } |
---|
321 | |
---|
322 | //check diagonals rows-columns-height |
---|
323 | for(int l=0; l<4; l++) |
---|
324 | { |
---|
325 | for(int i=1; i<4; i++) |
---|
326 | { |
---|
327 | if(this->board[i][i][i][l]==Mini4DgamePlayerColor::none || this->board[0][0][0][l] != this->board[i][i][i][l]) |
---|
328 | break; |
---|
329 | if(i==3) |
---|
330 | { |
---|
331 | winner.color_ = this->board[0][0][0][l]; |
---|
332 | for(int x=0; x<4; x++){ |
---|
333 | winner.winningRow[x] = x; |
---|
334 | winner.winningColumn[x] = x; |
---|
335 | winner.winningHeight[x] = x; |
---|
336 | winner.winningNumber[x] = l; |
---|
337 | } |
---|
338 | return winner; |
---|
339 | } |
---|
340 | } |
---|
341 | for(int i=1; i<4; i++) |
---|
342 | { |
---|
343 | if(this->board[3-i][i][i][l]==Mini4DgamePlayerColor::none || this->board[3][0][0][l] != this->board[3-i][i][i][l]) |
---|
344 | break; |
---|
345 | if(i==3) |
---|
346 | { |
---|
347 | winner.color_ = this->board[3][0][0][l]; |
---|
348 | for(int x=0; x<4; x++){ |
---|
349 | winner.winningRow[x] = 3-x; |
---|
350 | winner.winningColumn[x] = x; |
---|
351 | winner.winningHeight[x] = x; |
---|
352 | winner.winningNumber[x] = l; |
---|
353 | } |
---|
354 | return winner; |
---|
355 | } |
---|
356 | } |
---|
357 | for(int i=1; i<4; i++) |
---|
358 | { |
---|
359 | if(this->board[i][3-i][i][l]==Mini4DgamePlayerColor::none || this->board[0][3][0][l] != this->board[i][3-i][i][l]) |
---|
360 | break; |
---|
361 | if(i==3) |
---|
362 | { |
---|
363 | winner.color_ = this->board[0][3][0][l]; |
---|
364 | for(int x=0; x<4; x++){ |
---|
365 | winner.winningRow[x] = x; |
---|
366 | winner.winningColumn[x] = 3-x; |
---|
367 | winner.winningHeight[x] = x; |
---|
368 | winner.winningNumber[x] = l; |
---|
369 | } |
---|
370 | return winner; |
---|
371 | } |
---|
372 | } |
---|
373 | for(int i=1; i<4; i++) |
---|
374 | { |
---|
375 | if(this->board[i][i][3-i][l]==Mini4DgamePlayerColor::none || this->board[0][0][3][l] != this->board[i][i][3-i][l]) |
---|
376 | break; |
---|
377 | if(i==3) |
---|
378 | { |
---|
379 | winner.color_ = this->board[0][0][3][l]; |
---|
380 | for(int x=0; x<4; x++){ |
---|
381 | winner.winningRow[x] = x; |
---|
382 | winner.winningColumn[x] = x; |
---|
383 | winner.winningHeight[x] = 3-x; |
---|
384 | winner.winningNumber[x] = l; |
---|
385 | } |
---|
386 | return winner; |
---|
387 | } |
---|
388 | } |
---|
389 | } |
---|
390 | |
---|
391 | //check diagonals rows-columns-numbers |
---|
392 | for(int l=0; l<4; l++) |
---|
393 | { |
---|
394 | for(int i=1; i<4; i++) |
---|
395 | { |
---|
396 | if(this->board[i][i][l][i]==Mini4DgamePlayerColor::none || this->board[0][0][l][0] != this->board[i][i][l][i]) |
---|
397 | break; |
---|
398 | if(i==3) |
---|
399 | { |
---|
400 | winner.color_ = this->board[0][0][l][0]; |
---|
401 | for(int x=0; x<4; x++){ |
---|
402 | winner.winningRow[x] = x; |
---|
403 | winner.winningColumn[x] = x; |
---|
404 | winner.winningHeight[x] = l; |
---|
405 | winner.winningNumber[x] = x; |
---|
406 | } |
---|
407 | return winner; |
---|
408 | } |
---|
409 | } |
---|
410 | for(int i=1; i<4; i++) |
---|
411 | { |
---|
412 | if(this->board[3-i][i][l][i]==Mini4DgamePlayerColor::none || this->board[3][0][l][0] != this->board[3-i][i][l][i]) |
---|
413 | break; |
---|
414 | if(i==3) |
---|
415 | { |
---|
416 | winner.color_ = this->board[3][0][l][0]; |
---|
417 | for(int x=0; x<4; x++){ |
---|
418 | winner.winningRow[x] = 3-x; |
---|
419 | winner.winningColumn[x] = x; |
---|
420 | winner.winningHeight[x] = l; |
---|
421 | winner.winningNumber[x] = x; |
---|
422 | } |
---|
423 | return winner; |
---|
424 | } |
---|
425 | } |
---|
426 | for(int i=1; i<4; i++) |
---|
427 | { |
---|
428 | if(this->board[i][3-i][l][i]==Mini4DgamePlayerColor::none || this->board[0][3][l][0] != this->board[i][3-i][l][i]) |
---|
429 | break; |
---|
430 | if(i==3) |
---|
431 | { |
---|
432 | winner.color_ = this->board[0][3][l][0]; |
---|
433 | for(int x=0; x<4; x++){ |
---|
434 | winner.winningRow[x] = x; |
---|
435 | winner.winningColumn[x] = 3-x; |
---|
436 | winner.winningHeight[x] = l; |
---|
437 | winner.winningNumber[x] = x; |
---|
438 | } |
---|
439 | return winner; |
---|
440 | } |
---|
441 | } |
---|
442 | for(int i=1; i<4; i++) |
---|
443 | { |
---|
444 | if(this->board[i][i][l][3-i]==Mini4DgamePlayerColor::none || this->board[0][0][l][3] != this->board[i][i][l][3-i]) |
---|
445 | break; |
---|
446 | if(i==3) |
---|
447 | { |
---|
448 | winner.color_ = this->board[0][0][l][3]; |
---|
449 | for(int x=0; x<4; x++){ |
---|
450 | winner.winningRow[x] = x; |
---|
451 | winner.winningColumn[x] = x; |
---|
452 | winner.winningHeight[x] = l; |
---|
453 | winner.winningNumber[x] = 3-x; |
---|
454 | } |
---|
455 | return winner; |
---|
456 | } |
---|
457 | } |
---|
458 | } |
---|
459 | |
---|
460 | //check diagonals rows-height-numbers |
---|
461 | for(int l=0; l<4; l++) |
---|
462 | { |
---|
463 | for(int i=1; i<4; i++) |
---|
464 | { |
---|
465 | if(this->board[i][l][i][i]==Mini4DgamePlayerColor::none || this->board[0][l][0][0] != this->board[i][l][i][i]) |
---|
466 | break; |
---|
467 | if(i==3) |
---|
468 | { |
---|
469 | winner.color_ = this->board[0][l][0][0]; |
---|
470 | for(int x=0; x<4; x++){ |
---|
471 | winner.winningRow[x] = x; |
---|
472 | winner.winningColumn[x] = l; |
---|
473 | winner.winningHeight[x] = x; |
---|
474 | winner.winningNumber[x] = x; |
---|
475 | } |
---|
476 | return winner; |
---|
477 | } |
---|
478 | } |
---|
479 | for(int i=1; i<4; i++) |
---|
480 | { |
---|
481 | if(this->board[3-i][l][i][i]==Mini4DgamePlayerColor::none || this->board[3][l][0][0] != this->board[3-i][l][i][i]) |
---|
482 | break; |
---|
483 | if(i==3) |
---|
484 | { |
---|
485 | winner.color_ = this->board[3][l][0][0]; |
---|
486 | for(int x=0; x<4; x++){ |
---|
487 | winner.winningRow[x] = 3-x; |
---|
488 | winner.winningColumn[x] = l; |
---|
489 | winner.winningHeight[x] = x; |
---|
490 | winner.winningNumber[x] = x; |
---|
491 | } |
---|
492 | return winner; |
---|
493 | } |
---|
494 | } |
---|
495 | for(int i=1; i<4; i++) |
---|
496 | { |
---|
497 | if(this->board[i][l][3-i][i]==Mini4DgamePlayerColor::none || this->board[0][l][3][0] != this->board[i][l][3-i][i]) |
---|
498 | break; |
---|
499 | if(i==3) |
---|
500 | { |
---|
501 | winner.color_ = this->board[0][l][3][0]; |
---|
502 | for(int x=0; x<4; x++){ |
---|
503 | winner.winningRow[x] = x; |
---|
504 | winner.winningColumn[x] = l; |
---|
505 | winner.winningHeight[x] = 3-x; |
---|
506 | winner.winningNumber[x] = x; |
---|
507 | } |
---|
508 | return winner; |
---|
509 | } |
---|
510 | } |
---|
511 | for(int i=1; i<4; i++) |
---|
512 | { |
---|
513 | if(this->board[i][l][i][3-i]==Mini4DgamePlayerColor::none || this->board[0][l][0][3] != this->board[i][l][i][3-i]) |
---|
514 | break; |
---|
515 | if(i==3) |
---|
516 | { |
---|
517 | winner.color_ = this->board[0][l][0][3]; |
---|
518 | for(int x=0; x<4; x++){ |
---|
519 | winner.winningRow[x] = x; |
---|
520 | winner.winningColumn[x] = l; |
---|
521 | winner.winningHeight[x] = x; |
---|
522 | winner.winningNumber[x] = 3-x; |
---|
523 | } |
---|
524 | return winner; |
---|
525 | } |
---|
526 | } |
---|
527 | } |
---|
528 | |
---|
529 | //check diagonals columns-height-numbers |
---|
530 | for(int l=0; l<4; l++) |
---|
531 | { |
---|
532 | for(int i=1; i<4; i++) |
---|
533 | { |
---|
534 | if(this->board[l][i][i][i]==Mini4DgamePlayerColor::none || this->board[l][0][0][0] != this->board[l][i][i][i]) |
---|
535 | break; |
---|
536 | if(i==3) |
---|
537 | { |
---|
538 | winner.color_ = this->board[l][0][0][0]; |
---|
539 | for(int x=0; x<4; x++){ |
---|
540 | winner.winningRow[x] = l; |
---|
541 | winner.winningColumn[x] = x; |
---|
542 | winner.winningHeight[x] = x; |
---|
543 | winner.winningNumber[x] = x; |
---|
544 | } |
---|
545 | return winner; |
---|
546 | } |
---|
547 | } |
---|
548 | for(int i=1; i<4; i++) |
---|
549 | { |
---|
550 | if(this->board[l][3-i][i][i]==Mini4DgamePlayerColor::none || this->board[l][3][0][0] != this->board[l][3-i][i][i]) |
---|
551 | break; |
---|
552 | if(i==3) |
---|
553 | { |
---|
554 | winner.color_ = this->board[l][3][0][0]; |
---|
555 | for(int x=0; x<4; x++){ |
---|
556 | winner.winningRow[x] = l; |
---|
557 | winner.winningColumn[x] = 3-x; |
---|
558 | winner.winningHeight[x] = x; |
---|
559 | winner.winningNumber[x] = x; |
---|
560 | } |
---|
561 | return winner; |
---|
562 | } |
---|
563 | } |
---|
564 | for(int i=1; i<4; i++) |
---|
565 | { |
---|
566 | if(this->board[l][i][3-i][i]==Mini4DgamePlayerColor::none || this->board[l][0][3][0] != this->board[l][i][3-i][i]) |
---|
567 | break; |
---|
568 | if(i==3) |
---|
569 | { |
---|
570 | winner.color_ = this->board[l][0][3][0]; |
---|
571 | for(int x=0; x<4; x++){ |
---|
572 | winner.winningRow[x] = l; |
---|
573 | winner.winningColumn[x] = x; |
---|
574 | winner.winningHeight[x] = 3-x; |
---|
575 | winner.winningNumber[x] = x; |
---|
576 | } |
---|
577 | return winner; |
---|
578 | } |
---|
579 | } |
---|
580 | for(int i=1; i<4; i++) |
---|
581 | { |
---|
582 | if(this->board[l][i][i][3-i]==Mini4DgamePlayerColor::none || this->board[l][0][0][3] != this->board[l][i][i][3-i]) |
---|
583 | break; |
---|
584 | if(i==3) |
---|
585 | { |
---|
586 | winner.color_ = this->board[l][0][0][3]; |
---|
587 | for(int x=0; x<4; x++){ |
---|
588 | winner.winningRow[x] = l; |
---|
589 | winner.winningColumn[x] = x; |
---|
590 | winner.winningHeight[x] = x; |
---|
591 | winner.winningNumber[x] = 3-x; |
---|
592 | } |
---|
593 | return winner; |
---|
594 | } |
---|
595 | } |
---|
596 | } |
---|
597 | |
---|
598 | //check 2d diagonals |
---|
599 | for(int k=0;k<4;k++){ |
---|
600 | for(int l=0;l<4;l++){ |
---|
601 | //rows-columns |
---|
602 | for(int i=1; i<4; i++) |
---|
603 | { |
---|
604 | if(this->board[i][i][k][l]==Mini4DgamePlayerColor::none || this->board[0][0][k][l] != this->board[i][i][k][l]) |
---|
605 | break; |
---|
606 | if(i==3) |
---|
607 | { |
---|
608 | winner.color_ = this->board[0][0][k][l]; |
---|
609 | for(int x=0; x<4; x++){ |
---|
610 | winner.winningRow[x] = x; |
---|
611 | winner.winningColumn[x] = x; |
---|
612 | winner.winningHeight[x] = k; |
---|
613 | winner.winningNumber[x] = l; |
---|
614 | } |
---|
615 | return winner; |
---|
616 | } |
---|
617 | } |
---|
618 | for(int i=1; i<4; i++) |
---|
619 | { |
---|
620 | if(this->board[3-i][i][k][l]==Mini4DgamePlayerColor::none || this->board[3][0][k][l] != this->board[3-i][i][k][l]) |
---|
621 | break; |
---|
622 | if(i==3) |
---|
623 | { |
---|
624 | winner.color_ = this->board[3][0][k][l]; |
---|
625 | for(int x=0; x<4; x++){ |
---|
626 | winner.winningRow[x] = 3-x; |
---|
627 | winner.winningColumn[x] = x; |
---|
628 | winner.winningHeight[x] = k; |
---|
629 | winner.winningNumber[x] = l; |
---|
630 | } |
---|
631 | return winner; |
---|
632 | } |
---|
633 | } |
---|
634 | //rows-height |
---|
635 | for(int i=1; i<4; i++) |
---|
636 | { |
---|
637 | if(this->board[i][k][i][l]==Mini4DgamePlayerColor::none || this->board[0][k][0][l] != this->board[i][k][i][l]) |
---|
638 | break; |
---|
639 | if(i==3) |
---|
640 | { |
---|
641 | winner.color_ = this->board[0][k][0][l]; |
---|
642 | for(int x=0; x<4; x++){ |
---|
643 | winner.winningRow[x] = x; |
---|
644 | winner.winningColumn[x] = k; |
---|
645 | winner.winningHeight[x] = x; |
---|
646 | winner.winningNumber[x] = l; |
---|
647 | } |
---|
648 | return winner; |
---|
649 | } |
---|
650 | } |
---|
651 | for(int i=1; i<4; i++) |
---|
652 | { |
---|
653 | if(this->board[3-i][k][i][l]==Mini4DgamePlayerColor::none || this->board[3][k][0][l] != this->board[3-i][k][i][l]) |
---|
654 | break; |
---|
655 | if(i==3) |
---|
656 | { |
---|
657 | winner.color_ = this->board[3][k][0][l]; |
---|
658 | for(int x=0; x<4; x++){ |
---|
659 | winner.winningRow[x] = 3-x; |
---|
660 | winner.winningColumn[x] = k; |
---|
661 | winner.winningHeight[x] = x; |
---|
662 | winner.winningNumber[x] = l; |
---|
663 | } |
---|
664 | return winner; |
---|
665 | } |
---|
666 | } |
---|
667 | //rows-numbers |
---|
668 | for(int i=1; i<4; i++) |
---|
669 | { |
---|
670 | if(this->board[i][k][l][i]==Mini4DgamePlayerColor::none || this->board[0][k][l][0] != this->board[i][k][l][i]) |
---|
671 | break; |
---|
672 | if(i==3) |
---|
673 | { |
---|
674 | winner.color_ = this->board[0][k][l][0]; |
---|
675 | for(int x=0; x<4; x++){ |
---|
676 | winner.winningRow[x] = x; |
---|
677 | winner.winningColumn[x] = k; |
---|
678 | winner.winningHeight[x] = l; |
---|
679 | winner.winningNumber[x] = x; |
---|
680 | } |
---|
681 | return winner; |
---|
682 | } |
---|
683 | } |
---|
684 | for(int i=1; i<4; i++) |
---|
685 | { |
---|
686 | if(this->board[3-i][k][l][i]==Mini4DgamePlayerColor::none || this->board[3][k][l][0] != this->board[3-i][k][l][i]) |
---|
687 | break; |
---|
688 | if(i==3) |
---|
689 | { |
---|
690 | winner.color_ = this->board[3][k][l][0]; |
---|
691 | for(int x=0; x<4; x++){ |
---|
692 | winner.winningRow[x] = 3-x; |
---|
693 | winner.winningColumn[x] = k; |
---|
694 | winner.winningHeight[x] = l; |
---|
695 | winner.winningNumber[x] = x; |
---|
696 | } |
---|
697 | return winner; |
---|
698 | } |
---|
699 | } |
---|
700 | //column-height |
---|
701 | for(int i=1; i<4; i++) |
---|
702 | { |
---|
703 | if(this->board[k][i][i][l]==Mini4DgamePlayerColor::none || this->board[k][0][0][l] != this->board[k][i][i][l]) |
---|
704 | break; |
---|
705 | if(i==3) |
---|
706 | { |
---|
707 | winner.color_ = this->board[k][0][0][l]; |
---|
708 | for(int x=0; x<4; x++){ |
---|
709 | winner.winningRow[x] = k; |
---|
710 | winner.winningColumn[x] = x; |
---|
711 | winner.winningHeight[x] = x; |
---|
712 | winner.winningNumber[x] = l; |
---|
713 | } |
---|
714 | return winner; |
---|
715 | } |
---|
716 | } |
---|
717 | for(int i=1; i<4; i++) |
---|
718 | { |
---|
719 | if(this->board[k][3-i][i][l]==Mini4DgamePlayerColor::none || this->board[k][3][0][l] != this->board[k][3-i][i][l]) |
---|
720 | break; |
---|
721 | if(i==3) |
---|
722 | { |
---|
723 | winner.color_ = this->board[k][3][0][l]; |
---|
724 | for(int x=0; x<4; x++){ |
---|
725 | winner.winningRow[x] = k; |
---|
726 | winner.winningColumn[x] = 3-x; |
---|
727 | winner.winningHeight[x] = x; |
---|
728 | winner.winningNumber[x] = l; |
---|
729 | } |
---|
730 | return winner; |
---|
731 | } |
---|
732 | } |
---|
733 | //column-numbers |
---|
734 | for(int i=1; i<4; i++) |
---|
735 | { |
---|
736 | if(this->board[k][i][l][i]==Mini4DgamePlayerColor::none || this->board[k][0][l][0] != this->board[k][i][l][i]) |
---|
737 | break; |
---|
738 | if(i==3) |
---|
739 | { |
---|
740 | winner.color_ = this->board[k][0][l][0]; |
---|
741 | for(int x=0; x<4; x++){ |
---|
742 | winner.winningRow[x] = k; |
---|
743 | winner.winningColumn[x] = x; |
---|
744 | winner.winningHeight[x] = l; |
---|
745 | winner.winningNumber[x] = x; |
---|
746 | } |
---|
747 | return winner; |
---|
748 | } |
---|
749 | } |
---|
750 | for(int i=1; i<4; i++) |
---|
751 | { |
---|
752 | if(this->board[k][3-i][l][i]==Mini4DgamePlayerColor::none || this->board[k][3][l][0] != this->board[k][3-i][l][i]) |
---|
753 | break; |
---|
754 | if(i==3) |
---|
755 | { |
---|
756 | winner.color_ = this->board[k][3][l][0]; |
---|
757 | for(int x=0; x<4; x++){ |
---|
758 | winner.winningRow[x] = k; |
---|
759 | winner.winningColumn[x] = 3-x; |
---|
760 | winner.winningHeight[x] = l; |
---|
761 | winner.winningNumber[x] = x; |
---|
762 | } |
---|
763 | return winner; |
---|
764 | } |
---|
765 | } |
---|
766 | //height-numbers |
---|
767 | for(int i=1; i<4; i++) |
---|
768 | { |
---|
769 | if(this->board[k][l][i][i]==Mini4DgamePlayerColor::none || this->board[k][l][0][0] != this->board[k][l][i][i]) |
---|
770 | break; |
---|
771 | if(i==3) |
---|
772 | { |
---|
773 | winner.color_ = this->board[k][l][0][0]; |
---|
774 | for(int x=0; x<4; x++){ |
---|
775 | winner.winningRow[x] = k; |
---|
776 | winner.winningColumn[x] = l; |
---|
777 | winner.winningHeight[x] = x; |
---|
778 | winner.winningNumber[x] = x; |
---|
779 | } |
---|
780 | return winner; |
---|
781 | } |
---|
782 | } |
---|
783 | for(int i=1; i<4; i++) |
---|
784 | { |
---|
785 | if(this->board[k][l][3-i][i]==Mini4DgamePlayerColor::none || this->board[k][l][3][0] != this->board[k][l][3-i][i]) |
---|
786 | break; |
---|
787 | if(i==3) |
---|
788 | { |
---|
789 | winner.color_ = this->board[k][l][3][0]; |
---|
790 | for(int x=0; x<4; x++){ |
---|
791 | winner.winningRow[x] = k; |
---|
792 | winner.winningColumn[x] = l; |
---|
793 | winner.winningHeight[x] = 3-x; |
---|
794 | winner.winningNumber[x] = x; |
---|
795 | } |
---|
796 | return winner; |
---|
797 | } |
---|
798 | } |
---|
799 | } |
---|
800 | } |
---|
801 | |
---|
802 | //check rows |
---|
803 | for(int j=0;j<4;j++){ |
---|
804 | for(int k=0;k<4;k++){ |
---|
805 | for(int l=0;l<4;l++){ |
---|
806 | if(this->board[0][j][k][l]!= Mini4DgamePlayerColor::none |
---|
807 | && this->board[0][j][k][l]==this->board[1][j][k][l] |
---|
808 | && this->board[1][j][k][l]==this->board[2][j][k][l] |
---|
809 | && this->board[2][j][k][l]==this->board[3][j][k][l]) |
---|
810 | { |
---|
811 | winner.color_ = this->board[0][j][k][l]; |
---|
812 | for(int x=0; x<4; x++){ |
---|
813 | winner.winningRow[x] = x; |
---|
814 | winner.winningColumn[x] = j; |
---|
815 | winner.winningHeight[x] = k; |
---|
816 | winner.winningNumber[x] = l; |
---|
817 | } |
---|
818 | return winner; |
---|
819 | } |
---|
820 | } |
---|
821 | } |
---|
822 | } |
---|
823 | |
---|
824 | //check columns |
---|
825 | for(int i=0;i<4;i++){ |
---|
826 | for(int k=0;k<4;k++){ |
---|
827 | for(int l=0;l<4;l++){ |
---|
828 | if(this->board[i][0][k][l]!= Mini4DgamePlayerColor::none |
---|
829 | && this->board[i][0][k][l]==this->board[i][1][k][l] |
---|
830 | && this->board[i][1][k][l]==this->board[i][2][k][l] |
---|
831 | && this->board[i][2][k][l]==this->board[i][3][k][l]) |
---|
832 | { |
---|
833 | winner.color_ = this->board[i][0][k][l]; |
---|
834 | for(int x=0; x<4; x++){ |
---|
835 | winner.winningRow[x] = i; |
---|
836 | winner.winningColumn[x] = x; |
---|
837 | winner.winningHeight[x] = k; |
---|
838 | winner.winningNumber[x] = l; |
---|
839 | } |
---|
840 | return winner; |
---|
841 | } |
---|
842 | } |
---|
843 | } |
---|
844 | } |
---|
845 | |
---|
846 | //check height |
---|
847 | for(int i=0;i<4;i++){ |
---|
848 | for(int j=0;j<4;j++){ |
---|
849 | for(int l=0;l<4;l++){ |
---|
850 | if(this->board[i][j][0][l]!= Mini4DgamePlayerColor::none |
---|
851 | && this->board[i][j][0][l]==this->board[i][j][1][l] |
---|
852 | && this->board[i][j][1][l]==this->board[i][j][2][l] |
---|
853 | && this->board[i][j][2][l]==this->board[i][j][3][l]) |
---|
854 | { |
---|
855 | winner.color_ = this->board[i][j][0][l]; |
---|
856 | for(int x=0; x<4; x++){ |
---|
857 | winner.winningRow[x] = i; |
---|
858 | winner.winningColumn[x] = j; |
---|
859 | winner.winningHeight[x] = x; |
---|
860 | winner.winningNumber[x] = l; |
---|
861 | } |
---|
862 | return winner; |
---|
863 | } |
---|
864 | } |
---|
865 | } |
---|
866 | } |
---|
867 | |
---|
868 | //check numbers |
---|
869 | for(int i=0;i<4;i++){ |
---|
870 | for(int j=0;j<4;j++){ |
---|
871 | for(int k=0;k<4;k++){ |
---|
872 | if(this->board[i][j][k][0]!= Mini4DgamePlayerColor::none |
---|
873 | && this->board[i][j][k][0]==this->board[i][j][k][1] |
---|
874 | && this->board[i][j][k][1]==this->board[i][j][k][2] |
---|
875 | && this->board[i][j][k][2]==this->board[i][j][k][3]) |
---|
876 | { |
---|
877 | winner.color_ = this->board[i][j][k][0]; |
---|
878 | for(int x=0; x<4; x++){ |
---|
879 | winner.winningRow[x] = i; |
---|
880 | winner.winningColumn[x] = j; |
---|
881 | winner.winningHeight[x] = k; |
---|
882 | winner.winningNumber[x] = x; |
---|
883 | } |
---|
884 | return winner; |
---|
885 | } |
---|
886 | } |
---|
887 | } |
---|
888 | } |
---|
889 | return winner; |
---|
890 | } |
---|
891 | |
---|
892 | /** |
---|
893 | @brief |
---|
894 | Checks whether the gametype is Mini4Dgame and if it is, sets its centerpoint. |
---|
895 | */ |
---|
896 | void Mini4DgameBoard::checkGametype() |
---|
897 | { |
---|
898 | if (this->getGametype() != nullptr && this->getGametype()->isA(Class(Mini4Dgame))) |
---|
899 | { |
---|
900 | Mini4Dgame* Mini4DgameGametype = orxonox_cast<Mini4Dgame*>(this->getGametype()); |
---|
901 | Mini4DgameGametype->setGameboard(this); |
---|
902 | } |
---|
903 | } |
---|
904 | } |
---|