Changeset 2857 for code/trunk
- Timestamp:
- Mar 26, 2009, 7:28:09 PM (16 years ago)
- Location:
- code/trunk/src/orxonox/objects/controllers
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/orxonox/objects/controllers/PongAI.cc
r2839 r2857 31 31 32 32 #include "core/CoreIncludes.h" 33 #include "core/ConfigValueIncludes.h" 33 34 #include "objects/worldentities/ControllableEntity.h" 34 35 #include "objects/worldentities/PongBall.h" … … 45 46 this->randomOffset_ = 0; 46 47 this->relHysteresisOffset_ = 0.02; 48 this->strength_ = 0.5; 49 50 this->setConfigValues(); 51 } 52 53 void PongAI::setConfigValues() 54 { 55 SetConfigValue(strength_, 0.5).description("A value from 0 to 1 where 0 is weak and 1 is strong."); 47 56 } 48 57 … … 89 98 void PongAI::calculateRandomOffset() 90 99 { 91 this->randomOffset_ = rnd(-0.45, 0.45) * this->ball_->getBatLength() * this->ball_->getFieldDimension().y; 100 // Calculate the exponent for the position-formula 101 float exp = pow(10, 1 - 2*this->strength_); // strength: 0 -> exp = 10 102 // strength: 0.5 -> exp = 1 103 // strength: 1 -> exp = 0.1 104 105 // Calculate the relative position where to hit the ball with the bat 106 float position = pow(rnd(), exp); // exp > 1 -> position is more likely a small number 107 // exp < 1 -> position is more likely a large number 108 109 // The position shouln't be larger than 0.5 (50% of the bat-length from the middle is the end) 110 position *= 0.45; 111 112 // Both sides are equally probable 113 position *= sgn(rnd(-1,1)); 114 115 // Calculate the offset in world units 116 this->randomOffset_ = position * this->ball_->getBatLength() * this->ball_->getFieldDimension().y; 92 117 } 93 118 } -
code/trunk/src/orxonox/objects/controllers/PongAI.h
r2839 r2857 43 43 virtual ~PongAI() {} 44 44 45 void setConfigValues(); 46 45 47 virtual void tick(float dt); 46 48 … … 54 56 float randomOffset_; 55 57 float relHysteresisOffset_; 58 float strength_; 56 59 }; 57 60 }
Note: See TracChangeset
for help on using the changeset viewer.