[Orxonox-commit 7561] r12164 - code/branches/wagnis_HS18/src/modules/wagnis

samuelbl at orxonox.net samuelbl at orxonox.net
Thu Dec 6 20:45:48 CET 2018


Author: samuelbl
Date: 2018-12-06 20:45:47 +0100 (Thu, 06 Dec 2018)
New Revision: 12164

Modified:
   code/branches/wagnis_HS18/src/modules/wagnis/WagnisPlayer.cc
   code/branches/wagnis_HS18/src/modules/wagnis/WagnisPlayer.h
   code/branches/wagnis_HS18/src/modules/wagnis/WagnisProvince.h
Log:
Checkmove function fixed

Modified: code/branches/wagnis_HS18/src/modules/wagnis/WagnisPlayer.cc
===================================================================
--- code/branches/wagnis_HS18/src/modules/wagnis/WagnisPlayer.cc	2018-12-05 20:57:36 UTC (rev 12163)
+++ code/branches/wagnis_HS18/src/modules/wagnis/WagnisPlayer.cc	2018-12-06 19:45:47 UTC (rev 12164)
@@ -7,6 +7,7 @@
 #include <cstdlib>
 #include <ctime>
 
+
 namespace orxonox
 {
     RegisterClass(WagnisPlayer);
@@ -246,6 +247,7 @@
 
         if (move_type == MOVE)
         {
+            AlreadyChecked.clear();
             if (existPath(this->origin_province, this->target_province))//path exists, all belong to same player
             {
                 if (this->origin_province->getOwner_ID() == this->Player_ID)//origin belongs to player
@@ -293,15 +295,17 @@
     //checks if path is complete with provinces owned by player
     bool WagnisPlayer::existPath(WagnisProvince* origin, WagnisProvince* target)
     {
+        AlreadyChecked.push_back(origin->getID());
+        
         if (origin->getOwner_ID() == target->getOwner_ID() && isNeighbour(origin, target))
             return true;
         
         for (unsigned int i = 0; i < origin->neighbors.size(); ++i)
-        {
-            if (origin->getOwner_ID() == origin->neighbors[i]->getOwner_ID())
+        {                
+            if ((origin->getOwner_ID() == origin->neighbors[i]->getOwner_ID()) && (!(contains(AlreadyChecked, origin->neighbors[i]->getID()))))
                 return existPath(origin->neighbors[i], target);
         }
-            
+        
         return false;
     }
 
@@ -346,6 +350,14 @@
             return b;    
     }
 
+    bool WagnisPlayer::contains(std::vector<int> a, int key)
+    {
+        if(std::count(a.begin(), a.end(), key))
+            return true;
+        else 
+            return false;
+    }
+    
     void WagnisPlayer::setActive(bool b){
         this->is_active = b;
         if(b == true) orxout()<<"Player "<<this->Player_ID<<"\'s turn"<<endl;

Modified: code/branches/wagnis_HS18/src/modules/wagnis/WagnisPlayer.h
===================================================================
--- code/branches/wagnis_HS18/src/modules/wagnis/WagnisPlayer.h	2018-12-05 20:57:36 UTC (rev 12163)
+++ code/branches/wagnis_HS18/src/modules/wagnis/WagnisPlayer.h	2018-12-06 19:45:47 UTC (rev 12164)
@@ -16,10 +16,13 @@
 #include <vector>
 #include <string>
 #include "infos/HumanPlayer.h"
+#include <algorithm>
+#include <iostream>
 
 
 
 
+
 namespace orxonox
 {
     class WagnisPlayer : public HumanPlayer, public Tickable
@@ -49,8 +52,10 @@
         WagnisProvince* origin_province;
         WagnisProvince* target_province;
         int reinforcements;
+        std::vector<int> AlreadyChecked;
         bool isNeighbour(WagnisProvince*, WagnisProvince*);
         bool existPath(WagnisProvince*, WagnisProvince*);
+        bool contains(std::vector<int>, int);
         int dice();
         int best3(int, int, int);
         int best2(int, int);

Modified: code/branches/wagnis_HS18/src/modules/wagnis/WagnisProvince.h
===================================================================
--- code/branches/wagnis_HS18/src/modules/wagnis/WagnisProvince.h	2018-12-05 20:57:36 UTC (rev 12163)
+++ code/branches/wagnis_HS18/src/modules/wagnis/WagnisProvince.h	2018-12-06 19:45:47 UTC (rev 12164)
@@ -15,7 +15,6 @@
 #include <OgreColourValue.h>
 #include "tools/ToolsPrereqs.h"
 
-
 namespace orxonox
 {
     class _WagnisExport WagnisProvince : public Pawn



More information about the Orxonox-commit mailing list