Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 31, 2009, 1:15:52 AM (15 years ago)
Author:
landauf
Message:

some small adjustments in PongAI and related classes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/orxonox/objects/controllers/PongAI.cc

    r2860 r2872  
    5555
    5656        this->setConfigValues();
    57 
    58 //        this->randomOffsetTimer_.setTimer(MAX_REACTION_TIME * (1 - this->strength_), false, this, createExecutor(createFunctor(&PongAI::calculateRandomOffset)));
    59 //        this->ballEndPositionTimer_.setTimer(MAX_REACTION_TIME * (1 - this->strength_), false, this, createExecutor(createFunctor(&PongAI::calculateBallEndPosition)));
    60 //        this->randomOffsetTimer_.stopTimer();
    61 //        this->ballEndPositionTimer_.stopTimer();
    6257    }
    6358
     
    8883        if ((mypos.x > 0 && ballvel.x < 0) || (mypos.x < 0 && ballvel.x > 0))
    8984        {
    90             // Ball is flying away
     85            // The ball is flying away
    9186            this->ballDirection_.x = -1;
    9287            this->ballDirection_.y = 0;
    9388
     89            // Move to the middle
    9490            if (mypos.z > hysteresisOffset)
    9591                move = 1;
     
    9995        else if (ballvel.x == 0)
    10096        {
    101             // Ball is standing still
     97            // The ball is standing still
    10298            this->ballDirection_.x = 0;
    10399            this->ballDirection_.y = 0;
     
    105101        else
    106102        {
    107             // Ball is approaching
     103            // The ball is approaching
    108104            if (this->ballDirection_.x != 1)
    109105            {
     106                // The ball just startet to approach, initialize all values
    110107                this->ballDirection_.x = 1;
    111108                this->ballDirection_.y = sgn(ballvel.z);
     
    115112                this->calculateRandomOffset();
    116113                this->calculateBallEndPosition();
    117                 //this->randomOffsetTimer_.setInterval(MAX_REACTION_TIME * (1 - this->strength_));
    118                 //this->ballEndPositionTimer_.setInterval(MAX_REACTION_TIME * (1 - this->strength_));
    119                 //this->randomOffsetTimer_.startTimer();
    120                 //this->ballEndPositionTimer_.startTimer();
    121114            }
    122115
    123116            if (this->ballDirection_.y != sgn(ballvel.z))
    124117            {
     118                // The ball just bounced from a bound, recalculate the predicted end position
    125119                this->ballDirection_.y = sgn(ballvel.z);
    126120
    127121                this->calculateBallEndPosition();
    128                 //this->ballEndPositionTimer_.startTimer();
    129             }
    130 
    131             float desiredZValue = /*((1 - this->strength_) * ballpos.z) + */(/*this->strength_ * */this->ballEndPosition_) + this->randomOffset_;
     122            }
     123
     124            // Move to the predicted end position with an additional offset (to hit the ball with the side of the bat)
     125            float desiredZValue = this->ballEndPosition_ + this->randomOffset_;
    132126
    133127            if (mypos.z > desiredZValue + hysteresisOffset * (this->randomOffset_ < 0))
     
    156150
    157151        // Both sides are equally probable
    158         position *= sgn(rnd(-1,1));
     152        position *= rndsgn();
    159153
    160154        // Calculate the offset in world units
     
    174168        for (float limit = 0.35; limit < this->strength_ || this->strength_ > 0.99; limit += 0.4)
    175169        {
     170            // Bounce from the upper bound
    176171            if (this->ballEndPosition_ > dimension.y / 2)
    177172            {
     173                // Mirror the predicted position at the upper bound and add some random error
    178174                this->ballEndPosition_ = dimension.y - this->ballEndPosition_ + (rnd(-1, 1) * dimension.y * (1 - this->strength_));
    179175                continue;
    180176            }
     177            // Bounce from the upper bound
    181178            if (this->ballEndPosition_ < -dimension.y / 2)
    182179            {
     180                // Mirror the predicted position at the lower bound and add some random error
    183181                this->ballEndPosition_ = -dimension.y - this->ballEndPosition_ + (rnd(-1, 1) * dimension.y * (1 - this->strength_));
    184182                continue;
    185183            }
     184            // No bounce - break
    186185            break;
    187186        }
     
    216215    void PongAI::delayedMove()
    217216    {
     217        // Get the new movement direction from the timer list
    218218        this->movement_ = this->reactionTimers_.front().second;
    219219
     220        // Destroy the timer and remove it from the list
    220221        Timer<PongAI>* timer = this->reactionTimers_.front().first;
    221222        delete timer;
Note: See TracChangeset for help on using the changeset viewer.