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