home *** CD-ROM | disk | FTP | other *** search
/ AI Game Programming Wisdom / AIGameProgrammingWisdom.iso / SourceCode / 11 Learning / 04 Mommersteeg / Tennis / Aibot.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-09-23  |  2.7 KB  |  91 lines

  1. //----------------------------------------------------------------------------------------------
  2. // Sequential Prediction Demo: The positioning pattern
  3. // 
  4. // Author:  Fri Mommersteeg
  5. // Date:    10-09-2001
  6. // File:    AiBot.h
  7. //----------------------------------------------------------------------------------------------
  8.  
  9. #ifndef __AIBOT_H
  10. #define __AIBOT_H
  11.  
  12. //----------------------------------------------------------------------------------------------
  13. // Include files
  14. //----------------------------------------------------------------------------------------------
  15.  
  16. #include "paddle.h"
  17. #include "tennispredictor.h"
  18. #include "randompredictor.h"
  19.  
  20. //----------------------------------------------------------------------------------------------
  21. // Defines constants
  22. //----------------------------------------------------------------------------------------------
  23.  
  24. #define WINDOW_SIZE            10
  25. #define MIN_PATTERN_SIZE    3
  26. #define ANTICIPATION        1
  27. #define TOWARDSCENTER        2
  28. #define INTERPOLATION        3
  29. #define TOWARDSBALL            4
  30. #define PADDLE_ANGLES        9
  31.  
  32. //----------------------------------------------------------------------------------------------
  33. // CAiBot: An AI-controlled tennis paddle
  34. //----------------------------------------------------------------------------------------------
  35.  
  36. class CAiBot: public CPaddle, CObserver {
  37. public:
  38.  
  39.     CAiBot() {
  40.         pHorizontal = NULL;
  41.         pVertical = NULL;
  42.         RandomPredictor.Setup(PADDLE_ANGLES, GetTickCount());
  43.     }
  44.  
  45.     ~CAiBot() {
  46.         if (pVertical != NULL) {
  47.             delete pVertical;
  48.         }
  49.         if (pHorizontal != NULL) {
  50.             delete pHorizontal;
  51.         }
  52.     }
  53.  
  54. public:
  55.     void                            SetupAI(CTennisBall * TennisBall, BOOL bTargeting = FALSE);
  56.     void                            EnableTargeting(BOOL bEnabled);
  57.     virtual CTennisPredictor *        PredictorFactory();
  58.     virtual BOOL                    Notify(int msg, DWORD param = 0);
  59.     virtual void                    Paint(LPDDS lpdds);
  60.     virtual void                    Update();
  61.     virtual void                    ResetForService(BOOL HasService);
  62.     virtual void                    ShowStatistics(HDC dc);
  63.     
  64. protected:
  65.  
  66.     void                            SeekTarget();
  67.     void                            AdvanceTarget();
  68.     void                            AdjustPaddleAngle();
  69.     virtual void                    OnBallCollision();
  70.     void                            PaintSequence(HDC dc, int x, int y, char * szA, char * szB,
  71.                                         CTennisPredictor * pPredictor, int Width = 20);
  72.  
  73. protected:
  74.     CTennisBall *                    ball;
  75.     CTennisPredictor *                pHorizontal;
  76.     CTennisPredictor *                pVertical;
  77.     
  78.     int                                nBounces;
  79.     POINT                            target;
  80.     POINT                            BallDestination;
  81.     int                                halfwidth, halfheight;
  82.     int                                heuristic;
  83.     BOOL                            bHasService;
  84.     BOOL                            bTargeting;
  85.     CRandomPredictor                RandomPredictor;
  86. };
  87.  
  88. //----------------------------------------------------------------------------------------------
  89. #endif // __AIBOT_H
  90.  
  91.