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


' FB 1.05.0 Win64
 
Dim hle As String
Dim lowest As Integer = 1
Dim highest As Integer = 20
Dim guess As Integer = 10
Print "Please choose a number between 1 and 20 but don't tell me what it is yet"
Print
Do
  Print "My guess is"; guess
  Do
    Input "Is this higher/lower or equal to your chosen number h/l/e : "; hle
    hle = LCase(hle)
    If hle = "l" AndAlso guess = highest Then
      Print "It can't be more than"; highest; ", try again"
      hle = "i" '' invalid
    ElseIf hle = "h" AndAlso guess = lowest Then
      Print "It can't be less than"; lowest; ", try again"
      hle = "i"
    End If    
  Loop Until hle = "h" OrElse hle = "l" OrElse hle = "e"
  If hle = "e" Then
    Print "Good, thanks for playing the gaame with me!"
    Exit Do
  ElseIf hle = "h" Then
    If highest > guess - 1 Then highest = guess - 1   
  Else
    If lowest < guess + 1  Then lowest = guess + 1
  End If  
  guess = (lowest + highest)\2  
Loop
End