Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/spaceboundaries2/src/modules/pong/PongAI.h @ 8506

Last change on this file since 8506 was 8108, checked in by dafrick, 14 years ago

Merging changes from tetris branch into trunk, since they are also useful, there.

  • Property svn:eol-style set to native
File size: 3.4 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Fabian 'x3n' Landau
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29/**
30    @file PongAI.h
31    @brief Declaration of the PongAI class.
32    @ingroup Pong
33*/
34
35#ifndef _PongAI_H__
36#define _PongAI_H__
37
38#include "pong/PongPrereqs.h"
39
40#include <list>
41
42#include "util/Math.h"
43#include "tools/interfaces/Tickable.h"
44
45#include "controllers/Controller.h"
46
47namespace orxonox
48{
49
50    /**
51    @brief
52        The PongAI is an artificial intelligence for the @ref orxonox::Pong "Pong" gametype.
53
54    @author
55        Fabian 'x3n' Landau
56
57    @ingroup Pong
58    */
59    class _PongExport PongAI : public Controller, public Tickable
60    {
61        public:
62            PongAI(BaseObject* creator); //!< Constructor. Registers and initializes the object.
63            virtual ~PongAI();
64
65            void setConfigValues();
66
67            virtual void tick(float dt); //!< Implements the behavior of the PongAI (i.e. its intelligence).
68
69            /**
70            @brief Set the ball for the AI.
71            @param ball A pointer to the ball.
72            */
73            void setPongBall(PongBall* ball)
74                { this->ball_ = ball; }
75
76        protected:
77            void calculateRandomOffset(); //!< Calculates the random offset, that accounts for random errors the AI makes in order to be beatable.
78            void calculateBallEndPosition(); //!< Calculate the end position the ball will be in.
79            void move(char direction, bool bUseDelay); //!< Determine the movement the AI will undertake.
80            void delayedMove(); //!< Is called, when a delayed move takes effect.
81
82            PongBall* ball_; //!< A pointer to the ball.
83            Vector2 ballDirection_; //!< Vector to store the (x,z) direction in which the ball is flying.
84            float ballEndPosition_; //!< The calculated end position of the ball.
85            float randomOffset_; //!< A random offset to introduce random errors (weighted by the strength of the AI) into the AI's behavior.
86            bool bChangedRandomOffset_; //!< Helper boolean, to change the random offset more often.
87            float relHysteresisOffset_; //!< A hysteresis offset.
88            float strength_; //!< The strength of the AI. Ranging from 0 to 1.
89
90            std::list<std::pair<Timer*, char> > reactionTimers_; //!< A list of reaction timers and the directions that take effect when their timer expires.
91            char movement_; //!< The planned movement.
92            char oldMove_; //!< The previous movement.
93            bool bOscillationAvoidanceActive_; //!< Boolean, to avoid oscillations.
94    };
95}
96
97#endif /* _PongAI_H__ */
Note: See TracBrowser for help on using the repository browser.