[Orxonox-commit 182] r2857 - trunk/src/orxonox/objects/controllers

landauf at orxonox.net landauf at orxonox.net
Thu Mar 26 19:28:10 CET 2009


Author: landauf
Date: 2009-03-26 18:28:09 +0000 (Thu, 26 Mar 2009)
New Revision: 2857

Modified:
   trunk/src/orxonox/objects/controllers/PongAI.cc
   trunk/src/orxonox/objects/controllers/PongAI.h
Log:
added configurable PongAI-strength

Modified: trunk/src/orxonox/objects/controllers/PongAI.cc
===================================================================
--- trunk/src/orxonox/objects/controllers/PongAI.cc	2009-03-26 16:06:25 UTC (rev 2856)
+++ trunk/src/orxonox/objects/controllers/PongAI.cc	2009-03-26 18:28:09 UTC (rev 2857)
@@ -30,6 +30,7 @@
 #include "PongAI.h"
 
 #include "core/CoreIncludes.h"
+#include "core/ConfigValueIncludes.h"
 #include "objects/worldentities/ControllableEntity.h"
 #include "objects/worldentities/PongBall.h"
 
@@ -44,8 +45,16 @@
         this->ball_ = 0;
         this->randomOffset_ = 0;
         this->relHysteresisOffset_ = 0.02;
+        this->strength_ = 0.5;
+
+        this->setConfigValues();
     }
 
+    void PongAI::setConfigValues()
+    {
+        SetConfigValue(strength_, 0.5).description("A value from 0 to 1 where 0 is weak and 1 is strong.");
+    }
+
     void PongAI::tick(float dt)
     {
         if (!this->ball_ || !this->getControllableEntity())
@@ -88,6 +97,22 @@
 
     void PongAI::calculateRandomOffset()
     {
-        this->randomOffset_ = rnd(-0.45, 0.45) * this->ball_->getBatLength() * this->ball_->getFieldDimension().y;
+        // Calculate the exponent for the position-formula
+        float exp = pow(10, 1 - 2*this->strength_); // strength: 0   -> exp = 10
+                                                    // strength: 0.5 -> exp = 1
+                                                    // strength: 1   -> exp = 0.1
+
+        // Calculate the relative position where to hit the ball with the bat
+        float position = pow(rnd(), exp); // exp > 1 -> position is more likely a small number
+                                          // exp < 1 -> position is more likely a large number
+
+        // The position shouln't be larger than 0.5 (50% of the bat-length from the middle is the end)
+        position *= 0.45;
+
+        // Both sides are equally probable
+        position *= sgn(rnd(-1,1));
+
+        // Calculate the offset in world units
+        this->randomOffset_ = position * this->ball_->getBatLength() * this->ball_->getFieldDimension().y;
     }
 }

Modified: trunk/src/orxonox/objects/controllers/PongAI.h
===================================================================
--- trunk/src/orxonox/objects/controllers/PongAI.h	2009-03-26 16:06:25 UTC (rev 2856)
+++ trunk/src/orxonox/objects/controllers/PongAI.h	2009-03-26 18:28:09 UTC (rev 2857)
@@ -42,6 +42,8 @@
             PongAI(BaseObject* creator);
             virtual ~PongAI() {}
 
+            void setConfigValues();
+
             virtual void tick(float dt);
 
             void setPongBall(PongBall* ball)
@@ -53,6 +55,7 @@
             PongBall* ball_;
             float randomOffset_;
             float relHysteresisOffset_;
+            float strength_;
     };
 }
 




More information about the Orxonox-commit mailing list