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


V (target_min, target_max) = (1, 10)
V (mn, mx) = (target_min, target_max)
 
print(
‘Think of a number between #. and #. and wait for me to guess it.
On every guess of mine you should state whether the guess was
too high, too low, or equal to your number by typing h, l, or =
’.format(target_min, target_max))
 
V i = 0
L
   i++
   V guess = (mn + mx) I/ 2
   V txt = input(‘Guess #2 is: #2. The score for which is (h,l,=): ’.format(i, guess)).trim(‘ ’).lowercase()[0]
   I txt !C ‘hl=’
      print(‘  I don't understand your input of '#.' ?’.format(txt))
      L.continue
   I txt == ‘h’
      mx = guess - 1
   I txt == ‘l’
      mn = guess + 1
   I txt == ‘=’
      print(‘  Ye-Haw!!’)
      L.break
   I (mn > mx) | (mn < target_min) | (mx > target_max)
      print(‘Please check your scoring as I cannot find the value’)
      L.break
 
print("\nThanks for keeping score.")