Changeset 8194 for code/branches/dockingsystem/src/modules/pong/PongAI.cc
- Timestamp:
- Apr 6, 2011, 12:07:29 PM (13 years ago)
- Location:
- code/branches/dockingsystem
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/dockingsystem
- Property svn:mergeinfo changed
/code/branches/lastmanstanding3 (added) merged: 7903,8155,8165,8170-8175 /code/branches/tetris (added) merged: 8104-8107 /code/trunk (added) merged: 8108,8178-8179,8193
- Property svn:mergeinfo changed
-
code/branches/dockingsystem/src/modules/pong/PongAI.cc
r6417 r8194 27 27 */ 28 28 29 /** 30 @file PongAI.cc 31 @brief Implementation of the PongAI class. 32 */ 33 29 34 #include "PongAI.h" 30 35 … … 32 37 #include "core/ConfigValueIncludes.h" 33 38 #include "tools/Timer.h" 39 34 40 #include "worldentities/ControllableEntity.h" 41 35 42 #include "PongBall.h" 36 43 … … 41 48 const static float MAX_REACTION_TIME = 0.4f; 42 49 50 /** 51 @brief 52 Constructor. Registers and initializes the object. 53 */ 43 54 PongAI::PongAI(BaseObject* creator) : Controller(creator) 44 55 { … … 59 70 } 60 71 72 /** 73 @brief 74 Destructor. Cleans up the list fo reaction timers. 75 */ 61 76 PongAI::~PongAI() 62 77 { … … 65 80 } 66 81 82 /** 83 @brief 84 Sets config values. 85 */ 67 86 void PongAI::setConfigValues() 68 87 { 88 // Sets the strength of the PongAi as a config value. 69 89 SetConfigValue(strength_, 0.5).description("A value from 0 to 1 where 0 is weak and 1 is strong."); 70 90 } 71 91 92 /** 93 @brief 94 Is called each tick. 95 Implements the behavior of the PongAI (i.e. its intelligence). 96 @param dt 97 The time that has elapsed since the last tick. 98 */ 72 99 void PongAI::tick(float dt) 73 100 { 74 if (!this->ball_ || !this->getControllableEntity()) 101 // If either the ball, or the controllable entity (i.e. the bat) don't exist (or aren't set). 102 if (this->ball_ == NULL || this->getControllableEntity() == NULL) 75 103 return; 76 104 … … 109 137 if (this->ballDirection_.x != 1) 110 138 { 111 // The ball just starte tto approach, initialize all values139 // The ball just started to approach, initialize all values 112 140 this->ballDirection_.x = 1; 113 141 this->ballDirection_.y = sgn(ballvel.z); … … 158 186 { 159 187 // We had to correct our position because we moved too far 160 // (and delay is tfalse, so we're not in the wrong place because of a new end-position prediction)188 // (and delay is false, so we're not in the wrong place because of a new end-position prediction) 161 189 if (fabs(mypos.z - this->ballEndPosition_) < 0.5 * this->ball_->getBatLength() * this->ball_->getFieldDimension().y) 162 190 { … … 173 201 } 174 202 203 /** 204 @brief 205 Calculates the random offset, that accounts for random errors the AI makes in order to be beatable. 206 The higher the strength of the AI, the smaller the (expected value of the) error. 207 The result of this method is stored in this->randomOffset_. 208 */ 175 209 void PongAI::calculateRandomOffset() 176 210 { … … 184 218 // exp < 1 -> position is more likely a large number 185 219 186 // The position shoul n't be larger than 0.5 (50% of the bat-length from the middle is the end)220 // The position shouldn't be larger than 0.5 (50% of the bat-length from the middle is the end) 187 221 position *= 0.48f; 188 222 … … 194 228 } 195 229 230 /** 231 @brief 232 Calculate the end position the ball will be in. 233 The result of this calculation is stored in this->ballEndPosition_. 234 */ 196 235 void PongAI::calculateBallEndPosition() 197 236 { … … 295 334 } 296 335 336 /** 337 @brief 338 Determine the movement the AI will undertake. (Either -1, 0 or 1) 339 The result of this calculation is stored in this->movement_; 340 @param direction 341 The current direction of movement. 342 @param bUseDelay 343 The time by which this move is delayed. (Again, to make the AI less efficient) 344 */ 297 345 void PongAI::move(char direction, bool bUseDelay) 298 346 { … … 321 369 } 322 370 371 /** 372 @brief 373 Is called, when a delayed move takes effect. 374 */ 323 375 void PongAI::delayedMove() 324 376 {
Note: See TracChangeset
for help on using the changeset viewer.