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