Task

Write a game (computer program) that follows the following rules:

 The computer chooses a number between given set limits.
 The player is asked for repeated guesses until the the target number is guessed correctly
 At each guess, the computer responds with whether the guess is:
 higher than the target,
 equal to the target, 
 less than the target,   or
 the input was inappropriate. 


Related task

   Guess the number/With Feedback (Player)


[indent=4]
/*
   Number guessing with feedback, in Genie
   from https://wiki.gnome.org/Projects/Genie/AdvancedSample
 
   valac numberGuessing.gs
   ./numberGuessing
*/
class NumberGuessing
 
    prop min:int
    prop max:int
 
    construct(m:int, n:int)
        self.min = m
        self.max = n
 
    def start()
        try_count:int = 0
        number:int = Random.int_range(min, max)
 
        stdout.printf("Welcome to Number Guessing!\n\n")
        stdout.printf("I have thought up a number between %d and %d\n", min, max)
        stdout.printf("which you have to guess. I will give hints as we go.\n\n")
 
        while true
            stdout.printf("Try #%d, ", ++try_count)
            stdout.printf("please enter a number between %d and %d: ", min, max)
            line:string? = stdin.read_line()
            if line is null
                stdout.printf("bailing...\n")
                break
 
            input:int64 = 0
            unparsed:string = ""
            converted:bool = int64.try_parse(line, out input, out unparsed)
            if not converted or line is unparsed
                stdout.printf("Sorry, input seems invalid\n")
                continue
 
            guess:int = (int)input
            if number is guess
                stdout.printf("Congratulations! You win.\n")
                break
            else
                stdout.printf("Try again. The number in mind is %s than %d.\n",
                   number > guess ? "greater" : "less", guess)
 
init
    var game = new NumberGuessing(1, 100)
    game.start()