// AI that can guess a number between 1 and 100 // By Rune S. Johansen, June 2000. #ifndef (Randomness) #declare Randomness = 0; #end #if (file_exists("guessdat.inc")=0) #declare Time = 1; #else #include "guessdat.inc" #end #declare Seed = seed(Time); #declare Error = false; #ifndef (Name) #debug "\n\n\nWon't you tell me what your name is?\nPlease #declare the string \"Name\"." #declare Error=true; #else #debug concat("\n\n\nHello ",Name,"!") #if (Time=1) #debug "\nI don't think I've played with you before. It'll be fun!" #end #if (Time>=2) #debug concat("\nThis is our game nr. ",str(Time,0,0),"!") #end #if (Time>=20) #debug " You are kind of hooked on this game, eh?" #end #if (Time>=50) #debug " Really hooked!" #end #end #ifndef (Number) #debug concat("\n\nErr, ",Name,", it's not enough to *think* of a number. You have to write it down.\nYou must #declare the value \"Number\".") #declare Error=true; #else #if (Number>100|Number<1) #debug concat("\n\nI haven't looked at your number ",Name,", but I have a strange feeling that you're cheating!\nPlease keep the value \"Number\" between 1 and 100.") #declare Error=true; #end #if (int(Number)!=Number) #debug concat("\n\nI haven't looked at your number ",Name,", but I have a strange feeling that you're cheating!\nPlease use integers for the value \"Number\".") #declare Error=true; #end #end #if (Error=false) #declare Fair = log(Limit)/log(2); #debug str(Fair,0,0) #declare Random = int(rand(Seed)*2.99); #if (Random=0) #debug "\n\nWatch me guess the number you have typed in!\n" #end #if (Random=1) #debug "\n\nI will now guess the number you're thinking of!\n" #end #if (Random=2) #debug "\n\nLet the guessing begin!\n" #end #declare Endgame = false; #declare Lowest = 1; #declare Highest = Limit; #declare Tries = 1; #while (Endgame=false) #declare Guess = int( (Highest-Lowest)*(rand(Seed)*Randomness+(1-Randomness)/2) )+Lowest; #if (Highest=Lowest) #debug concat("\nWell, the only possible number left is ",str(Guess,0,0),"...") #else #declare Random = int(rand(Seed)*2.99); #if (Random=0) #debug concat("\nI'm guessing that it's ",str(Guess,0,0),"!") #end #if (Random=1) #debug concat("\nThe number shouldn't happen to be ",str(Guess,0,0),"?") #end #if (Random=2) #debug concat("\nYou're probably thinking of ",str(Guess,0,0),"!") #end #end #if (Guess!=Number) #declare LoHi = ( Number4/7*Fair&Tries<=6/7*Fair) #debug concat("\nIt took me ",str(Tries,0,0)," tries! Not too bad!") #end #if (Tries>6/7*Fair&Tries<=8/7*Fair) #debug concat("\nIt took me ",str(Tries,0,0)," tries. That's okay, I guess...") #end #if (Tries>8/7*Fair&Tries<=10/7*Fair) #debug concat("\nIt took ",str(Tries,0,0)," tries. That's too much! Please lower my Randomness value!") #end #if (Tries>10/7*Fair) #debug concat("\nIt took me ",str(Tries,0,0)," tries. Aaarrgh! Please lower my Randomness value!!!") #end #declare Endgame = true; #end #declare Tries = Tries+1; #end #declare Time = Time+1; #end #debug "\n\n" #fopen Data "guessdat.inc" write #write (Data,"#declare Time = ",Time,";") #fclose Data sphere {-z, 0.1 pigment {color 0}}