[Orxonox-commit 5458] r10121 - code/branches/minigame4DHS14/src/modules/mini4Dgame

richtero at orxonox.net richtero at orxonox.net
Wed Nov 12 16:07:11 CET 2014


Author: richtero
Date: 2014-11-12 16:07:10 +0100 (Wed, 12 Nov 2014)
New Revision: 10121

Added:
   code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4DgameAI.cc
   code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4DgameAI.h
Modified:
   code/branches/minigame4DHS14/src/modules/mini4Dgame/CMakeLists.txt
   code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4Dgame.cc
   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:
finished getWinner function which checks if somebody has won and started on the AI.

Modified: code/branches/minigame4DHS14/src/modules/mini4Dgame/CMakeLists.txt
===================================================================
--- code/branches/minigame4DHS14/src/modules/mini4Dgame/CMakeLists.txt	2014-11-12 15:04:45 UTC (rev 10120)
+++ code/branches/minigame4DHS14/src/modules/mini4Dgame/CMakeLists.txt	2014-11-12 15:07:10 UTC (rev 10121)
@@ -1,5 +1,6 @@
 SET_SOURCE_FILES(Mini4Dgame_SRC_FILES
   Mini4Dgame.cc
+  Mini4DgameAI.cc
   Mini4DgameCenterpoint.cc
 )
 

Modified: code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4Dgame.cc
===================================================================
--- code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4Dgame.cc	2014-11-12 15:04:45 UTC (rev 10120)
+++ code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4Dgame.cc	2014-11-12 15:07:10 UTC (rev 10121)
@@ -169,19 +169,4 @@
     }
 
 
-    /**
-    @brief
-        Get the player.
-    @return
-        Returns a pointer to the player. If there is no player, NULL is returned.
-    */
-    //TODO: colors
-    PlayerInfo* Mini4Dgame::getPlayer(int color) const
-    {
-        return players[color].info_;
-    	//for(int i=0;i<NUMBEROFPLAYERS;i++)
-        	//if(color == this->mini4DgamePlayers[i].color)
-        		//return this->mini4DgamePlayers[i].info;
-    }
-
 }

Modified: code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4Dgame.h
===================================================================
--- code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4Dgame.h	2014-11-12 15:04:45 UTC (rev 10120)
+++ code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4Dgame.h	2014-11-12 15:07:10 UTC (rev 10121)
@@ -56,7 +56,14 @@
 	    mini4DgamePlayerColor::color color_;
 	};
 
-
+	struct Mini4DgameWinner
+	{
+		int winningRow[4];
+		int winningColumn[4];
+		int winningHeight[4];
+		int winningNumber[4];
+		mini4DgamePlayerColor::color color_;
+	};
     /**
     @brief
 
@@ -77,12 +84,8 @@
             void setCenterpoint(Mini4DgameCenterpoint* center)
             	{ this->center_ = center; }
 
-//TODO: enum colors
-            PlayerInfo* getPlayer(int color) const; //!< Get the player with the specified color.
+            void win(Mini4DgameWinner winner);
 
-
-            //bool isValidMove(Vector4* move, const Mini4DgameBoard* board);//!< Checks if the move is valid
-
         protected:
             virtual void spawnPlayersIfRequested(); //!< Spawns player.
 
@@ -90,11 +93,9 @@
         private:
             void cleanup(void); //!< Cleans up the Gametype by destroying the ball and the bats.
 
-          Mini4DgamePlayer players[2];
+            Mini4DgamePlayer players[2];
 
             WeakPtr<Mini4DgameCenterpoint> center_; //!< The playing field.
-
-            //TODO: Board is missing up to now
     };
 }
 

Added: code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4DgameAI.cc
===================================================================
--- code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4DgameAI.cc	                        (rev 0)
+++ code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4DgameAI.cc	2014-11-12 15:07:10 UTC (rev 10121)
@@ -0,0 +1,126 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Fabian 'x3n' Landau
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+/**
+    @file Mini4DgameAI.cc
+    @brief Implementation of the Mini4DgameAI class.
+*/
+
+#include "Mini4DgameAI.h"
+
+#include "core/CoreIncludes.h"
+#include "core/config/ConfigValueIncludes.h"
+#include "core/command/Executor.h"
+#include "tools/Timer.h"
+
+#include <list>
+
+#include "worldentities/ControllableEntity.h"
+
+#include "Mini4DgameCenterpoint.h"
+
+namespace orxonox
+{
+    RegisterUnloadableClass(Mini4DgameAI);
+
+    //const static float MAX_REACTION_TIME = 0.4f;
+
+    /**
+    @brief
+        Constructor. Registers and initializes the object.
+    */
+    Mini4DgameAI::Mini4DgameAI(Context* context) : Controller(context)
+    {
+        RegisterObject(Mini4DgameAI);
+
+        this->setConfigValues();
+        this->center_ = 0;
+    }
+
+    /**
+    @brief
+        Destructor. Cleans up the list fo reaction timers.
+    */
+    Mini4DgameAI::~Mini4DgameAI()
+    {
+
+    }
+
+    Vector4 Mini4DgameAI::makeMove(float timeout)
+    {
+    	this->copyBoard();
+    	std::list<Vector4> possibleMoves = this->getPossibleMoves();
+
+    	//TODO: alphabeta ueber possibleMoves
+
+    	//when timeout
+    	Vector4 move = possibleMoves.front();
+    	return move;
+    }
+
+    void Mini4DgameAI::copyBoard()
+    {
+		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]=this->center_->board[i][j][k][l];
+					}
+				}
+			}
+		}
+    }
+
+    std::list<Vector4> Mini4DgameAI::getPossibleMoves()
+    {
+    	std::list<Vector4> possibleMoves = new std::list<Vector4>;
+    	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++){
+						if (this->board_[i][j][k][l]==mini4DgamePlayerColor::none)
+							possibleMoves.push_back(Vector4(i,j,k,l));
+					}
+				}
+			}
+		}
+    	return possibleMoves;
+    }
+
+    /**
+    @brief
+        Is called each tick.
+        Implements the behavior of the PongAI (i.e. its intelligence).
+    @param dt
+        The time that has elapsed since the last tick.
+    */
+    void Mini4DgameAI::tick(float dt)
+    {
+
+    }
+}

Added: code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4DgameAI.h
===================================================================
--- code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4DgameAI.h	                        (rev 0)
+++ code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4DgameAI.h	2014-11-12 15:07:10 UTC (rev 10121)
@@ -0,0 +1,94 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Fabian 'x3n' Landau
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+/**
+    @file Mini4DgameAI.h
+    @brief Declaration of the Mini4DgameAI class.
+*/
+
+#ifndef _Mini4DgameAI_H__
+#define _Mini4DgameAI_H__
+
+#include "mini4Dgame/Mini4DgamePrereqs.h"
+
+#include <list>
+
+#include "tools/interfaces/Tickable.h"
+
+#include "controllers/Controller.h"
+#include "Mini4DgameCenterpoint.h"
+#include "Mini4Dgame.h"
+
+namespace orxonox
+{
+
+    /**
+    @brief
+        The Mini4DgameAI is an artificial intelligence for the @ref orxonox::Mini4Dgame "Mini4Dgame" gametype.
+
+    @author
+        Oliver Richter
+    */
+    class _Mini4DgameExport Mini4DgameAI : public Controller, public Tickable
+    {
+        public:
+    		Mini4DgameAI(Context* context); //!< Constructor. Registers and initializes the object.
+            virtual ~Mini4DgameAI();
+
+            //void setConfigValues();
+
+            /**
+                @brief
+                    starts the AI to make a move. implements the intelligence of the AI
+                @param timeout
+                    The time the AI has to decide on a move. (Sets the strength of the AI)
+                @return move
+                	The move that the AI decided to make.
+            */
+            Vector4 Mini4DgameAI::makeMove(float timeout);
+
+
+            virtual void tick(float dt);
+
+            void setCenterpoint(Mini4DgameCenterpoint* center)
+                        	{ this->center_ = center; }
+
+        protected:
+
+            std::list<std::pair<Timer*, char> > reactionTimers_; //!< A list of reaction timers and the directions that take effect when their timer expires.
+            Mini4DgameCenterpoint* center_;
+
+        private:
+
+            std::list<Vector4> Mini4DgameAI::getPossibleMoves();
+            void Mini4DgameAI::copyBoard();
+            mini4DgamePlayerColor::color board_[4][4][4][4];
+    };
+}
+
+#endif /* _Mini4DgameAI_H__ */

Modified: code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4DgameCenterpoint.cc
===================================================================
--- code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4DgameCenterpoint.cc	2014-11-12 15:04:45 UTC (rev 10120)
+++ code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4DgameCenterpoint.cc	2014-11-12 15:07:10 UTC (rev 10121)
@@ -121,72 +121,147 @@
     	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)
+    		Mini4DgameWinner winner = this->getWinner();
+    		if(winner.color_ != mini4DgamePlayerColor::none)
     		{
     			Mini4Dgame->win(winner);
     		}
     	}
     }
 
-    mini4DgamePlayerColor::color Mini4DgameCenterpoint::getWinner()
+    Mini4DgameWinner Mini4DgameCenterpoint::getWinner()
     {
+    	Mini4DgameWinner winner;
+		winner.color_ = mini4DgamePlayerColor::none;
+
     	//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];
+			{
+				winner.color_ = this->board[0][0][0][0];
+				for(int x=0; x<4; x++){
+					winner.winningRow[x] = x;
+					winner.winningColumn[x] = x;
+					winner.winningHeight[x] = x;
+					winner.winningNumber[x] = x;
+				}
+				return winner;
+			}
 		}
 		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];
+			{
+				winner.color_ = this->board[3][0][0][0];
+				for(int x=0; x<4; x++){
+					winner.winningRow[x] = 3-x;
+					winner.winningColumn[x] = x;
+					winner.winningHeight[x] = x;
+					winner.winningNumber[x] = x;
+				}
+				return winner;
+			}
 		}
 		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];
+			{
+				winner.color_ = this->board[0][3][0][0];
+				for(int x=0; x<4; x++){
+					winner.winningRow[x] = x;
+					winner.winningColumn[x] = 3-x;
+					winner.winningHeight[x] = x;
+					winner.winningNumber[x] = x;
+				}
+				return winner;
+			}
 		}
 		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];
+			{
+				winner.color_ = this->board[0][0][3][0];
+				for(int x=0; x<4; x++){
+					winner.winningRow[x] = x;
+					winner.winningColumn[x] = x;
+					winner.winningHeight[x] = 3-x;
+					winner.winningNumber[x] = x;
+				}
+				return winner;
+			}
 		}
 		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];
+			{
+				winner.color_ = this->board[0][0][0][3];
+				for(int x=0; x<4; x++){
+					winner.winningRow[x] = x;
+					winner.winningColumn[x] = x;
+					winner.winningHeight[x] = x;
+					winner.winningNumber[x] = 3-x;
+				}
+				return winner;
+			}
 		}
 		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];
+			{
+				winner.color_ = this->board[3][3][0][0];
+				for(int x=0; x<4; x++){
+					winner.winningRow[x] = 3-x;
+					winner.winningColumn[x] = 3-x;
+					winner.winningHeight[x] = x;
+					winner.winningNumber[x] = x;
+				}
+				return winner;
+			}
 		}
 		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];
+			{
+				winner.color_ = this->board[3][0][3][0];
+				for(int x=0; x<4; x++){
+					winner.winningRow[x] = 3-x;
+					winner.winningColumn[x] = x;
+					winner.winningHeight[x] = 3-x;
+					winner.winningNumber[x] = x;
+				}
+				return winner;
+			}
 		}
 		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];
+			{
+				winner.color_ = this->board[3][0][0][3];
+				for(int x=0; x<4; x++){
+					winner.winningRow[x] = 3-x;
+					winner.winningColumn[x] = x;
+					winner.winningHeight[x] = x;
+					winner.winningNumber[x] = 3-x;
+				}
+				return winner;
+			}
 		}
 
 		//check diagonals rows-columns-height
@@ -197,28 +272,64 @@
 				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];
+				{
+					winner.color_ = this->board[0][0][0][l];
+					for(int x=0; x<4; x++){
+						winner.winningRow[x] = x;
+						winner.winningColumn[x] = x;
+						winner.winningHeight[x] = x;
+						winner.winningNumber[x] = l;
+					}
+					return winner;
+				}
 			}
 			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];
+				{
+					winner.color_ = this->board[3][0][0][l];
+					for(int x=0; x<4; x++){
+						winner.winningRow[x] = 3-x;
+						winner.winningColumn[x] = x;
+						winner.winningHeight[x] = x;
+						winner.winningNumber[x] = l;
+					}
+					return winner;
+				}
 			}
 			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];
+				{
+					winner.color_ = this->board[0][3][0][l];
+					for(int x=0; x<4; x++){
+						winner.winningRow[x] = x;
+						winner.winningColumn[x] = 3-x;
+						winner.winningHeight[x] = x;
+						winner.winningNumber[x] = l;
+					}
+					return winner;
+				}
 			}
 			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];
+				{
+					winner.color_ = this->board[0][0][3][l];
+					for(int x=0; x<4; x++){
+						winner.winningRow[x] = x;
+						winner.winningColumn[x] = x;
+						winner.winningHeight[x] = 3-x;
+						winner.winningNumber[x] = l;
+					}
+					return winner;
+				}
 			}
 		}
 
@@ -230,28 +341,64 @@
 				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];
+				{
+					winner.color_ = this->board[0][0][l][0];
+					for(int x=0; x<4; x++){
+						winner.winningRow[x] = x;
+						winner.winningColumn[x] = x;
+						winner.winningHeight[x] = l;
+						winner.winningNumber[x] = x;
+					}
+					return winner;
+				}
 			}
 			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];
+				{
+					winner.color_ = this->board[3][0][l][0];
+					for(int x=0; x<4; x++){
+						winner.winningRow[x] = 3-x;
+						winner.winningColumn[x] = x;
+						winner.winningHeight[x] = l;
+						winner.winningNumber[x] = x;
+					}
+					return winner;
+				}
 			}
 			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];
+				{
+					winner.color_ = this->board[0][3][l][0];
+					for(int x=0; x<4; x++){
+						winner.winningRow[x] = x;
+						winner.winningColumn[x] = 3-x;
+						winner.winningHeight[x] = l;
+						winner.winningNumber[x] = x;
+					}
+					return winner;
+				}
 			}
 			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];
+				{
+					winner.color_ = this->board[0][0][l][3];
+					for(int x=0; x<4; x++){
+						winner.winningRow[x] = x;
+						winner.winningColumn[x] = x;
+						winner.winningHeight[x] = l;
+						winner.winningNumber[x] = 3-x;
+					}
+					return winner;
+				}
 			}
 		}
 
@@ -263,28 +410,64 @@
 				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];
+				{
+					winner.color_ = this->board[0][l][0][0];
+					for(int x=0; x<4; x++){
+						winner.winningRow[x] = x;
+						winner.winningColumn[x] = l;
+						winner.winningHeight[x] = x;
+						winner.winningNumber[x] = x;
+					}
+					return winner;
+				}
 			}
 			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];
+				{
+					winner.color_ = this->board[3][l][0][0];
+					for(int x=0; x<4; x++){
+						winner.winningRow[x] = 3-x;
+						winner.winningColumn[x] = l;
+						winner.winningHeight[x] = x;
+						winner.winningNumber[x] = x;
+					}
+					return winner;
+				}
 			}
 			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];
+				{
+					winner.color_ = this->board[0][l][3][0];
+					for(int x=0; x<4; x++){
+						winner.winningRow[x] = x;
+						winner.winningColumn[x] = l;
+						winner.winningHeight[x] = 3-x;
+						winner.winningNumber[x] = x;
+					}
+					return winner;
+				}
 			}
 			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];
+				{
+					winner.color_ = this->board[0][l][0][3];
+					for(int x=0; x<4; x++){
+						winner.winningRow[x] = x;
+						winner.winningColumn[x] = l;
+						winner.winningHeight[x] = x;
+						winner.winningNumber[x] = 3-x;
+					}
+					return winner;
+				}
 			}
 		}
 
@@ -296,42 +479,270 @@
 				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];
+				{
+					winner.color_ = this->board[l][0][0][0];
+					for(int x=0; x<4; x++){
+						winner.winningRow[x] = l;
+						winner.winningColumn[x] = x;
+						winner.winningHeight[x] = x;
+						winner.winningNumber[x] = x;
+					}
+					return winner;
+				}
 			}
 			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];
+				{
+					winner.color_ = this->board[l][3][0][0];
+					for(int x=0; x<4; x++){
+						winner.winningRow[x] = l;
+						winner.winningColumn[x] = 3-x;
+						winner.winningHeight[x] = x;
+						winner.winningNumber[x] = x;
+					}
+					return winner;
+				}
 			}
 			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];
+				{
+					winner.color_ = this->board[l][0][3][0];
+					for(int x=0; x<4; x++){
+						winner.winningRow[x] = l;
+						winner.winningColumn[x] = x;
+						winner.winningHeight[x] = 3-x;
+						winner.winningNumber[x] = x;
+					}
+					return winner;
+				}
 			}
 			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];
+				{
+					winner.color_ = this->board[l][0][0][3];
+					for(int x=0; x<4; x++){
+						winner.winningRow[x] = l;
+						winner.winningColumn[x] = x;
+						winner.winningHeight[x] = x;
+						winner.winningNumber[x] = 3-x;
+					}
+					return winner;
+				}
 			}
 		}
 
-		//check diagonals rows-columns
+		//check 2d diagonals
 		for(int k=0;k<4;k++){
     		for(int l=0;l<4;l++){
+    			//rows-columns
     			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])
+					if(this->board[i][i][k][l]==mini4DgamePlayerColor::none || this->board[0][0][k][l] != this->board[i][i][k][l])
 						break;
 					if(i==3)
-						return this->board[0][0][l][0];
-				}}}
-    	//-------------------------------------------------------------------------------------------------------
+					{
+						winner.color_ = this->board[0][0][k][l];
+						for(int x=0; x<4; x++){
+							winner.winningRow[x] = x;
+							winner.winningColumn[x] = x;
+							winner.winningHeight[x] = k;
+							winner.winningNumber[x] = l;
+						}
+						return winner;
+					}
+				}
+				for(int i=1; i<4; i++)
+				{
+					if(this->board[3-i][i][k][l]==mini4DgamePlayerColor::none || this->board[3][0][k][l] != this->board[3-i][i][k][l])
+						break;
+					if(i==3)
+					{
+						winner.color_ = this->board[3][0][k][l];
+						for(int x=0; x<4; x++){
+							winner.winningRow[x] = 3-x;
+							winner.winningColumn[x] = x;
+							winner.winningHeight[x] = k;
+							winner.winningNumber[x] = l;
+						}
+						return winner;
+					}
+				}
+				//rows-height
+    			for(int i=1; i<4; i++)
+    			{
+    				if(this->board[i][k][i][l]==mini4DgamePlayerColor::none || this->board[0][k][0][l] != this->board[i][k][i][l])
+    					break;
+    				if(i==3)
+    				{
+						winner.color_ = this->board[0][k][0][l];
+						for(int x=0; x<4; x++){
+							winner.winningRow[x] = x;
+							winner.winningColumn[x] = k;
+							winner.winningHeight[x] = x;
+							winner.winningNumber[x] = l;
+						}
+						return winner;
+					}
+				}
+				for(int i=1; i<4; i++)
+    			{
+    				if(this->board[3-i][k][i][l]==mini4DgamePlayerColor::none || this->board[3][k][0][l] != this->board[3-i][k][i][l])
+    					break;
+    				if(i==3)
+    				{
+						winner.color_ = this->board[3][k][0][l];
+						for(int x=0; x<4; x++){
+							winner.winningRow[x] = 3-x;
+							winner.winningColumn[x] = k;
+							winner.winningHeight[x] = x;
+							winner.winningNumber[x] = l;
+						}
+						return winner;
+					}
+				}
+				//rows-numbers
+				for(int i=1; i<4; i++)
+    			{
+    				if(this->board[i][k][l][i]==mini4DgamePlayerColor::none || this->board[0][k][l][0] != this->board[i][k][l][i])
+    					break;
+    				if(i==3)
+    				{
+						winner.color_ = this->board[0][k][l][0];
+						for(int x=0; x<4; x++){
+							winner.winningRow[x] = x;
+							winner.winningColumn[x] = k;
+							winner.winningHeight[x] = l;
+							winner.winningNumber[x] = x;
+						}
+						return winner;
+					}
+				}
+				for(int i=1; i<4; i++)
+    			{
+    				if(this->board[3-i][k][l][i]==mini4DgamePlayerColor::none || this->board[3][k][l][0] != this->board[3-i][k][l][i])
+    					break;
+    				if(i==3)
+    				{
+						winner.color_ = this->board[3][k][l][0];
+						for(int x=0; x<4; x++){
+							winner.winningRow[x] = 3-x;
+							winner.winningColumn[x] = k;
+							winner.winningHeight[x] = l;
+							winner.winningNumber[x] = x;
+						}
+						return winner;
+					}
+				}
+				//column-height
+				for(int i=1; i<4; i++)
+    			{
+    				if(this->board[k][i][i][l]==mini4DgamePlayerColor::none || this->board[k][0][0][l] != this->board[k][i][i][l])
+    					break;
+    				if(i==3)
+    				{
+						winner.color_ = this->board[k][0][0][l];
+						for(int x=0; x<4; x++){
+							winner.winningRow[x] = k;
+							winner.winningColumn[x] = x;
+							winner.winningHeight[x] = x;
+							winner.winningNumber[x] = l;
+						}
+						return winner;
+					}
+				}
+				for(int i=1; i<4; i++)
+    			{
+    				if(this->board[k][3-i][i][l]==mini4DgamePlayerColor::none || this->board[k][3][0][l] != this->board[k][3-i][i][l])
+    					break;
+    				if(i==3)
+    				{
+						winner.color_ = this->board[k][3][0][l];
+						for(int x=0; x<4; x++){
+							winner.winningRow[x] = k;
+							winner.winningColumn[x] = 3-x;
+							winner.winningHeight[x] = x;
+							winner.winningNumber[x] = l;
+						}
+						return winner;
+					}
+				}
+				//column-numbers
+				for(int i=1; i<4; i++)
+    			{
+    				if(this->board[k][i][l][i]==mini4DgamePlayerColor::none || this->board[k][0][l][0] != this->board[k][i][l][i])
+    					break;
+    				if(i==3)
+    				{
+						winner.color_ = this->board[k][0][l][0];
+						for(int x=0; x<4; x++){
+							winner.winningRow[x] = k;
+							winner.winningColumn[x] = x;
+							winner.winningHeight[x] = l;
+							winner.winningNumber[x] = x;
+						}
+						return winner;
+					}
+				}
+				for(int i=1; i<4; i++)
+    			{
+    				if(this->board[k][3-i][l][i]==mini4DgamePlayerColor::none || this->board[k][3][l][0] != this->board[k][3-i][l][i])
+    					break;
+    				if(i==3)
+    				{
+						winner.color_ = this->board[k][3][l][0];
+						for(int x=0; x<4; x++){
+							winner.winningRow[x] = k;
+							winner.winningColumn[x] = 3-x;
+							winner.winningHeight[x] = l;
+							winner.winningNumber[x] = x;
+						}
+						return winner;
+					}
+				}
+				//height-numbers
+				for(int i=1; i<4; i++)
+    			{
+    				if(this->board[k][l][i][i]==mini4DgamePlayerColor::none || this->board[k][l][0][0] != this->board[k][l][i][i])
+    					break;
+    				if(i==3)
+    				{
+						winner.color_ = this->board[k][l][0][0];
+						for(int x=0; x<4; x++){
+							winner.winningRow[x] = k;
+							winner.winningColumn[x] = l;
+							winner.winningHeight[x] = x;
+							winner.winningNumber[x] = x;
+						}
+						return winner;
+					}
+				}
+				for(int i=1; i<4; i++)
+    			{
+    				if(this->board[k][l][3-i][i]==mini4DgamePlayerColor::none || this->board[k][l][3][0] != this->board[k][l][3-i][i])
+    					break;
+    				if(i==3)
+    				{
+						winner.color_ = this->board[k][l][3][0];
+						for(int x=0; x<4; x++){
+							winner.winningRow[x] = k;
+							winner.winningColumn[x] = l;
+							winner.winningHeight[x] = 3-x;
+							winner.winningNumber[x] = x;
+						}
+						return winner;
+					}
+				}
+    		}
+    	}
 
     	//check rows
     	for(int j=0;j<4;j++){
@@ -342,7 +753,14 @@
     				   && 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];
+    					winner.color_ = this->board[0][j][k][l];
+						for(int x=0; x<4; x++){
+							winner.winningRow[x] = x;
+							winner.winningColumn[x] = j;
+							winner.winningHeight[x] = k;
+							winner.winningNumber[x] = l;
+						}
+						return winner;
     				}
     			}
     		}
@@ -357,7 +775,14 @@
     	    				   && 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];
+    	    			winner.color_ = this->board[i][0][k][l];
+						for(int x=0; x<4; x++){
+							winner.winningRow[x] = i;
+							winner.winningColumn[x] = x;
+							winner.winningHeight[x] = k;
+							winner.winningNumber[x] = l;
+						}
+						return winner;
     				}
     			}
     		}
@@ -372,7 +797,14 @@
     	    	    				   && 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];
+    					winner.color_ = this->board[i][j][0][l];
+						for(int x=0; x<4; x++){
+							winner.winningRow[x] = i;
+							winner.winningColumn[x] = j;
+							winner.winningHeight[x] = x;
+							winner.winningNumber[x] = l;
+						}
+						return winner;
     				}
     			}
     		}
@@ -387,13 +819,18 @@
     	    	    				   && 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];
+    					winner.color_ = this->board[i][j][k][0];
+						for(int x=0; x<4; x++){
+							winner.winningRow[x] = i;
+							winner.winningColumn[x] = j;
+							winner.winningHeight[x] = k;
+							winner.winningNumber[x] = x;
+						}
+						return winner;
     				}
     			}
     		}
     	}
-
-
-    	return mini4DgamePlayerColor::none;
+    	return winner;
     }
 }

Modified: code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4DgameCenterpoint.h
===================================================================
--- code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4DgameCenterpoint.h	2014-11-12 15:04:45 UTC (rev 10120)
+++ code/branches/minigame4DHS14/src/modules/mini4Dgame/Mini4DgameCenterpoint.h	2014-11-12 15:07:10 UTC (rev 10121)
@@ -40,6 +40,7 @@
 
 #include "worldentities/StaticEntity.h"
 #include "mini4Dgame/Mini4DgamePrereqs.h"
+#include "mini4Dgame/Mini4Dgame.h"
 
 namespace orxonox
 {
@@ -108,19 +109,19 @@
                     @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);
+            bool isValidMove(const Vector4 move);
 
             /**
                @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);
+            void makeMove(const Vector4 move, const mini4DgamePlayerColor::color playerColor);
 
             /**
-                @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()
+               @brief checks if somebody has won
+               @return the winner with the winning fields or a winner with winner.color_ == mini4DgamePlayerColor::none if nobody has won so far.
+            */
+            Mini4DgameWinner Mini4DgameCenterpoint::getWinner();
 
         private:
             void checkGametype(); //!< Checks whether the gametype is Mini4Dgame and if it is, sets its centerpoint.




More information about the Orxonox-commit mailing list