How to resolve the algorithm Guess the number/With feedback (player) step by step in the Arturo programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Guess the number/With feedback (player) step by step in the Arturo programming language

Table of Contents

Problem Statement

Write a player for the game that follows the following rules: The computer should guess intelligently based on the accumulated scores given. One way is to use a Binary search based algorithm.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Guess the number/With feedback (player) step by step in the Arturo programming language

Source code in the arturo programming language

print {:
Think of a number between 1 and 10 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 =
:}

rmin: 1
rmax: 10

while ø [
    guess: random rmin rmax
    print ["My guess is:" guess]
    inputOk: false
    while [not? inputOk][
        hle: strip input "How did I do? (h)igh, (l)ow, (=): "
        case [hle]
            when? [="h"][
                if? rmin =< dec guess [rmax: dec guess, inputOk: true]
                else -> print "\tThat doesn't make any sense. I cannot find the number..."
            ]
            when? [="l"][
                if? (inc guess) =< rmax [rmin: inc guess, inputOk: true]
                else -> print "\tThat doesn't make any sense. I cannot find the number..."
            ]
            when? [="="][
                print ""
                print "Great! I found it! :)"
                print "Thanks for keeping the score."
                exit
            ]
            else [
                print "\tPlease, check your input; it doesn't appear to be correct!"
            ]
    ]
    print ""
]


  

You may also check:How to resolve the algorithm Loops/Infinite step by step in the 4DOS Batch programming language
You may also check:How to resolve the algorithm Higher-order functions step by step in the DWScript programming language
You may also check:How to resolve the algorithm Continued fraction/Arithmetic/G(matrix ng, continued fraction n) step by step in the zkl programming language
You may also check:How to resolve the algorithm Sierpinski triangle step by step in the Arturo programming language
You may also check:How to resolve the algorithm Loops/For step by step in the Lang5 programming language