home *** CD-ROM | disk | FTP | other *** search
/ AI Game Programming Wisdom / AIGameProgrammingWisdom.iso / SourceCode / 11 Learning / 01 Manslow / GPExample / CGPRandomNumberNode.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-10  |  1.2 KB  |  59 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 "CGPRandomNumberNode.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. CGPRandomNumberNode RandomNumberPrototype;
  21.  
  22. CGPRandomNumberNode::CGPRandomNumberNode()
  23. {
  24.     nType=12;
  25.  
  26.     pChildren=NULL;
  27.     ulNumberOfChildren=0;
  28.  
  29.     sprintf(psName,"RandomNumberNode");
  30.     nIsPrototype=1-AddToPrototypeList();
  31.     dPrior=0.1;
  32. }
  33.  
  34. CGPRandomNumberNode::~CGPRandomNumberNode()
  35. {
  36. }
  37.  
  38. CGPNode *CGPRandomNumberNode::pGetCopy(CGP* pGP)
  39. {
  40.     CGPRandomNumberNode *pNewNode=new CGPRandomNumberNode;
  41.     assert(!(pNewNode==NULL));
  42.     return (CGPNode*)pNewNode;
  43. }
  44.  
  45. double CGPRandomNumberNode::dEvaluate(void)
  46. {
  47.     //This funciton returns zero of one, each  with probability 0.5
  48.     return rand()%2;
  49. }
  50.  
  51. char* CGPRandomNumberNode::psGetString(char* pString)
  52. {
  53.     if(pString!=NULL && strlen(pString)<10000)
  54.     {
  55.         sprintf(pString,"%s Random()",pString);
  56.     }
  57.     return pString;
  58. }
  59.