Task

Write a player for the game that follows the following rules:

The scorer will choose a number between set limits. The computer player will print a guess of the target number. The computer asks for a score of whether its guess is higher than, lower than, or equal to the target. The computer guesses, and the scorer scores, in turn, until the computer correctly guesses the target number.
The computer should guess intelligently based on the accumulated scores given. One way is to use a Binary search based algorithm.



Related tasks

   Guess the number/With Feedback
   Bulls and cows/Player


 
min = 1
max = 100
see "think of a number between " + min + " and " + max + nl
see "i will try to guess your number." + nl
while true
      guess =floor((min + max) / 2) 
      see "my guess is " + guess + nl
      see "is it higher than, lower than or equal to your number " give answer
      ans = left(answer,1)
      switch ans
             on "l" min = guess + 1 
             on "h" max = guess - 1 
             on "e" exit 
             other see "sorry, i didn't understand your answer." + nl
      off
end
see "goodbye." + nl
 