home *** CD-ROM | disk | FTP | other *** search
/ AI Game Programming Wisdom / AIGameProgrammingWisdom.iso / SourceCode / 11 Learning / 01 Manslow / GPExample / CGPIsPoisonNode.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-09  |  1.3 KB  |  68 lines

  1. //GPExample
  2. //Copyright John Manslow
  3. //29/09/2001
  4.  
  5. ////////////////////////////////////////////////////////////
  6. //Only when compiling under Windows
  7. #include "stdafx.h"
  8. #define new DEBUG_NEW
  9. ////////////////////////////////////////////////////////////
  10.  
  11. #include "math.h"
  12. #include "CGPIsPoisonNode.h"
  13. #include "CGPNode.h"
  14. #include "CGP.h"
  15. #include "assert.h"
  16.  
  17. extern CGPNode **pPrototypeList;
  18. extern unsigned long ulNumberOfPrototypes;
  19.  
  20. extern int nLookForward(void);
  21.  
  22. CGPIsPoisonNode IsPoisonPrototype;
  23.  
  24. CGPIsPoisonNode::CGPIsPoisonNode()
  25. {
  26.     nType=102;
  27.  
  28.     pChildren=NULL;
  29.     ulNumberOfChildren=0;
  30.  
  31.     sprintf(psName,"IsPoisonNode");
  32.     nIsPrototype=1-AddToPrototypeList();
  33.     dPrior=0.2;
  34. }
  35.  
  36. CGPIsPoisonNode::~CGPIsPoisonNode()
  37. {
  38. }
  39.  
  40. CGPNode *CGPIsPoisonNode::pGetCopy(CGP* pGP)
  41. {
  42.     CGPIsPoisonNode *pNewNode=new CGPIsPoisonNode;
  43.     assert(!(pNewNode==NULL));
  44.     return (CGPNode*)pNewNode;
  45. }
  46.  
  47. double CGPIsPoisonNode::dEvaluate(void)
  48. {
  49.     //This function returns one if the object directly in front of the agent is poison and zero otherwise
  50.     if(nLookForward()==3)
  51.     {
  52.         return 1.0;
  53.     }
  54.     else
  55.     {
  56.         return 0.0;
  57.     }
  58. }
  59.  
  60. char* CGPIsPoisonNode::psGetString(char* pString)
  61. {
  62.     if(pString!=NULL && strlen(pString)<10000)
  63.     {
  64.         sprintf(pString,"%s IsPoison()",pString);
  65.     }
  66.     return pString;
  67. }
  68.