[Orxonox-commit 5452] r10115 - in code/branches/minigame4DHS14: data/levels src/modules/mini4Dgame

richtero at orxonox.net richtero at orxonox.net
Wed Nov 5 16:39:32 CET 2014


Author: richtero
Date: 2014-11-05 16:39:31 +0100 (Wed, 05 Nov 2014)
New Revision: 10115

Modified:
   code/branches/minigame4DHS14/data/levels/4Dtest.oxw
   code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4Dgame.h
   code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4DgameCenterpoint.cc
   code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4DgameCenterpoint.h
Log:
started programming game logic

Modified: code/branches/minigame4DHS14/data/levels/4Dtest.oxw
===================================================================
--- code/branches/minigame4DHS14/data/levels/4Dtest.oxw	2014-11-05 15:33:51 UTC (rev 10114)
+++ code/branches/minigame4DHS14/data/levels/4Dtest.oxw	2014-11-05 15:39:31 UTC (rev 10115)
@@ -48,23 +48,26 @@
     <Light type=directional position="0,0,0" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0"/>
     
     
-    <SpawnPoint position="-200,200,100" lookat="0,0,0" />
+    <SpawnPoint position="-330,330,165" lookat="0,0,0" />
 
 	<Mini4DgameCenterpoint name=mini4Dgamecenter width=16 height=16 length=16 position="0,0,0">
         <attached>
         	<?lua
         	for i = -90, 90, 60
+        	do
         	?>
         		<?lua
         		for j = -90, 90, 60
+        		do
         		?>
         			<?lua
         			for k = -90, 90, 60
+        			do
         			?>
         				<Model
         				position="<?lua print(i) ?>,<?lua print(j) ?>,<?lua print(k) ?>"
-        				mesh="ast1.mesh"
-        				scale="1" />
+        				mesh="checkPoint.mesh"
+        				scale="5" />
         			<?lua
     		  		end
     				?>

Modified: code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4Dgame.h
===================================================================
--- code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4Dgame.h	2014-11-05 15:33:51 UTC (rev 10114)
+++ code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4Dgame.h	2014-11-05 15:39:31 UTC (rev 10115)
@@ -39,6 +39,24 @@
 
 namespace orxonox
 {
+	namespace mini4DgamePlayerColor
+	{
+		enum color
+		{
+			none,
+			red,
+			blue,
+			green
+		};
+	}
+
+	struct Mini4DgamePlayer
+	{
+	    Player player;
+	    mini4DgamePlayerColor::color color_;
+	};
+
+
     /**
     @brief
 
@@ -72,7 +90,7 @@
         private:
             void cleanup(void); //!< Cleans up the Gametype by destroying the ball and the bats.
 
-          Player players[3];
+          Mini4DgamePlayer players[2];
 
             WeakPtr<Mini4DgameCenterpoint> center_; //!< The playing field.
 

Modified: code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4DgameCenterpoint.cc
===================================================================
--- code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4DgameCenterpoint.cc	2014-11-05 15:33:51 UTC (rev 10114)
+++ code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4DgameCenterpoint.cc	2014-11-05 15:39:31 UTC (rev 10115)
@@ -54,6 +54,16 @@
         this->height_ = 200;
         this->length_ = 200;
 
+        for(int i=0;i<4;i++){
+        	for(int j=0;j<4;j++){
+        		for(int k=0;k<4;k++){
+        			for(int l=0;l<4;l++){
+        				this->board[i][j][k][l]=mini4DgamePlayerColor::none;
+        			}
+        		}
+        	}
+        }
+
         this->checkGametype();
     }
 
@@ -92,4 +102,298 @@
             Mini4DgameGametype->setCenterpoint(this);
         }
     }
+
+    /**
+        @brief checks if the move is valid
+        @param the position where to put the stone plus the player who makes the move
+    */
+    bool Mini4DgameCenterpoint::isValidMove(const Vector4 move)
+    {
+    	return (this->board[(int)move.x][(int)move.y][(int)move.z][(int)move.w] == mini4DgamePlayerColor::none);
+    }
+
+    /**
+    @brief makes a move on the logic playboard
+    @param the position where to put the stone plus the player who makes the move
+    */
+    void Mini4DgameCenterpoint::makeMove(const Vector4 move, const mini4DgamePlayerColor::color playerColor)
+    {
+    	if(this->isValidMove(move))
+    	{
+    		this->board[(int)move.x][(int)move.y][(int)move.z][(int)move.w] = playerColor;
+    		mini4DgamePlayerColor::color winner = this->getWinner();
+    		if(winner != mini4DgamePlayerColor::none)
+    		{
+    			Mini4Dgame->win(winner);
+    		}
+    	}
+    }
+
+    mini4DgamePlayerColor::color Mini4DgameCenterpoint::getWinner()
+    {
+    	//check diagonals rows-columns-height-numbers
+		for(int i=1; i<4; i++)
+		{
+			if(this->board[i][i][i][i]==mini4DgamePlayerColor::none || this->board[0][0][0][0] != this->board[i][i][i][i])
+				break;
+			if(i==3)
+				return this->board[0][0][0][0];
+		}
+		for(int i=1; i<4; i++)
+		{
+			if(this->board[3-i][i][i][i]==mini4DgamePlayerColor::none || this->board[3][0][0][0] != this->board[3-i][i][i][i])
+				break;
+			if(i==3)
+				return this->board[3][0][0][0];
+		}
+		for(int i=1; i<4; i++)
+		{
+			if(this->board[i][3-i][i][i]==mini4DgamePlayerColor::none || this->board[0][3][0][0] != this->board[i][3-i][i][i])
+				break;
+			if(i==3)
+				return this->board[0][3][0][0];
+		}
+		for(int i=1; i<4; i++)
+		{
+			if(this->board[i][i][3-i][i]==mini4DgamePlayerColor::none || this->board[0][0][3][0] != this->board[i][i][3-i][i])
+				break;
+			if(i==3)
+				return this->board[0][0][3][0];
+		}
+		for(int i=1; i<4; i++)
+		{
+			if(this->board[i][i][i][3-i]==mini4DgamePlayerColor::none || this->board[0][0][0][3] != this->board[i][i][i][3-i])
+				break;
+			if(i==3)
+				return this->board[0][0][0][3];
+		}
+		for(int i=1; i<4; i++)
+		{
+			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])
+				break;
+			if(i==3)
+				return this->board[3][3][0][0];
+		}
+		for(int i=1; i<4; i++)
+		{
+			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])
+				break;
+			if(i==3)
+				return this->board[3][0][3][0];
+		}
+		for(int i=1; i<4; i++)
+		{
+			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])
+				break;
+			if(i==3)
+				return this->board[3][0][0][3];
+		}
+
+		//check diagonals rows-columns-height
+		for(int l=0; l<4; l++)
+		{
+			for(int i=1; i<4; i++)
+			{
+				if(this->board[i][i][i][l]==mini4DgamePlayerColor::none || this->board[0][0][0][l] != this->board[i][i][i][l])
+					break;
+				if(i==3)
+					return this->board[0][0][0][l];
+			}
+			for(int i=1; i<4; i++)
+			{
+				if(this->board[3-i][i][i][l]==mini4DgamePlayerColor::none || this->board[3][0][0][l] != this->board[3-i][i][i][l])
+					break;
+				if(i==3)
+					return this->board[3][0][0][l];
+			}
+			for(int i=1; i<4; i++)
+			{
+				if(this->board[i][3-i][i][l]==mini4DgamePlayerColor::none || this->board[0][3][0][l] != this->board[i][3-i][i][l])
+					break;
+				if(i==3)
+					return this->board[0][3][0][l];
+			}
+			for(int i=1; i<4; i++)
+			{
+				if(this->board[i][i][3-i][l]==mini4DgamePlayerColor::none || this->board[0][0][3][l] != this->board[i][i][3-i][l])
+					break;
+				if(i==3)
+					return this->board[0][0][3][l];
+			}
+		}
+
+		//check diagonals rows-columns-numbers
+		for(int l=0; l<4; l++)
+		{
+			for(int i=1; i<4; i++)
+			{
+				if(this->board[i][i][l][i]==mini4DgamePlayerColor::none || this->board[0][0][l][0] != this->board[i][i][l][i])
+					break;
+				if(i==3)
+					return this->board[0][0][l][0];
+			}
+			for(int i=1; i<4; i++)
+			{
+				if(this->board[3-i][i][l][i]==mini4DgamePlayerColor::none || this->board[3][0][l][0] != this->board[3-i][i][l][i])
+					break;
+				if(i==3)
+					return this->board[3][0][l][0];
+			}
+			for(int i=1; i<4; i++)
+			{
+				if(this->board[i][3-i][l][i]==mini4DgamePlayerColor::none || this->board[0][3][l][0] != this->board[i][3-i][l][i])
+					break;
+				if(i==3)
+					return this->board[0][3][l][0];
+			}
+			for(int i=1; i<4; i++)
+			{
+				if(this->board[i][i][l][3-i]==mini4DgamePlayerColor::none || this->board[0][0][l][3] != this->board[i][i][l][3-i])
+					break;
+				if(i==3)
+					return this->board[0][0][l][3];
+			}
+		}
+
+		//check diagonals rows-height-numbers
+		for(int l=0; l<4; l++)
+		{
+			for(int i=1; i<4; i++)
+			{
+				if(this->board[i][l][i][i]==mini4DgamePlayerColor::none || this->board[0][l][0][0] != this->board[i][l][i][i])
+					break;
+				if(i==3)
+					return this->board[0][l][0][0];
+			}
+			for(int i=1; i<4; i++)
+			{
+				if(this->board[3-i][l][i][i]==mini4DgamePlayerColor::none || this->board[3][l][0][0] != this->board[3-i][l][i][i])
+					break;
+				if(i==3)
+					return this->board[3][l][0][0];
+			}
+			for(int i=1; i<4; i++)
+			{
+				if(this->board[i][l][3-i][i]==mini4DgamePlayerColor::none || this->board[0][l][3][0] != this->board[i][l][3-i][i])
+					break;
+				if(i==3)
+					return this->board[0][l][3][0];
+			}
+			for(int i=1; i<4; i++)
+			{
+				if(this->board[i][l][i][3-i]==mini4DgamePlayerColor::none || this->board[0][l][0][3] != this->board[i][l][i][3-i])
+					break;
+				if(i==3)
+					return this->board[0][l][0][3];
+			}
+		}
+
+		//check diagonals columns-height-numbers
+		for(int l=0; l<4; l++)
+		{
+			for(int i=1; i<4; i++)
+			{
+				if(this->board[l][i][i][i]==mini4DgamePlayerColor::none || this->board[l][0][0][0] != this->board[l][i][i][i])
+					break;
+				if(i==3)
+					return this->board[l][0][0][0];
+			}
+			for(int i=1; i<4; i++)
+			{
+				if(this->board[l][3-i][i][i]==mini4DgamePlayerColor::none || this->board[l][3][0][0] != this->board[l][3-i][i][i])
+					break;
+				if(i==3)
+					return this->board[l][3][0][0];
+			}
+			for(int i=1; i<4; i++)
+			{
+				if(this->board[l][i][3-i][i]==mini4DgamePlayerColor::none || this->board[l][0][3][0] != this->board[l][i][3-i][i])
+					break;
+				if(i==3)
+					return this->board[l][0][3][0];
+			}
+			for(int i=1; i<4; i++)
+			{
+				if(this->board[l][i][i][3-i]==mini4DgamePlayerColor::none || this->board[l][0][0][3] != this->board[l][i][i][3-i])
+					break;
+				if(i==3)
+					return this->board[l][0][0][3];
+			}
+		}
+
+		//check diagonals rows-columns
+		for(int k=0;k<4;k++){
+    		for(int l=0;l<4;l++){
+    			for(int i=1; i<4; i++)
+				{
+					if(this->board[i][i][k][l]==mini4DgamePlayerColor::none || this->board[0][0][l][0] != this->board[i][i][l][i])
+						break;
+					if(i==3)
+						return this->board[0][0][l][0];
+				}}}
+    	//-------------------------------------------------------------------------------------------------------
+
+    	//check rows
+    	for(int j=0;j<4;j++){
+    		for(int k=0;k<4;k++){
+    			for(int l=0;l<4;l++){
+    				if(this->board[0][j][k][l]!= mini4DgamePlayerColor::none
+    				   && this->board[0][j][k][l]==this->board[1][j][k][l]
+    				   && this->board[1][j][k][l]==this->board[2][j][k][l]
+    				   && this->board[2][j][k][l]==this->board[3][j][k][l])
+    				{
+    					return this->board[0][j][k][l];
+    				}
+    			}
+    		}
+    	}
+
+    	//check columns
+    	for(int i=0;i<4;i++){
+    		for(int k=0;k<4;k++){
+    			for(int l=0;l<4;l++){
+    				if(this->board[i][0][k][l]!= mini4DgamePlayerColor::none
+    	    				   && this->board[i][0][k][l]==this->board[i][1][k][l]
+    	    				   && this->board[i][1][k][l]==this->board[i][2][k][l]
+    	    				   && this->board[i][2][k][l]==this->board[i][3][k][l])
+    				{
+    	    			return this->board[i][0][k][l];
+    				}
+    			}
+    		}
+    	}
+
+    	//check height
+    	for(int i=0;i<4;i++){
+    		for(int j=0;j<4;j++){
+    			for(int l=0;l<4;l++){
+    				if(this->board[i][j][0][l]!= mini4DgamePlayerColor::none
+    	    	    				   && this->board[i][j][0][l]==this->board[i][j][1][l]
+    	    	    				   && this->board[i][j][1][l]==this->board[i][j][2][l]
+    	    	    				   && this->board[i][j][2][l]==this->board[i][j][3][l])
+    				{
+    					return this->board[i][j][0][l];
+    				}
+    			}
+    		}
+    	}
+
+    	//check numbers
+    	for(int i=0;i<4;i++){
+    		for(int j=0;j<4;j++){
+    			for(int k=0;k<4;k++){
+    				if(this->board[i][j][k][0]!= mini4DgamePlayerColor::none
+    	    	    				   && this->board[i][j][k][0]==this->board[i][j][k][1]
+    	    	    				   && this->board[i][j][k][1]==this->board[i][j][k][2]
+    	    	    				   && this->board[i][j][k][2]==this->board[i][j][k][3])
+    				{
+    					return this->board[i][j][k][0];
+    				}
+    			}
+    		}
+    	}
+
+
+    	return mini4DgamePlayerColor::none;
+    }
 }

Modified: code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4DgameCenterpoint.h
===================================================================
--- code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4DgameCenterpoint.h	2014-11-05 15:33:51 UTC (rev 10114)
+++ code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4DgameCenterpoint.h	2014-11-05 15:39:31 UTC (rev 10115)
@@ -104,7 +104,24 @@
             Vector3 getFieldDimension() const
                 { return Vector3(this->width_, this->height_, this->length_); }
 
+            /**
+                    @brief checks if the move is valid
+                    @param the position where to put the stone plus the player who makes the move
+            */
+            bool isValidMove(const Vector4 move,const int playerColor);
 
+            /**
+               @brief makes a move on the logic playboard
+           	   @param the position where to put the stone plus the player who makes the move
+             */
+            void makeMove(const Vector4 move, const int player);
+
+            /**
+                @brief searches the board if somebody has won
+				@return the winner if somebody has won or mini4DgamePlayerColor::none if nobody has won so far
+             */
+            mini4DgamePlayerColor::color Mini4DgameCenterpoint::getWinner()
+
         private:
             void checkGametype(); //!< Checks whether the gametype is Mini4Dgame and if it is, sets its centerpoint.
 
@@ -114,6 +131,7 @@
             float width_; //!< The height of the playing field.
             float height_; //!< The width of the playing field.
             float length_; //!< The length of the playing field.
+            mini4DgamePlayerColor::color board[4][4][4][4]; //!< The logical board where the game takes place. board[row][column][height][number]
     };
 }
 




More information about the Orxonox-commit mailing list