home *** CD-ROM | disk | FTP | other *** search
/ AI Game Programming Wisdom / AIGameProgrammingWisdom.iso / SourceCode / 11 Learning / 09 Laramée / Troll.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-08-22  |  2.8 KB  |  97 lines

  1. /****************************************************************
  2.  * CLASS Troll
  3.  * The hero of our grand adventure; this is the object we will be
  4.  * evolving with genetic algorithms
  5.  ***************************************************************/
  6.  
  7. #ifndef TROLL_H
  8. #define TROLL_H
  9.  
  10. #include "Globals.h"
  11. #include "Entities.h"
  12. #include "Chromosome.h"
  13.  
  14. /****************************************************************
  15.  
  16.      NOTE: Although we will often treat the Troll in unique fashion,
  17.      we still derive it from the Entity class to benefit from its
  18.      services
  19.  
  20. *****************************************************************/
  21.  
  22. class Troll : public Entity
  23. {
  24.     // The troll's genetic material...
  25.     Chromosome * DNA;
  26.  
  27.     // How healthy is our friend the troll?  Globals.h defines a
  28.     // few constants describing health levels
  29.     int HitPoints;
  30.  
  31.     // Some flags used during the simulation
  32.     bool IsCaptured;
  33.     bool IsDead;
  34.  
  35.  
  36. public:
  37.     // Stats compiled during the simulation; they are used to 
  38.     // compute the individual's performance and assess its fitness
  39.     int StatsTimeSinceLastMeal;
  40.     int StatsKnightsKilled;
  41.     int StatsSheepEaten;
  42.     int StatsDamageTaken;
  43.     int StatsTimeAlive;
  44.     int StatsTimeCaptive;
  45.  
  46.     // Construction
  47.     Troll( Chromosome & c, int x, int y ) : Entity( x, y, -1 ), HitPoints( FULL_HEALTH ), 
  48.         IsCaptured( false ), IsDead( false ), DNA( &c ), StatsTimeSinceLastMeal( 0 ),
  49.         StatsKnightsKilled( 0 ), StatsSheepEaten( 0 ), StatsDamageTaken( 0 ),
  50.         StatsTimeAlive( 0 ), StatsTimeCaptive( 0 ) {}
  51.     Entity * Clone() { return 0; } // Cloning of the troll is illegal
  52.  
  53.     bool Dead() { return IsDead; }
  54.  
  55.     // The Entity virtual classes
  56.     bool Update();
  57.     int ExportedClass() { return ENTITY_TROLL; }
  58.  
  59.     // Messages sent to the troll by other entities
  60.     void SendCaptureMessage();
  61.     void SendDamageMessage( int ouch );
  62.     bool SendFightMessage();
  63.  
  64.     // Functions needed by the simulation
  65.     void Reset();
  66.     double GetEvaluation();
  67.  
  68. private:
  69.     // A whole mess of methods used to decide what the troll
  70.     // will do in a given turn.  First, a self-explanatory one
  71.     int PickStrategy();
  72.  
  73.     // These methods explore the environment for conditions
  74.     // suitable to each of the troll's goals.  The scores
  75.     // they return are multiplied by the priorities set in the
  76.     // troll's genes, and the highest total determines which
  77.     // goal the troll will follow this time
  78.     double FleeingStrategy();
  79.     double EatingStrategy();
  80.     double HealingStrategy();
  81.     double KillingStrategy();
  82.     double ExploringStrategy();
  83.  
  84.     // These methods implement the goals selected by PickStrategy
  85.     void ImplementFleeingStrategy();
  86.     void ImplementEatingStrategy();
  87.     void ImplementHealingStrategy();
  88.     void ImplementKillingStrategy();
  89.     void ImplementExploringStrategy();
  90.  
  91.  
  92. public:
  93.     // Debugging help
  94.     void Dump();
  95. };
  96.  
  97. #endif