Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2857


Ignore:
Timestamp:
Mar 26, 2009, 7:28:09 PM (15 years ago)
Author:
landauf
Message:

added configurable PongAI-strength

Location:
code/trunk/src/orxonox/objects/controllers
Files:
2 edited

Legend:

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

    r2839 r2857  
    3131
    3232#include "core/CoreIncludes.h"
     33#include "core/ConfigValueIncludes.h"
    3334#include "objects/worldentities/ControllableEntity.h"
    3435#include "objects/worldentities/PongBall.h"
     
    4546        this->randomOffset_ = 0;
    4647        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.");
    4756    }
    4857
     
    8998    void PongAI::calculateRandomOffset()
    9099    {
    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;
    92117    }
    93118}
  • code/trunk/src/orxonox/objects/controllers/PongAI.h

    r2839 r2857  
    4343            virtual ~PongAI() {}
    4444
     45            void setConfigValues();
     46
    4547            virtual void tick(float dt);
    4648
     
    5456            float randomOffset_;
    5557            float relHysteresisOffset_;
     58            float strength_;
    5659    };
    5760}
Note: See TracChangeset for help on using the changeset viewer.