home *** CD-ROM | disk | FTP | other *** search
/ AI Game Programming Wisdom / AIGameProgrammingWisdom.iso / SourceCode / 11 Learning / 01 Manslow / GPExample / CGPNode.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-07  |  1.8 KB  |  60 lines

  1. //GPExample
  2. //Copyright John Manslow
  3. //29/09/2001
  4.  
  5. #ifndef _GPNode_
  6. #define _GPNode_
  7.  
  8. class CGP;
  9.  
  10. //Base class for all nodes that can appear in a genetic program tree
  11. class CGPNode
  12. {
  13. public:
  14.     CGPNode();
  15.     virtual ~CGPNode();
  16.  
  17.     //Returns a copy of the node
  18.     virtual CGPNode *pGetCopy(CGP*);
  19.  
  20.     //Evaluates the node. This causes non-teminal nodes to evaluate their children and return some 
  21.     //function of their return values. Some nodes - usual terminals - cause the agent to perform actions
  22.     //in the world, such a moving forwards, or return sensory information from the agent, such as the
  23.     //type of object directly in front of it
  24.     virtual double dEvaluate(void);
  25.  
  26.     //Returns a string containing the subprogram starting at this node. In principle, the programs could
  27.     //be placed directly into a scipring engine (provided, of course, that the syntax is appropriately
  28.     //constructed)
  29.     virtual char *psGetString(char*);
  30.  
  31.     //Returns the number of nodes in the subtree attached to this node
  32.     virtual unsigned long ulGetNumberOfNodesInSubtree(unsigned long);
  33.  
  34.     //Returns a pointer to the specified node in the subtree
  35.     virtual void GetnthNode(unsigned long&,unsigned long,CGPNode**&);
  36.  
  37.     //Adds the current node to the prototype list
  38.     virtual int AddToPrototypeList(void);
  39.  
  40.     //A pointer to an array of child nodes
  41.     CGPNode **pChildren;
  42.  
  43.     //The number of child nodes attached to this node
  44.     unsigned long ulNumberOfChildren;
  45.  
  46.     //The type of this node
  47.     int nType;
  48.  
  49.     //Indicates whether this nodes is a working node or if it is just a prototype
  50.     int nIsPrototype;
  51.  
  52.     //A weighting factor affecting how likely this type of node is to appear in a randomly generated
  53.     //subtree
  54.     double dPrior;
  55.  
  56.     //A string name for the node
  57.     char *psName;
  58. };
  59.  
  60. #endif