Changeset 10115 for code/branches/minigame4DHS14/src
- Timestamp:
- Nov 5, 2014, 4:39:31 PM (10 years ago)
- Location:
- code/branches/minigame4DHS14/src/modules/mini4Dgame
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4Dgame.h
r10101 r10115 40 40 namespace orxonox 41 41 { 42 namespace mini4DgamePlayerColor 43 { 44 enum color 45 { 46 none, 47 red, 48 blue, 49 green 50 }; 51 } 52 53 struct Mini4DgamePlayer 54 { 55 Player player; 56 mini4DgamePlayerColor::color color_; 57 }; 58 59 42 60 /** 43 61 @brief … … 73 91 void cleanup(void); //!< Cleans up the Gametype by destroying the ball and the bats. 74 92 75 Player players[3];93 Mini4DgamePlayer players[2]; 76 94 77 95 WeakPtr<Mini4DgameCenterpoint> center_; //!< The playing field. -
code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4DgameCenterpoint.cc
r10097 r10115 54 54 this->height_ = 200; 55 55 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 } 56 66 57 67 this->checkGametype(); … … 93 103 } 94 104 } 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 mini4DgamePlayerColor::color winner = this->getWinner(); 125 if(winner != mini4DgamePlayerColor::none) 126 { 127 Mini4Dgame->win(winner); 128 } 129 } 130 } 131 132 mini4DgamePlayerColor::color Mini4DgameCenterpoint::getWinner() 133 { 134 //check diagonals rows-columns-height-numbers 135 for(int i=1; i<4; i++) 136 { 137 if(this->board[i][i][i][i]==mini4DgamePlayerColor::none || this->board[0][0][0][0] != this->board[i][i][i][i]) 138 break; 139 if(i==3) 140 return this->board[0][0][0][0]; 141 } 142 for(int i=1; i<4; i++) 143 { 144 if(this->board[3-i][i][i][i]==mini4DgamePlayerColor::none || this->board[3][0][0][0] != this->board[3-i][i][i][i]) 145 break; 146 if(i==3) 147 return this->board[3][0][0][0]; 148 } 149 for(int i=1; i<4; i++) 150 { 151 if(this->board[i][3-i][i][i]==mini4DgamePlayerColor::none || this->board[0][3][0][0] != this->board[i][3-i][i][i]) 152 break; 153 if(i==3) 154 return this->board[0][3][0][0]; 155 } 156 for(int i=1; i<4; i++) 157 { 158 if(this->board[i][i][3-i][i]==mini4DgamePlayerColor::none || this->board[0][0][3][0] != this->board[i][i][3-i][i]) 159 break; 160 if(i==3) 161 return this->board[0][0][3][0]; 162 } 163 for(int i=1; i<4; i++) 164 { 165 if(this->board[i][i][i][3-i]==mini4DgamePlayerColor::none || this->board[0][0][0][3] != this->board[i][i][i][3-i]) 166 break; 167 if(i==3) 168 return this->board[0][0][0][3]; 169 } 170 for(int i=1; i<4; i++) 171 { 172 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]) 173 break; 174 if(i==3) 175 return this->board[3][3][0][0]; 176 } 177 for(int i=1; i<4; i++) 178 { 179 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]) 180 break; 181 if(i==3) 182 return this->board[3][0][3][0]; 183 } 184 for(int i=1; i<4; i++) 185 { 186 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]) 187 break; 188 if(i==3) 189 return this->board[3][0][0][3]; 190 } 191 192 //check diagonals rows-columns-height 193 for(int l=0; l<4; l++) 194 { 195 for(int i=1; i<4; i++) 196 { 197 if(this->board[i][i][i][l]==mini4DgamePlayerColor::none || this->board[0][0][0][l] != this->board[i][i][i][l]) 198 break; 199 if(i==3) 200 return this->board[0][0][0][l]; 201 } 202 for(int i=1; i<4; i++) 203 { 204 if(this->board[3-i][i][i][l]==mini4DgamePlayerColor::none || this->board[3][0][0][l] != this->board[3-i][i][i][l]) 205 break; 206 if(i==3) 207 return this->board[3][0][0][l]; 208 } 209 for(int i=1; i<4; i++) 210 { 211 if(this->board[i][3-i][i][l]==mini4DgamePlayerColor::none || this->board[0][3][0][l] != this->board[i][3-i][i][l]) 212 break; 213 if(i==3) 214 return this->board[0][3][0][l]; 215 } 216 for(int i=1; i<4; i++) 217 { 218 if(this->board[i][i][3-i][l]==mini4DgamePlayerColor::none || this->board[0][0][3][l] != this->board[i][i][3-i][l]) 219 break; 220 if(i==3) 221 return this->board[0][0][3][l]; 222 } 223 } 224 225 //check diagonals rows-columns-numbers 226 for(int l=0; l<4; l++) 227 { 228 for(int i=1; i<4; i++) 229 { 230 if(this->board[i][i][l][i]==mini4DgamePlayerColor::none || this->board[0][0][l][0] != this->board[i][i][l][i]) 231 break; 232 if(i==3) 233 return this->board[0][0][l][0]; 234 } 235 for(int i=1; i<4; i++) 236 { 237 if(this->board[3-i][i][l][i]==mini4DgamePlayerColor::none || this->board[3][0][l][0] != this->board[3-i][i][l][i]) 238 break; 239 if(i==3) 240 return this->board[3][0][l][0]; 241 } 242 for(int i=1; i<4; i++) 243 { 244 if(this->board[i][3-i][l][i]==mini4DgamePlayerColor::none || this->board[0][3][l][0] != this->board[i][3-i][l][i]) 245 break; 246 if(i==3) 247 return this->board[0][3][l][0]; 248 } 249 for(int i=1; i<4; i++) 250 { 251 if(this->board[i][i][l][3-i]==mini4DgamePlayerColor::none || this->board[0][0][l][3] != this->board[i][i][l][3-i]) 252 break; 253 if(i==3) 254 return this->board[0][0][l][3]; 255 } 256 } 257 258 //check diagonals rows-height-numbers 259 for(int l=0; l<4; l++) 260 { 261 for(int i=1; i<4; i++) 262 { 263 if(this->board[i][l][i][i]==mini4DgamePlayerColor::none || this->board[0][l][0][0] != this->board[i][l][i][i]) 264 break; 265 if(i==3) 266 return this->board[0][l][0][0]; 267 } 268 for(int i=1; i<4; i++) 269 { 270 if(this->board[3-i][l][i][i]==mini4DgamePlayerColor::none || this->board[3][l][0][0] != this->board[3-i][l][i][i]) 271 break; 272 if(i==3) 273 return this->board[3][l][0][0]; 274 } 275 for(int i=1; i<4; i++) 276 { 277 if(this->board[i][l][3-i][i]==mini4DgamePlayerColor::none || this->board[0][l][3][0] != this->board[i][l][3-i][i]) 278 break; 279 if(i==3) 280 return this->board[0][l][3][0]; 281 } 282 for(int i=1; i<4; i++) 283 { 284 if(this->board[i][l][i][3-i]==mini4DgamePlayerColor::none || this->board[0][l][0][3] != this->board[i][l][i][3-i]) 285 break; 286 if(i==3) 287 return this->board[0][l][0][3]; 288 } 289 } 290 291 //check diagonals columns-height-numbers 292 for(int l=0; l<4; l++) 293 { 294 for(int i=1; i<4; i++) 295 { 296 if(this->board[l][i][i][i]==mini4DgamePlayerColor::none || this->board[l][0][0][0] != this->board[l][i][i][i]) 297 break; 298 if(i==3) 299 return this->board[l][0][0][0]; 300 } 301 for(int i=1; i<4; i++) 302 { 303 if(this->board[l][3-i][i][i]==mini4DgamePlayerColor::none || this->board[l][3][0][0] != this->board[l][3-i][i][i]) 304 break; 305 if(i==3) 306 return this->board[l][3][0][0]; 307 } 308 for(int i=1; i<4; i++) 309 { 310 if(this->board[l][i][3-i][i]==mini4DgamePlayerColor::none || this->board[l][0][3][0] != this->board[l][i][3-i][i]) 311 break; 312 if(i==3) 313 return this->board[l][0][3][0]; 314 } 315 for(int i=1; i<4; i++) 316 { 317 if(this->board[l][i][i][3-i]==mini4DgamePlayerColor::none || this->board[l][0][0][3] != this->board[l][i][i][3-i]) 318 break; 319 if(i==3) 320 return this->board[l][0][0][3]; 321 } 322 } 323 324 //check diagonals rows-columns 325 for(int k=0;k<4;k++){ 326 for(int l=0;l<4;l++){ 327 for(int i=1; i<4; i++) 328 { 329 if(this->board[i][i][k][l]==mini4DgamePlayerColor::none || this->board[0][0][l][0] != this->board[i][i][l][i]) 330 break; 331 if(i==3) 332 return this->board[0][0][l][0]; 333 }}} 334 //------------------------------------------------------------------------------------------------------- 335 336 //check rows 337 for(int j=0;j<4;j++){ 338 for(int k=0;k<4;k++){ 339 for(int l=0;l<4;l++){ 340 if(this->board[0][j][k][l]!= mini4DgamePlayerColor::none 341 && this->board[0][j][k][l]==this->board[1][j][k][l] 342 && this->board[1][j][k][l]==this->board[2][j][k][l] 343 && this->board[2][j][k][l]==this->board[3][j][k][l]) 344 { 345 return this->board[0][j][k][l]; 346 } 347 } 348 } 349 } 350 351 //check columns 352 for(int i=0;i<4;i++){ 353 for(int k=0;k<4;k++){ 354 for(int l=0;l<4;l++){ 355 if(this->board[i][0][k][l]!= mini4DgamePlayerColor::none 356 && this->board[i][0][k][l]==this->board[i][1][k][l] 357 && this->board[i][1][k][l]==this->board[i][2][k][l] 358 && this->board[i][2][k][l]==this->board[i][3][k][l]) 359 { 360 return this->board[i][0][k][l]; 361 } 362 } 363 } 364 } 365 366 //check height 367 for(int i=0;i<4;i++){ 368 for(int j=0;j<4;j++){ 369 for(int l=0;l<4;l++){ 370 if(this->board[i][j][0][l]!= mini4DgamePlayerColor::none 371 && this->board[i][j][0][l]==this->board[i][j][1][l] 372 && this->board[i][j][1][l]==this->board[i][j][2][l] 373 && this->board[i][j][2][l]==this->board[i][j][3][l]) 374 { 375 return this->board[i][j][0][l]; 376 } 377 } 378 } 379 } 380 381 //check numbers 382 for(int i=0;i<4;i++){ 383 for(int j=0;j<4;j++){ 384 for(int k=0;k<4;k++){ 385 if(this->board[i][j][k][0]!= mini4DgamePlayerColor::none 386 && this->board[i][j][k][0]==this->board[i][j][k][1] 387 && this->board[i][j][k][1]==this->board[i][j][k][2] 388 && this->board[i][j][k][2]==this->board[i][j][k][3]) 389 { 390 return this->board[i][j][k][0]; 391 } 392 } 393 } 394 } 395 396 397 return mini4DgamePlayerColor::none; 398 } 95 399 } -
code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4DgameCenterpoint.h
r10101 r10115 105 105 { return Vector3(this->width_, this->height_, this->length_); } 106 106 107 /** 108 @brief checks if the move is valid 109 @param the position where to put the stone plus the player who makes the move 110 */ 111 bool isValidMove(const Vector4 move,const int playerColor); 112 113 /** 114 @brief makes a move on the logic playboard 115 @param the position where to put the stone plus the player who makes the move 116 */ 117 void makeMove(const Vector4 move, const int player); 118 119 /** 120 @brief searches the board if somebody has won 121 @return the winner if somebody has won or mini4DgamePlayerColor::none if nobody has won so far 122 */ 123 mini4DgamePlayerColor::color Mini4DgameCenterpoint::getWinner() 107 124 108 125 private: … … 115 132 float height_; //!< The width of the playing field. 116 133 float length_; //!< The length of the playing field. 134 mini4DgamePlayerColor::color board[4][4][4][4]; //!< The logical board where the game takes place. board[row][column][height][number] 117 135 }; 118 136 }
Note: See TracChangeset
for help on using the changeset viewer.