home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.ai      Awaiting the gospel from Sarah Connor      1,954 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 1,670 of 1,954   
   Michael B Allen to All   
   The Fire Program   
   19 Feb 08 03:04:10   
   
   From: miallen@ioplex.com   
      
   Hi,   
      
   I was just thinking about a "closed" program that an AI "agent" might   
   "learn" from (don't know the right terminology sorry) and thought it was   
   simple and elegant so I thought I'd write it up and post it for whatever   
   it's worth.   
      
   Enjoy,   
   Mike   
      
   To run do:   
      
   $ ./fire   
   1   
   6   
   4   
   choice: 4   
   You are warm and dry.   
   4   
   2   
   0   
   choice: 2   
   You are warm and dry.   
   2   
   0   
   5   
   choice: 2   
   You are warm and dry.   
   5   
   3   
   1   
   choice: 1   
   You are getting burned!   
   1   
   6   
   4   
   choice: 6   
   You are cold and wet.   
   3   
   1   
   6   
   choice: q   
   $   
      
   --8<--   
      
   /* The Fire Program   
    * by Michael B Allen   
    * This software is public domain.   
    * $ gcc -Wall -W -o fire fire.c   
    */   
      
   #include    
   #include    
      
   #define MIN(a,b) ((a) < (b) ? (a) : (b))   
   #define MAX(a,b) ((a) > (b) ? (a) : (b))   
      
   int   
   main(void)   
   {   
       int c0, c1, c2, ch = 1, min, max;   
      
       for ( ;; ) {   
           switch (ch) {   
               case '\r':   
               case '\n':   
                   break;   
               case 'q':   
               case EOF:   
                   return EXIT_SUCCESS;   
               default:   
                   min = MIN(MIN(c0, c1), c2);   
                   max = MAX(MAX(c0, c1), c2);   
                   if ((ch - '0') == min) {   
                       printf("You are getting burned!\n");   
                   } else if ((ch - '0') == max) {   
                       printf("You are cold and wet.\n");   
                   } else {   
                       printf("You are warm and dry.\n");   
                   }   
               case 1:   
                   c0 = rand() % 7;   
                   c1 = (c0 + 19) % 7;   
                   c2 = (c1 + 19) % 7;   
                   printf("%d\n%d\n%d\nchoice: ", c0, c1, c2);   
           }   
      
           ch = fgetc(stdin);   
       }   
   }   
      
   [ comp.ai is moderated ... your article may take a while to appear. ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca