Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 23, 2011, 9:41:21 PM (13 years ago)
Author:
dafrick
Message:

Done documenting Pong.
Also resolved some doxygen warnings.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/tetris/src/modules/pong/PongAI.cc

    r6417 r8107  
    2727 */
    2828
     29/**
     30    @file PongAI.cc
     31    @brief Implementation of the PongAI class.
     32*/
     33
    2934#include "PongAI.h"
    3035
     
    3237#include "core/ConfigValueIncludes.h"
    3338#include "tools/Timer.h"
     39
    3440#include "worldentities/ControllableEntity.h"
     41
    3542#include "PongBall.h"
    3643
     
    4148    const static float MAX_REACTION_TIME = 0.4f;
    4249
     50    /**
     51    @brief
     52        Constructor. Registers and initializes the object.
     53    */
    4354    PongAI::PongAI(BaseObject* creator) : Controller(creator)
    4455    {
     
    5970    }
    6071
     72    /**
     73    @brief
     74        Destructor. Cleans up the list fo reaction timers.
     75    */
    6176    PongAI::~PongAI()
    6277    {
     
    6580    }
    6681
     82    /**
     83    @brief
     84        Sets config values.
     85    */
    6786    void PongAI::setConfigValues()
    6887    {
     88        // Sets the strength of the PongAi as a config value.
    6989        SetConfigValue(strength_, 0.5).description("A value from 0 to 1 where 0 is weak and 1 is strong.");
    7090    }
    7191
     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    */
    7299    void PongAI::tick(float dt)
    73100    {
    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)
    75103            return;
    76104
     
    109137            if (this->ballDirection_.x != 1)
    110138            {
    111                 // The ball just startet to approach, initialize all values
     139                // The ball just started to approach, initialize all values
    112140                this->ballDirection_.x = 1;
    113141                this->ballDirection_.y = sgn(ballvel.z);
     
    158186            {
    159187                // We had to correct our position because we moved too far
    160                 // (and delay ist false, 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)
    161189                if (fabs(mypos.z - this->ballEndPosition_) < 0.5 * this->ball_->getBatLength() * this->ball_->getFieldDimension().y)
    162190                {
     
    173201    }
    174202
     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    */
    175209    void PongAI::calculateRandomOffset()
    176210    {
     
    184218                                          // exp < 1 -> position is more likely a large number
    185219
    186         // The position shouln'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)
    187221        position *= 0.48f;
    188222
     
    194228    }
    195229
     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    */
    196235    void PongAI::calculateBallEndPosition()
    197236    {
     
    295334    }
    296335
     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    */
    297345    void PongAI::move(char direction, bool bUseDelay)
    298346    {
     
    321369    }
    322370
     371    /**
     372    @brief
     373        Is called, when a delayed move takes effect.
     374    */
    323375    void PongAI::delayedMove()
    324376    {
Note: See TracChangeset for help on using the changeset viewer.