On this page:
guess-with-gui
guess-with-gui-3
guess-with-gui-list

1.4 Guessing Numbers: "guess.rkt"🔗ℹ

 (require htdp/guess) package: htdp-lib

The teachpack provides functions to play a guess-the-number game. Each function display a GUI in which a player can choose specific values for some number of digits and then check the guess. The more advanced functions ask students to implement more of the game.

procedure

(guess-with-gui check-guess)  true

  check-guess : (-> number? number? symbol?)
The check-guess function consumes two numbers: guess, which is the user’s guess, and target, which is the randomly chosen number-to-be-guessed. The result is a symbol that reflects the relationship of the player’s guess to the target.

procedure

(guess-with-gui-3 check-guess)  true

  check-guess : (-> digit? digit? digit? number? symbol?)
The check-guess function consumes three digits (digit0, digit1, digit2) and one number (target). The latter is the randomly chosen number-to-be-guessed; the three digits are the current guess. The result is a symbol that reflects the relationship of the player’s guess (the digits converted to a number) to the target.

Note: digit0 is the least significant digit that the user chose and digit2 is the most significant one.

procedure

(guess-with-gui-list check-guess)  true

  check-guess : (-> (list-of digit?) number? symbol?)
The check-guess function consumes a list of digits (digits) and a number (target). The former is a list that makes up the user’s guess, and the latter is the randomly chosen number-to-be-guessed. The result is a symbol that reflects the relationship of the player’s guess (the digits converted to a number) to the target.

Note: the first item on digits is the least significant digit that the user chose, and the last one is the most significant digit.