Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 19, 2014, 4:08:42 PM (9 years ago)
Author:
richtero
Message:

new structure: Board in separate class

Location:
code/branches/minigame4DHS14
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • code/branches/minigame4DHS14/data/levels/4Dtest.oxw

    r10115 r10131  
    1212?>
    1313
    14 <!-- Templates here
    15 <Template name=mini4Dgamestone>
    16   <Mini4DgameStone>
     14<!-- Templates here -->
     15<Template name=mini4Dgameboard>
     16  <Mini4DgameBoard>
    1717    <attached>
    18       <Model mesh="asteroid_UV.mesh" scale="2" />
     18      <?lua
     19                for i = -90, 90, 60
     20                do
     21                ?>
     22                        <?lua
     23                        for j = -90, 90, 60
     24                        do
     25                        ?>
     26                                <?lua
     27                                for k = -90, 90, 60
     28                                do
     29                                ?>
     30                                        <Model
     31                                        position="<?lua print(i) ?>,<?lua print(j) ?>,<?lua print(k) ?>"
     32                                        mesh="checkPoint.mesh"
     33                                        scale="5" />
     34                                <?lua
     35                                end
     36                                ?>
     37                        <?lua
     38                        end
     39                        ?>
     40                <?lua
     41                end
     42                ?>
    1943    </attached>
    20   </Mini4DgameStone>
     44  </Mini4DgameBoard>
    2145</Template>
    2246
    23 
     47<!--
    2448        <BlinkingBillboard position="0,0,0" frequency=0.6 amplitude=0.4 material="Flares/lensflare" colour="0,1,0">
    2549        </BlinkingBillboard>
     
    5175    <SpawnPoint position="-330,330,165" lookat="0,0,0" />
    5276
    53         <Mini4DgameCenterpoint name=mini4Dgamecenter width=16 height=16 length=16 position="0,0,0">
    54         <attached>
    55                 <?lua
    56                 for i = -90, 90, 60
    57                 do
    58                 ?>
    59                         <?lua
    60                         for j = -90, 90, 60
    61                         do
    62                         ?>
    63                                 <?lua
    64                                 for k = -90, 90, 60
    65                                 do
    66                                 ?>
    67                                         <Model
    68                                         position="<?lua print(i) ?>,<?lua print(j) ?>,<?lua print(k) ?>"
    69                                         mesh="checkPoint.mesh"
    70                                         scale="5" />
    71                                 <?lua
    72                                 end
    73                                 ?>
    74                         <?lua
    75                         end
    76                         ?>
    77                 <?lua
    78                 end
    79                 ?>
    80         </attached>
     77        <Mini4DgameCenterpoint name=mini4Dgamecenter boardtemplate=mini4Dgameboard width=16 height=16 length=16 position="0,0,0">
     78
    8179    </Mini4DgameCenterpoint>
    8280
  • code/branches/minigame4DHS14/src/modules/mini4Dgame/CMakeLists.txt

    r10121 r10131  
    11SET_SOURCE_FILES(Mini4Dgame_SRC_FILES
    22  Mini4Dgame.cc
    3   Mini4DgameAI.cc
     3  #Mini4DgameAI.cc
     4  Mini4DgameBoard.cc
    45  Mini4DgameCenterpoint.cc
    56)
  • code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4Dgame.cc

    r10121 r10131  
    4545#include "core/config/ConfigValueIncludes.h"
    4646#include "infos/PlayerInfo.h"
     47#include "core/command/ConsoleCommand.h"
    4748
    4849#include "gamestates/GSLevel.h"
     
    5354namespace orxonox
    5455{
     56
     57        SetConsoleCommand("Mini4Dgame", "setStone", &Mini4Dgame::setStone).addShortcut();
    5558
    5659    RegisterUnloadableClass(Mini4Dgame);
     
    6568
    6669        this->center_ = 0;
    67         //TODO: player Null setzen
     70        this->board_ = 0;
     71
     72        // Set the type of Bots for this particular Gametype.
     73        //this->botclass_ = Class(Mini4DgameBot);
    6874    }
    6975
     
    8793    }
    8894
    89     /*
    90     bool Mini4Dgame::isValidMove(Vector4* move, const Mini4DgameBoard* board)
    91     {
    92 
    93     }
    94     */
    95 
    96 
    9795    /**
    9896    @brief
    99         Starts the Tetris minigame.
     97        Starts the mini4Dgame.
    10098    */
    10199    void Mini4Dgame::start()
     
    103101        if (this->center_ != NULL) // There needs to be a Mini4DgameCenterpoint, i.e. the area the game takes place.
    104102        {
    105             //TODO: create all objects if they don't exist so far and attach the parameters specified in the centerpoint to them
     103                if (this->board_ == NULL)
     104                {
     105                        this->board_ = new Mini4DgameBoard(this->center_->getContext());
     106                        // Apply the template for the ball specified by the centerpoint.
     107                        this->board_->addTemplate(this->center_->getBoardtemplate());
     108                }
     109
     110                // Attach the board to the centerpoint and set the parameters as specified in the centerpoint, the ball is attached to.
     111                this->center_->attach(this->board_);
     112                this->board_->setPosition(0, 0, 0);
     113
    106114        }
    107115        else // If no centerpoint was specified, an error is thrown and the level is exited.
     
    169177    }
    170178
     179    static void Mini4Dgame::setStone(Vector4 move, const int playerColor, Mini4DgameBoard* board)
     180    {
     181        board->makeMove(move,playerColor);
     182    }
    171183
     184    void Mini4Dgame::win(Mini4DgameWinner winner)
     185    {
     186
     187    }
    172188}
  • code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4Dgame.h

    r10121 r10131  
    3737#include "gametypes/Deathmatch.h"
    3838#include "mini4Dgame/Mini4DgamePrereqs.h"
     39#include "Mini4DgameCenterpoint.h"
     40#include "Mini4DgameBoard.h"
    3941
    4042namespace orxonox
    4143{
     44
    4245        namespace mini4DgamePlayerColor
    4346        {
     
    5154        }
    5255
    53         struct Mini4DgamePlayer
    54         {
    55             Player player;
    56             mini4DgamePlayerColor::color color_;
    57         };
    58 
    59         struct Mini4DgameWinner
    60         {
    61                 int winningRow[4];
    62                 int winningColumn[4];
    63                 int winningHeight[4];
    64                 int winningNumber[4];
    65                 mini4DgamePlayerColor::color color_;
    66         };
    6756    /**
    6857    @brief
     
    8574                { this->center_ = center; }
    8675
     76            static void setStone(Vector4 move, const int playerColor, Mini4DgameBoard* board);
     77
    8778            void win(Mini4DgameWinner winner);
    8879
     
    9485            void cleanup(void); //!< Cleans up the Gametype by destroying the ball and the bats.
    9586
    96             Mini4DgamePlayer players[2];
     87            //Player players[2];
    9788
    98             WeakPtr<Mini4DgameCenterpoint> center_; //!< The playing field.
     89            WeakPtr<Mini4DgameCenterpoint> center_; //!< The centerpoint to which the objects are attached
     90            WeakPtr<Mini4DgameBoard> board_;
    9991    };
    10092}
  • code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4DgameAI.h

    r10121 r10131  
    7171                        The move that the AI decided to make.
    7272            */
    73             Vector4 Mini4DgameAI::makeMove(float timeout);
     73            Vector4 makeMove(float timeout);
    7474
    7575
     
    8686        private:
    8787
    88             std::list<Vector4> Mini4DgameAI::getPossibleMoves();
    89             void Mini4DgameAI::copyBoard();
     88            std::list<Vector4> getPossibleMoves();
     89            void copyBoard();
    9090            mini4DgamePlayerColor::color board_[4][4][4][4];
    9191    };
  • code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4DgameCenterpoint.cc

    r10121 r10131  
    3737#include "core/XMLPort.h"
    3838
     39#include "../orxonox/graphics/BlinkingBillboard.h"
     40
    3941#include "Mini4Dgame.h"
    4042
    4143namespace orxonox
    4244{
     45
    4346    RegisterClass(Mini4DgameCenterpoint);
    44 
    4547    /**
    4648    @brief
     
    5456        this->height_ = 200;
    5557        this->length_ = 200;
    56 
    57         for(int i=0;i<4;i++){
    58                 for(int j=0;j<4;j++){
    59                         for(int k=0;k<4;k++){
    60                                 for(int l=0;l<4;l++){
    61                                         this->board[i][j][k][l]=mini4DgamePlayerColor::none;
    62                                 }
    63                         }
    64                 }
    65         }
    6658
    6759        this->checkGametype();
     
    7769
    7870        XMLPortParam(Mini4DgameCenterpoint, "dimension", setFieldDimension, getFieldDimension, xmlelement, mode);
     71        XMLPortParam(Mini4DgameCenterpoint, "boardtemplate", setBoardtemplate, getBoardtemplate, xmlelement, mode);
    7972    }
    8073
     
    10396        }
    10497    }
    105 
    106     /**
    107         @brief checks if the move is valid
    108         @param the position where to put the stone plus the player who makes the move
    109     */
    110     bool Mini4DgameCenterpoint::isValidMove(const Vector4 move)
    111     {
    112         return (this->board[(int)move.x][(int)move.y][(int)move.z][(int)move.w] == mini4DgamePlayerColor::none);
    113     }
    114 
    115     /**
    116     @brief makes a move on the logic playboard
    117     @param the position where to put the stone plus the player who makes the move
    118     */
    119     void Mini4DgameCenterpoint::makeMove(const Vector4 move, const mini4DgamePlayerColor::color playerColor)
    120     {
    121         if(this->isValidMove(move))
    122         {
    123                 this->board[(int)move.x][(int)move.y][(int)move.z][(int)move.w] = playerColor;
    124                 Mini4DgameWinner winner = this->getWinner();
    125                 if(winner.color_ != mini4DgamePlayerColor::none)
    126                 {
    127                         Mini4Dgame->win(winner);
    128                 }
    129         }
    130     }
    131 
    132     Mini4DgameWinner Mini4DgameCenterpoint::getWinner()
    133     {
    134         Mini4DgameWinner winner;
    135                 winner.color_ = mini4DgamePlayerColor::none;
    136 
    137         //check diagonals rows-columns-height-numbers
    138                 for(int i=1; i<4; i++)
    139                 {
    140                         if(this->board[i][i][i][i]==mini4DgamePlayerColor::none || this->board[0][0][0][0] != this->board[i][i][i][i])
    141                                 break;
    142                         if(i==3)
    143                         {
    144                                 winner.color_ = this->board[0][0][0][0];
    145                                 for(int x=0; x<4; x++){
    146                                         winner.winningRow[x] = x;
    147                                         winner.winningColumn[x] = x;
    148                                         winner.winningHeight[x] = x;
    149                                         winner.winningNumber[x] = x;
    150                                 }
    151                                 return winner;
    152                         }
    153                 }
    154                 for(int i=1; i<4; i++)
    155                 {
    156                         if(this->board[3-i][i][i][i]==mini4DgamePlayerColor::none || this->board[3][0][0][0] != this->board[3-i][i][i][i])
    157                                 break;
    158                         if(i==3)
    159                         {
    160                                 winner.color_ = this->board[3][0][0][0];
    161                                 for(int x=0; x<4; x++){
    162                                         winner.winningRow[x] = 3-x;
    163                                         winner.winningColumn[x] = x;
    164                                         winner.winningHeight[x] = x;
    165                                         winner.winningNumber[x] = x;
    166                                 }
    167                                 return winner;
    168                         }
    169                 }
    170                 for(int i=1; i<4; i++)
    171                 {
    172                         if(this->board[i][3-i][i][i]==mini4DgamePlayerColor::none || this->board[0][3][0][0] != this->board[i][3-i][i][i])
    173                                 break;
    174                         if(i==3)
    175                         {
    176                                 winner.color_ = this->board[0][3][0][0];
    177                                 for(int x=0; x<4; x++){
    178                                         winner.winningRow[x] = x;
    179                                         winner.winningColumn[x] = 3-x;
    180                                         winner.winningHeight[x] = x;
    181                                         winner.winningNumber[x] = x;
    182                                 }
    183                                 return winner;
    184                         }
    185                 }
    186                 for(int i=1; i<4; i++)
    187                 {
    188                         if(this->board[i][i][3-i][i]==mini4DgamePlayerColor::none || this->board[0][0][3][0] != this->board[i][i][3-i][i])
    189                                 break;
    190                         if(i==3)
    191                         {
    192                                 winner.color_ = this->board[0][0][3][0];
    193                                 for(int x=0; x<4; x++){
    194                                         winner.winningRow[x] = x;
    195                                         winner.winningColumn[x] = x;
    196                                         winner.winningHeight[x] = 3-x;
    197                                         winner.winningNumber[x] = x;
    198                                 }
    199                                 return winner;
    200                         }
    201                 }
    202                 for(int i=1; i<4; i++)
    203                 {
    204                         if(this->board[i][i][i][3-i]==mini4DgamePlayerColor::none || this->board[0][0][0][3] != this->board[i][i][i][3-i])
    205                                 break;
    206                         if(i==3)
    207                         {
    208                                 winner.color_ = this->board[0][0][0][3];
    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] = 3-x;
    214                                 }
    215                                 return winner;
    216                         }
    217                 }
    218                 for(int i=1; i<4; i++)
    219                 {
    220                         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])
    221                                 break;
    222                         if(i==3)
    223                         {
    224                                 winner.color_ = this->board[3][3][0][0];
    225                                 for(int x=0; x<4; x++){
    226                                         winner.winningRow[x] = 3-x;
    227                                         winner.winningColumn[x] = 3-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[3-i][i][3-i][i]==mini4DgamePlayerColor::none || this->board[3][0][3][0] != this->board[3-i][i][3-i][i])
    237                                 break;
    238                         if(i==3)
    239                         {
    240                                 winner.color_ = this->board[3][0][3][0];
    241                                 for(int x=0; x<4; x++){
    242                                         winner.winningRow[x] = 3-x;
    243                                         winner.winningColumn[x] = x;
    244                                         winner.winningHeight[x] = 3-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[3-i][i][i][3-i]==mini4DgamePlayerColor::none || this->board[3][0][0][3] != this->board[3-i][i][i][3-i])
    253                                 break;
    254                         if(i==3)
    255                         {
    256                                 winner.color_ = this->board[3][0][0][3];
    257                                 for(int x=0; x<4; x++){
    258                                         winner.winningRow[x] = 3-x;
    259                                         winner.winningColumn[x] = x;
    260                                         winner.winningHeight[x] = x;
    261                                         winner.winningNumber[x] = 3-x;
    262                                 }
    263                                 return winner;
    264                         }
    265                 }
    266 
    267                 //check diagonals rows-columns-height
    268                 for(int l=0; l<4; l++)
    269                 {
    270                         for(int i=1; i<4; i++)
    271                         {
    272                                 if(this->board[i][i][i][l]==mini4DgamePlayerColor::none || this->board[0][0][0][l] != this->board[i][i][i][l])
    273                                         break;
    274                                 if(i==3)
    275                                 {
    276                                         winner.color_ = this->board[0][0][0][l];
    277                                         for(int x=0; x<4; x++){
    278                                                 winner.winningRow[x] = x;
    279                                                 winner.winningColumn[x] = x;
    280                                                 winner.winningHeight[x] = x;
    281                                                 winner.winningNumber[x] = l;
    282                                         }
    283                                         return winner;
    284                                 }
    285                         }
    286                         for(int i=1; i<4; i++)
    287                         {
    288                                 if(this->board[3-i][i][i][l]==mini4DgamePlayerColor::none || this->board[3][0][0][l] != this->board[3-i][i][i][l])
    289                                         break;
    290                                 if(i==3)
    291                                 {
    292                                         winner.color_ = this->board[3][0][0][l];
    293                                         for(int x=0; x<4; x++){
    294                                                 winner.winningRow[x] = 3-x;
    295                                                 winner.winningColumn[x] = x;
    296                                                 winner.winningHeight[x] = x;
    297                                                 winner.winningNumber[x] = l;
    298                                         }
    299                                         return winner;
    300                                 }
    301                         }
    302                         for(int i=1; i<4; i++)
    303                         {
    304                                 if(this->board[i][3-i][i][l]==mini4DgamePlayerColor::none || this->board[0][3][0][l] != this->board[i][3-i][i][l])
    305                                         break;
    306                                 if(i==3)
    307                                 {
    308                                         winner.color_ = this->board[0][3][0][l];
    309                                         for(int x=0; x<4; x++){
    310                                                 winner.winningRow[x] = x;
    311                                                 winner.winningColumn[x] = 3-x;
    312                                                 winner.winningHeight[x] = x;
    313                                                 winner.winningNumber[x] = l;
    314                                         }
    315                                         return winner;
    316                                 }
    317                         }
    318                         for(int i=1; i<4; i++)
    319                         {
    320                                 if(this->board[i][i][3-i][l]==mini4DgamePlayerColor::none || this->board[0][0][3][l] != this->board[i][i][3-i][l])
    321                                         break;
    322                                 if(i==3)
    323                                 {
    324                                         winner.color_ = this->board[0][0][3][l];
    325                                         for(int x=0; x<4; x++){
    326                                                 winner.winningRow[x] = x;
    327                                                 winner.winningColumn[x] = x;
    328                                                 winner.winningHeight[x] = 3-x;
    329                                                 winner.winningNumber[x] = l;
    330                                         }
    331                                         return winner;
    332                                 }
    333                         }
    334                 }
    335 
    336                 //check diagonals rows-columns-numbers
    337                 for(int l=0; l<4; l++)
    338                 {
    339                         for(int i=1; i<4; i++)
    340                         {
    341                                 if(this->board[i][i][l][i]==mini4DgamePlayerColor::none || this->board[0][0][l][0] != this->board[i][i][l][i])
    342                                         break;
    343                                 if(i==3)
    344                                 {
    345                                         winner.color_ = this->board[0][0][l][0];
    346                                         for(int x=0; x<4; x++){
    347                                                 winner.winningRow[x] = x;
    348                                                 winner.winningColumn[x] = x;
    349                                                 winner.winningHeight[x] = l;
    350                                                 winner.winningNumber[x] = x;
    351                                         }
    352                                         return winner;
    353                                 }
    354                         }
    355                         for(int i=1; i<4; i++)
    356                         {
    357                                 if(this->board[3-i][i][l][i]==mini4DgamePlayerColor::none || this->board[3][0][l][0] != this->board[3-i][i][l][i])
    358                                         break;
    359                                 if(i==3)
    360                                 {
    361                                         winner.color_ = this->board[3][0][l][0];
    362                                         for(int x=0; x<4; x++){
    363                                                 winner.winningRow[x] = 3-x;
    364                                                 winner.winningColumn[x] = x;
    365                                                 winner.winningHeight[x] = l;
    366                                                 winner.winningNumber[x] = x;
    367                                         }
    368                                         return winner;
    369                                 }
    370                         }
    371                         for(int i=1; i<4; i++)
    372                         {
    373                                 if(this->board[i][3-i][l][i]==mini4DgamePlayerColor::none || this->board[0][3][l][0] != this->board[i][3-i][l][i])
    374                                         break;
    375                                 if(i==3)
    376                                 {
    377                                         winner.color_ = this->board[0][3][l][0];
    378                                         for(int x=0; x<4; x++){
    379                                                 winner.winningRow[x] = x;
    380                                                 winner.winningColumn[x] = 3-x;
    381                                                 winner.winningHeight[x] = l;
    382                                                 winner.winningNumber[x] = x;
    383                                         }
    384                                         return winner;
    385                                 }
    386                         }
    387                         for(int i=1; i<4; i++)
    388                         {
    389                                 if(this->board[i][i][l][3-i]==mini4DgamePlayerColor::none || this->board[0][0][l][3] != this->board[i][i][l][3-i])
    390                                         break;
    391                                 if(i==3)
    392                                 {
    393                                         winner.color_ = this->board[0][0][l][3];
    394                                         for(int x=0; x<4; x++){
    395                                                 winner.winningRow[x] = x;
    396                                                 winner.winningColumn[x] = x;
    397                                                 winner.winningHeight[x] = l;
    398                                                 winner.winningNumber[x] = 3-x;
    399                                         }
    400                                         return winner;
    401                                 }
    402                         }
    403                 }
    404 
    405                 //check diagonals rows-height-numbers
    406                 for(int l=0; l<4; l++)
    407                 {
    408                         for(int i=1; i<4; i++)
    409                         {
    410                                 if(this->board[i][l][i][i]==mini4DgamePlayerColor::none || this->board[0][l][0][0] != this->board[i][l][i][i])
    411                                         break;
    412                                 if(i==3)
    413                                 {
    414                                         winner.color_ = this->board[0][l][0][0];
    415                                         for(int x=0; x<4; x++){
    416                                                 winner.winningRow[x] = x;
    417                                                 winner.winningColumn[x] = l;
    418                                                 winner.winningHeight[x] = x;
    419                                                 winner.winningNumber[x] = x;
    420                                         }
    421                                         return winner;
    422                                 }
    423                         }
    424                         for(int i=1; i<4; i++)
    425                         {
    426                                 if(this->board[3-i][l][i][i]==mini4DgamePlayerColor::none || this->board[3][l][0][0] != this->board[3-i][l][i][i])
    427                                         break;
    428                                 if(i==3)
    429                                 {
    430                                         winner.color_ = this->board[3][l][0][0];
    431                                         for(int x=0; x<4; x++){
    432                                                 winner.winningRow[x] = 3-x;
    433                                                 winner.winningColumn[x] = l;
    434                                                 winner.winningHeight[x] = x;
    435                                                 winner.winningNumber[x] = x;
    436                                         }
    437                                         return winner;
    438                                 }
    439                         }
    440                         for(int i=1; i<4; i++)
    441                         {
    442                                 if(this->board[i][l][3-i][i]==mini4DgamePlayerColor::none || this->board[0][l][3][0] != this->board[i][l][3-i][i])
    443                                         break;
    444                                 if(i==3)
    445                                 {
    446                                         winner.color_ = this->board[0][l][3][0];
    447                                         for(int x=0; x<4; x++){
    448                                                 winner.winningRow[x] = x;
    449                                                 winner.winningColumn[x] = l;
    450                                                 winner.winningHeight[x] = 3-x;
    451                                                 winner.winningNumber[x] = x;
    452                                         }
    453                                         return winner;
    454                                 }
    455                         }
    456                         for(int i=1; i<4; i++)
    457                         {
    458                                 if(this->board[i][l][i][3-i]==mini4DgamePlayerColor::none || this->board[0][l][0][3] != this->board[i][l][i][3-i])
    459                                         break;
    460                                 if(i==3)
    461                                 {
    462                                         winner.color_ = this->board[0][l][0][3];
    463                                         for(int x=0; x<4; x++){
    464                                                 winner.winningRow[x] = x;
    465                                                 winner.winningColumn[x] = l;
    466                                                 winner.winningHeight[x] = x;
    467                                                 winner.winningNumber[x] = 3-x;
    468                                         }
    469                                         return winner;
    470                                 }
    471                         }
    472                 }
    473 
    474                 //check diagonals columns-height-numbers
    475                 for(int l=0; l<4; l++)
    476                 {
    477                         for(int i=1; i<4; i++)
    478                         {
    479                                 if(this->board[l][i][i][i]==mini4DgamePlayerColor::none || this->board[l][0][0][0] != this->board[l][i][i][i])
    480                                         break;
    481                                 if(i==3)
    482                                 {
    483                                         winner.color_ = this->board[l][0][0][0];
    484                                         for(int x=0; x<4; x++){
    485                                                 winner.winningRow[x] = l;
    486                                                 winner.winningColumn[x] = x;
    487                                                 winner.winningHeight[x] = x;
    488                                                 winner.winningNumber[x] = x;
    489                                         }
    490                                         return winner;
    491                                 }
    492                         }
    493                         for(int i=1; i<4; i++)
    494                         {
    495                                 if(this->board[l][3-i][i][i]==mini4DgamePlayerColor::none || this->board[l][3][0][0] != this->board[l][3-i][i][i])
    496                                         break;
    497                                 if(i==3)
    498                                 {
    499                                         winner.color_ = this->board[l][3][0][0];
    500                                         for(int x=0; x<4; x++){
    501                                                 winner.winningRow[x] = l;
    502                                                 winner.winningColumn[x] = 3-x;
    503                                                 winner.winningHeight[x] = x;
    504                                                 winner.winningNumber[x] = x;
    505                                         }
    506                                         return winner;
    507                                 }
    508                         }
    509                         for(int i=1; i<4; i++)
    510                         {
    511                                 if(this->board[l][i][3-i][i]==mini4DgamePlayerColor::none || this->board[l][0][3][0] != this->board[l][i][3-i][i])
    512                                         break;
    513                                 if(i==3)
    514                                 {
    515                                         winner.color_ = this->board[l][0][3][0];
    516                                         for(int x=0; x<4; x++){
    517                                                 winner.winningRow[x] = l;
    518                                                 winner.winningColumn[x] = x;
    519                                                 winner.winningHeight[x] = 3-x;
    520                                                 winner.winningNumber[x] = x;
    521                                         }
    522                                         return winner;
    523                                 }
    524                         }
    525                         for(int i=1; i<4; i++)
    526                         {
    527                                 if(this->board[l][i][i][3-i]==mini4DgamePlayerColor::none || this->board[l][0][0][3] != this->board[l][i][i][3-i])
    528                                         break;
    529                                 if(i==3)
    530                                 {
    531                                         winner.color_ = this->board[l][0][0][3];
    532                                         for(int x=0; x<4; x++){
    533                                                 winner.winningRow[x] = l;
    534                                                 winner.winningColumn[x] = x;
    535                                                 winner.winningHeight[x] = x;
    536                                                 winner.winningNumber[x] = 3-x;
    537                                         }
    538                                         return winner;
    539                                 }
    540                         }
    541                 }
    542 
    543                 //check 2d diagonals
    544                 for(int k=0;k<4;k++){
    545                 for(int l=0;l<4;l++){
    546                         //rows-columns
    547                         for(int i=1; i<4; i++)
    548                                 {
    549                                         if(this->board[i][i][k][l]==mini4DgamePlayerColor::none || this->board[0][0][k][l] != this->board[i][i][k][l])
    550                                                 break;
    551                                         if(i==3)
    552                                         {
    553                                                 winner.color_ = this->board[0][0][k][l];
    554                                                 for(int x=0; x<4; x++){
    555                                                         winner.winningRow[x] = x;
    556                                                         winner.winningColumn[x] = x;
    557                                                         winner.winningHeight[x] = k;
    558                                                         winner.winningNumber[x] = l;
    559                                                 }
    560                                                 return winner;
    561                                         }
    562                                 }
    563                                 for(int i=1; i<4; i++)
    564                                 {
    565                                         if(this->board[3-i][i][k][l]==mini4DgamePlayerColor::none || this->board[3][0][k][l] != this->board[3-i][i][k][l])
    566                                                 break;
    567                                         if(i==3)
    568                                         {
    569                                                 winner.color_ = this->board[3][0][k][l];
    570                                                 for(int x=0; x<4; x++){
    571                                                         winner.winningRow[x] = 3-x;
    572                                                         winner.winningColumn[x] = x;
    573                                                         winner.winningHeight[x] = k;
    574                                                         winner.winningNumber[x] = l;
    575                                                 }
    576                                                 return winner;
    577                                         }
    578                                 }
    579                                 //rows-height
    580                         for(int i=1; i<4; i++)
    581                         {
    582                                 if(this->board[i][k][i][l]==mini4DgamePlayerColor::none || this->board[0][k][0][l] != this->board[i][k][i][l])
    583                                         break;
    584                                 if(i==3)
    585                                 {
    586                                                 winner.color_ = this->board[0][k][0][l];
    587                                                 for(int x=0; x<4; x++){
    588                                                         winner.winningRow[x] = x;
    589                                                         winner.winningColumn[x] = k;
    590                                                         winner.winningHeight[x] = x;
    591                                                         winner.winningNumber[x] = l;
    592                                                 }
    593                                                 return winner;
    594                                         }
    595                                 }
    596                                 for(int i=1; i<4; i++)
    597                         {
    598                                 if(this->board[3-i][k][i][l]==mini4DgamePlayerColor::none || this->board[3][k][0][l] != this->board[3-i][k][i][l])
    599                                         break;
    600                                 if(i==3)
    601                                 {
    602                                                 winner.color_ = this->board[3][k][0][l];
    603                                                 for(int x=0; x<4; x++){
    604                                                         winner.winningRow[x] = 3-x;
    605                                                         winner.winningColumn[x] = k;
    606                                                         winner.winningHeight[x] = x;
    607                                                         winner.winningNumber[x] = l;
    608                                                 }
    609                                                 return winner;
    610                                         }
    611                                 }
    612                                 //rows-numbers
    613                                 for(int i=1; i<4; i++)
    614                         {
    615                                 if(this->board[i][k][l][i]==mini4DgamePlayerColor::none || this->board[0][k][l][0] != this->board[i][k][l][i])
    616                                         break;
    617                                 if(i==3)
    618                                 {
    619                                                 winner.color_ = this->board[0][k][l][0];
    620                                                 for(int x=0; x<4; x++){
    621                                                         winner.winningRow[x] = x;
    622                                                         winner.winningColumn[x] = k;
    623                                                         winner.winningHeight[x] = l;
    624                                                         winner.winningNumber[x] = x;
    625                                                 }
    626                                                 return winner;
    627                                         }
    628                                 }
    629                                 for(int i=1; i<4; i++)
    630                         {
    631                                 if(this->board[3-i][k][l][i]==mini4DgamePlayerColor::none || this->board[3][k][l][0] != this->board[3-i][k][l][i])
    632                                         break;
    633                                 if(i==3)
    634                                 {
    635                                                 winner.color_ = this->board[3][k][l][0];
    636                                                 for(int x=0; x<4; x++){
    637                                                         winner.winningRow[x] = 3-x;
    638                                                         winner.winningColumn[x] = k;
    639                                                         winner.winningHeight[x] = l;
    640                                                         winner.winningNumber[x] = x;
    641                                                 }
    642                                                 return winner;
    643                                         }
    644                                 }
    645                                 //column-height
    646                                 for(int i=1; i<4; i++)
    647                         {
    648                                 if(this->board[k][i][i][l]==mini4DgamePlayerColor::none || this->board[k][0][0][l] != this->board[k][i][i][l])
    649                                         break;
    650                                 if(i==3)
    651                                 {
    652                                                 winner.color_ = this->board[k][0][0][l];
    653                                                 for(int x=0; x<4; x++){
    654                                                         winner.winningRow[x] = k;
    655                                                         winner.winningColumn[x] = x;
    656                                                         winner.winningHeight[x] = x;
    657                                                         winner.winningNumber[x] = l;
    658                                                 }
    659                                                 return winner;
    660                                         }
    661                                 }
    662                                 for(int i=1; i<4; i++)
    663                         {
    664                                 if(this->board[k][3-i][i][l]==mini4DgamePlayerColor::none || this->board[k][3][0][l] != this->board[k][3-i][i][l])
    665                                         break;
    666                                 if(i==3)
    667                                 {
    668                                                 winner.color_ = this->board[k][3][0][l];
    669                                                 for(int x=0; x<4; x++){
    670                                                         winner.winningRow[x] = k;
    671                                                         winner.winningColumn[x] = 3-x;
    672                                                         winner.winningHeight[x] = x;
    673                                                         winner.winningNumber[x] = l;
    674                                                 }
    675                                                 return winner;
    676                                         }
    677                                 }
    678                                 //column-numbers
    679                                 for(int i=1; i<4; i++)
    680                         {
    681                                 if(this->board[k][i][l][i]==mini4DgamePlayerColor::none || this->board[k][0][l][0] != this->board[k][i][l][i])
    682                                         break;
    683                                 if(i==3)
    684                                 {
    685                                                 winner.color_ = this->board[k][0][l][0];
    686                                                 for(int x=0; x<4; x++){
    687                                                         winner.winningRow[x] = k;
    688                                                         winner.winningColumn[x] = x;
    689                                                         winner.winningHeight[x] = l;
    690                                                         winner.winningNumber[x] = x;
    691                                                 }
    692                                                 return winner;
    693                                         }
    694                                 }
    695                                 for(int i=1; i<4; i++)
    696                         {
    697                                 if(this->board[k][3-i][l][i]==mini4DgamePlayerColor::none || this->board[k][3][l][0] != this->board[k][3-i][l][i])
    698                                         break;
    699                                 if(i==3)
    700                                 {
    701                                                 winner.color_ = this->board[k][3][l][0];
    702                                                 for(int x=0; x<4; x++){
    703                                                         winner.winningRow[x] = k;
    704                                                         winner.winningColumn[x] = 3-x;
    705                                                         winner.winningHeight[x] = l;
    706                                                         winner.winningNumber[x] = x;
    707                                                 }
    708                                                 return winner;
    709                                         }
    710                                 }
    711                                 //height-numbers
    712                                 for(int i=1; i<4; i++)
    713                         {
    714                                 if(this->board[k][l][i][i]==mini4DgamePlayerColor::none || this->board[k][l][0][0] != this->board[k][l][i][i])
    715                                         break;
    716                                 if(i==3)
    717                                 {
    718                                                 winner.color_ = this->board[k][l][0][0];
    719                                                 for(int x=0; x<4; x++){
    720                                                         winner.winningRow[x] = k;
    721                                                         winner.winningColumn[x] = l;
    722                                                         winner.winningHeight[x] = x;
    723                                                         winner.winningNumber[x] = x;
    724                                                 }
    725                                                 return winner;
    726                                         }
    727                                 }
    728                                 for(int i=1; i<4; i++)
    729                         {
    730                                 if(this->board[k][l][3-i][i]==mini4DgamePlayerColor::none || this->board[k][l][3][0] != this->board[k][l][3-i][i])
    731                                         break;
    732                                 if(i==3)
    733                                 {
    734                                                 winner.color_ = this->board[k][l][3][0];
    735                                                 for(int x=0; x<4; x++){
    736                                                         winner.winningRow[x] = k;
    737                                                         winner.winningColumn[x] = l;
    738                                                         winner.winningHeight[x] = 3-x;
    739                                                         winner.winningNumber[x] = x;
    740                                                 }
    741                                                 return winner;
    742                                         }
    743                                 }
    744                 }
    745         }
    746 
    747         //check rows
    748         for(int j=0;j<4;j++){
    749                 for(int k=0;k<4;k++){
    750                         for(int l=0;l<4;l++){
    751                                 if(this->board[0][j][k][l]!= mini4DgamePlayerColor::none
    752                                    && this->board[0][j][k][l]==this->board[1][j][k][l]
    753                                    && this->board[1][j][k][l]==this->board[2][j][k][l]
    754                                    && this->board[2][j][k][l]==this->board[3][j][k][l])
    755                                 {
    756                                         winner.color_ = this->board[0][j][k][l];
    757                                                 for(int x=0; x<4; x++){
    758                                                         winner.winningRow[x] = x;
    759                                                         winner.winningColumn[x] = j;
    760                                                         winner.winningHeight[x] = k;
    761                                                         winner.winningNumber[x] = l;
    762                                                 }
    763                                                 return winner;
    764                                 }
    765                         }
    766                 }
    767         }
    768 
    769         //check columns
    770         for(int i=0;i<4;i++){
    771                 for(int k=0;k<4;k++){
    772                         for(int l=0;l<4;l++){
    773                                 if(this->board[i][0][k][l]!= mini4DgamePlayerColor::none
    774                                            && this->board[i][0][k][l]==this->board[i][1][k][l]
    775                                            && this->board[i][1][k][l]==this->board[i][2][k][l]
    776                                            && this->board[i][2][k][l]==this->board[i][3][k][l])
    777                                 {
    778                                 winner.color_ = this->board[i][0][k][l];
    779                                                 for(int x=0; x<4; x++){
    780                                                         winner.winningRow[x] = i;
    781                                                         winner.winningColumn[x] = x;
    782                                                         winner.winningHeight[x] = k;
    783                                                         winner.winningNumber[x] = l;
    784                                                 }
    785                                                 return winner;
    786                                 }
    787                         }
    788                 }
    789         }
    790 
    791         //check height
    792         for(int i=0;i<4;i++){
    793                 for(int j=0;j<4;j++){
    794                         for(int l=0;l<4;l++){
    795                                 if(this->board[i][j][0][l]!= mini4DgamePlayerColor::none
    796                                                    && this->board[i][j][0][l]==this->board[i][j][1][l]
    797                                                    && this->board[i][j][1][l]==this->board[i][j][2][l]
    798                                                    && this->board[i][j][2][l]==this->board[i][j][3][l])
    799                                 {
    800                                         winner.color_ = this->board[i][j][0][l];
    801                                                 for(int x=0; x<4; x++){
    802                                                         winner.winningRow[x] = i;
    803                                                         winner.winningColumn[x] = j;
    804                                                         winner.winningHeight[x] = x;
    805                                                         winner.winningNumber[x] = l;
    806                                                 }
    807                                                 return winner;
    808                                 }
    809                         }
    810                 }
    811         }
    812 
    813         //check numbers
    814         for(int i=0;i<4;i++){
    815                 for(int j=0;j<4;j++){
    816                         for(int k=0;k<4;k++){
    817                                 if(this->board[i][j][k][0]!= mini4DgamePlayerColor::none
    818                                                    && this->board[i][j][k][0]==this->board[i][j][k][1]
    819                                                    && this->board[i][j][k][1]==this->board[i][j][k][2]
    820                                                    && this->board[i][j][k][2]==this->board[i][j][k][3])
    821                                 {
    822                                         winner.color_ = this->board[i][j][k][0];
    823                                                 for(int x=0; x<4; x++){
    824                                                         winner.winningRow[x] = i;
    825                                                         winner.winningColumn[x] = j;
    826                                                         winner.winningHeight[x] = k;
    827                                                         winner.winningNumber[x] = x;
    828                                                 }
    829                                                 return winner;
    830                                 }
    831                         }
    832                 }
    833         }
    834         return winner;
    835     }
    83698}
  • code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4DgameCenterpoint.h

    r10121 r10131  
    4141#include "worldentities/StaticEntity.h"
    4242#include "mini4Dgame/Mini4DgamePrereqs.h"
    43 #include "mini4Dgame/Mini4Dgame.h"
     43//#include "mini4Dgame/Mini4Dgame.h"
    4444
    4545namespace orxonox
    4646{
    47    
    4847    /**
    4948    @brief
    5049        The Mini4DgameCenterpoint implements the playing field @ref orxonox::Mini4Dgame "Mini4Dgame" takes place in and allows for many parameters of the minigame to be set.
    5150       
    52         Various parameters can be set:
    53         - The <b>dimension</b> is a vector, that defines the width and height of the playing field. The default is <em>(200, 120)</em>.
    54         - The <b>balltemplate</b> is a template that is applied to the @ref orxonox::PongBall "PongBall", it can be used to attach different things to it, e.g. its @ref orxonox::Model "Model". See below for a usage example.
    55         - The <b>battemplate</b> is a template that is applied to the @ref orxonox::PongBall "PongBat", it can be used to attach different things to it, e.g. its @ref orxonox::Model "Model". See below for a usage example.
    56         - The <b>ballspeed</b> is the speed with which the @ref orxonox::PongBall "PongBall" moves. The default is <em>100</em>.
    57         - The <b>ballaccfactor</b> is the acceleration factor for the @ref orxonox::PongBall "PongBall". The default is <em>1.0</em>.
    58         - The <b>batspeed</b> is the speed with which the @ref orxonox::PongBat "PongBats" move. The default is <em>60</em>.
    59         - The <b>batlength</b> is the length of the @ref orxonox::PongBat "PongBats" as the percentage of the height of the playing field. The default is <em>0.25</em>.
    6051    */
    6152    class _Mini4DgameExport Mini4DgameCenterpoint : public StaticEntity
     
    7061
    7162            /**
    72             @brief Set the template for the ball. (e.g. to attach the model of the ball, but also to attach an EventListener to it to detect, when it hits the boundaries, and e.g. display some ParticleEffets, when it does.)
    73             @param balltemplate The name of the template to be set.
     63            @brief Get the template of the board.
     64            @return Returns the name of the template of the board.
     65            */
     66            const std::string& getBoardtemplate() const
     67                { return this->boardtemplate_; }
    7468
    75             void setBalltemplate(const std::string& balltemplate)
    76                 { this->balltemplate_ = balltemplate; }
    77             */
    7869
    7970            /**
    80             @brief Get the template of the ball.
    81             @return Returns the name of the template of the ball.
     71            @brief Set the template for the board.
     72            @param boardtemplate The name of the template to be set.
     73            */
     74            void setBoardtemplate(const std::string& boardtemplate)
     75                { this->boardtemplate_ = boardtemplate; }
    8276
    83             const std::string& getBalltemplate() const
    84                 { return this->balltemplate_; }
    85             */
    86 
    87             /**
    88             @brief Set the template for the bats. (e.g. to attach the model of the bat, but also to attach CameraPositions to it, to be able to view the game from the bats perspective)
    89             @param battemplate The name of the template to be set.
    90 
    91             void setBattemplate(const std::string& battemplate)
    92                 { this->battemplate_ = battemplate; }
    93             */
    9477
    9578            /**
     
    10689                { return Vector3(this->width_, this->height_, this->length_); }
    10790
    108             /**
    109                     @brief checks if the move is valid
    110                     @param the position where to put the stone plus the player who makes the move
    111             */
    112             bool isValidMove(const Vector4 move);
    113 
    114             /**
    115                @brief makes a move on the logic playboard
    116                    @param the position where to put the stone plus the player who makes the move
    117              */
    118             void makeMove(const Vector4 move, const mini4DgamePlayerColor::color playerColor);
    119 
    120             /**
    121                @brief checks if somebody has won
    122                @return the winner with the winning fields or a winner with winner.color_ == mini4DgamePlayerColor::none if nobody has won so far.
    123             */
    124             Mini4DgameWinner Mini4DgameCenterpoint::getWinner();
    125 
    12691        private:
    12792            void checkGametype(); //!< Checks whether the gametype is Mini4Dgame and if it is, sets its centerpoint.
    12893
    129             //std::string balltemplate_; //!< The template for the ball.
    130             //std::string battemplate_; //!< The template for the bats.
     94            std::string boardtemplate_; //!< The template for the board.
    13195
    13296            float width_; //!< The height of the playing field.
    13397            float height_; //!< The width of the playing field.
    13498            float length_; //!< The length of the playing field.
    135             mini4DgamePlayerColor::color board[4][4][4][4]; //!< The logical board where the game takes place. board[row][column][height][number]
    13699    };
    137100}
  • code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4DgamePrereqs.h

    r10104 r10131  
    6969{
    7070    class Mini4Dgame;
     71    class Mini4DgameBoard;
    7172    class Mini4DgameCenterpoint;
    7273}
Note: See TracChangeset for help on using the changeset viewer.