home *** CD-ROM | disk | FTP | other *** search
/ AI Game Programming Wisdom / AIGameProgrammingWisdom.iso / SourceCode / 07 DecisionMaking Architectures / 03 Laramée / WinMain.cpp < prev   
Encoding:
C/C++ Source or Header  |  2001-10-18  |  3.1 KB  |  80 lines

  1. /****************************************************************
  2.  *
  3.  * MAIN PROGRAM
  4.  *
  5.  * Here, we assume that the various sources of evidence have
  6.  * examined data before coming up with their beliefs.  How to do
  7.  * that should be fairly straightforward.
  8.  *
  9.  ***************************************************************/
  10.  
  11. #include "Evidence.h"
  12. #include <iostream.h>
  13.  
  14. int main( int argc, char ** argv )
  15. {
  16.     // The evidence provided by the catcher
  17.     // Of the pitcher's last 10 pitches, 8 have hit the catcher's
  18.     // target or come reasonably close, while 2 have not.  
  19.     BodyOfEvidence catcher;
  20.     catcher.AcceptEvidence( eventPitcherOK, 0.8 );
  21.     catcher.AcceptEvidence( eventPitcherNervous | eventPitcherTired, 0.2 );
  22.  
  23.     // The evidence provided by the pitch counts
  24.     // The pitcher normally tires after 100 pitches, and he has now
  25.     // reached 115; of the last 20 pitches, 75% were thus beyong his
  26.     // normal limit and suggest he is probably getting tired...
  27.     BodyOfEvidence pitchCount;
  28.     pitchCount.AcceptEvidence( eventPitcherOK | eventPitcherNervous, 0.25 );
  29.     pitchCount.AcceptEvidence( eventPitcherTired, 0.75 );
  30.  
  31.     // The evidence provided by the radar gun examines the speeds of the
  32.     // last 10 pitches thrown:
  33.     // 2 were clocked at over 92 mph (which suggests that the pitcher is fine)
  34.     // 1 was clocked at between 87 and 92 (which suggests that he is either 
  35.     //            tired or being cautious)
  36.     // 4 were clocked at less than 87 (which suggests that his arm is tired) 
  37.     // and 3 were changeups or breaking balls (in which case the radar gun 
  38.     //            evidence is inconclusive).
  39.     BodyOfEvidence radarGun;
  40.     radarGun.AcceptEvidence( eventPitcherOK, 0.2 );
  41.     radarGun.AcceptEvidence( eventPitcherTired | eventPitcherNervous, 0.1 );
  42.     radarGun.AcceptEvidence( eventPitcherTired, 0.4 );
  43.     radarGun.AcceptEvidence( eventPitcherOK | eventPitcherNervous | eventPitcherTired, 0.3 );
  44.  
  45.     // The evidence provided by the state of the game: of the last
  46.     // 10 pitches thrown:
  47.     // 1 was a strike or resulted in an out (a good sign)
  48.     // 2 were balls with runners on base (he may be distracted or tired)
  49.     // 1 was grounded for a base hit (the hitters are catching up)
  50.     // 6 were balls with nobody on (he can't hit the plate)
  51.     BodyOfEvidence stats;
  52.     stats.AcceptEvidence( eventPitcherOK, 0.1 );
  53.     stats.AcceptEvidence( eventPitcherTired | eventPitcherNervous, 0.2 );
  54.     stats.AcceptEvidence( eventPitcherTired, 0.1 + 0.6 );
  55.  
  56.  
  57.     // Now, we combine the evidence
  58.     BodyOfEvidence manager;
  59.     manager.Copy( catcher );
  60.     manager.Combine( pitchCount );
  61.     manager.Combine( radarGun );
  62.     manager.Combine( stats );
  63.  
  64.     // Let's look at the evidence, shall we?
  65.     cout << "MANAGER'S EVIDENCE" << endl;
  66.     cout << "------------------" << endl << endl;
  67.     manager.Print();
  68.     cout << endl;
  69.     
  70.     // And now, let's make a decision
  71.     if( manager.Credibility( eventPitcherTired ) > 0.75 )
  72.         cout << "Time to go to the bullpen!" << endl;
  73.     else if ( manager.Plausibility( eventPitcherNervous ) > 0.60 )
  74.         cout << "Time to visit the mound" << endl;
  75.     else
  76.         cout << "The pitcher is OK, no need to do anything" << endl;
  77.  
  78.     return 0;
  79. }
  80.