Skip to content

Demo: guess — number-guessing game (port from BASIC) #3

Description

@softwarewrighter

Smalltalk port of the classic number-guessing game from
`web-sw-cor24-basic/examples/guess.bas`.

Of the four interactive BASIC demos (`guess`, `robot-chase`,
`startrek`, `trek-adventure`), `guess` is the only one worth
porting in the near term. The other three are homages to BASIC
heritage and don't translate cleanly to Smalltalk idiom. `guess`
is small, OO-friendly, and pulls weight as a "first interactive
game" for the dialect.

Mechanics

  • Computer picks a secret integer 1..100. PRNG seed: lift the
    `R = R * 97 + 1 mod 8191` PRNG that startrek.bas uses, or
    promote it to a `Random` class.
  • User types a guess via `INPUT` / stdin.
  • Computer responds:
    • too high → "lower" (or `1` in v0)
    • too low → "higher" (or `2` in v0)
    • match → "got it in N guesses" (or `0` and the count in v0)
  • Loop until match (and/or N-guess budget).

Dialect requirements

  • v0 (current dialect) — feasible but degraded UX. Output is
    numeric only (`1` / `2` / `0`), no friendly prompts. Sketch:
    • `Game` class with `secret`, `guesses` instance variables.
    • `Game>>play` recursive (no blocks/loops yet) or use BASIC's
      GOTO at the driver level.
    • `Game>>respondTo:` polymorphic on guess vs secret.
  • v1 (strings) — proper UX with "higher" / "lower" /
    "got it in N guesses". This is the right form to ship.
  • v2 (blocks) — `[ guess = secret ] whileFalse: [ ... ]`
    reads as intended.

Recommendation

Hold until v1 (strings) lands so the demo prints recognizable text;
the v0 form is too cryptic to be a useful "first interactive game"
demo. Filing this now to track intent and reserve the slot.

Web demo coverage

`web-sw-cor24-smalltalk`'s
runner already supports interactive demos via the BASIC `INPUT`
pause flow (proven by D5 calc). When this lands in
`examples/guess.bas`, mark `interactive: true` in the web's
`src/demos.rs` and the input row appears automatically.

See also: dialect roadmap issue (v1 strings).

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions