Damian Walker

Personal Web Pages

Hunt the Hurkle: Another Tiny BASIC game

Sunday, 11th August 2019

It looks like I jumped in at the deep end with Hunt the Wumpus. Simple as it is, when I chose it as a sub-project I hadn't realised that it's very much more complex than Hunt the Hurkle. It's taken me barely half an hour to develop a Hunt the Hurkle game, producing versions for both a modern compiler and the original interpreter. The entire program, stripped of comments, weighs in at 34 lines instead of the 182 of Wumpus. First I'll give the readable version of the code:

    REM
    REM Hunt the Hurkle
    REM A Demonstration Program for Tiny BASIC
    REM

    REM --- Variables
    REM     G: hurkle column
    REM     H: hurkle row
    REM     M: moves taken
    REM     S: random number seed
    REM     X: player guess column
    REM     Y: player guess row

    REM --- Initialise the random number generator
    PRINT "Think of a number."
    INPUT S

    REM --- Initialise the game
    GOSUB 200
    LET G=R-(R/10*10)
    GOSUB 200
    LET H=R-(R/10*10)
    LET M=0

    REM --- Input player guess
 10 PRINT "Where is the hurkle? Enter column then row."
    INPUT X,Y
    IF X>=0 THEN IF X<=9 THEN IF Y>=0 THEN IF Y<=9 THEN GOTO 20
    PRINT "That location is off the grid!"
    GOTO 10

    REM --- Process player guess
 20 LET M=M+1
    PRINT "The Hurkle is..."
    IF G<X THEN IF H<Y THEN PRINT "...to the northwest."
    IF G=X THEN IF H<Y THEN PRINT "...to the north."
    IF G>X THEN IF H<Y THEN PRINT "...to the northeast."
    IF G>X THEN IF H=Y THEN PRINT "...to the east."
    IF G>X THEN IF H>Y THEN PRINT "...to the southeast."
    IF G=X THEN IF H>Y THEN PRINT "...to the south."
    IF G<X THEN IF H>Y THEN PRINT "...to the southwest."
    IF G<X THEN IF H=Y THEN PRINT "...to the west."
    IF G=X THEN IF H=Y THEN GOTO 40
    IF M>6 THEN GOTO 50
    PRINT "You have taken ",M," turns so far."
    GOTO 10

    REM --- Player has won
 40 PRINT "...RIGHT HERE!"
    PRINT "You took ",M," turns to find it."
    END

    REM --- Player has lost
 50 PRINT "You have taken too long over this. You lose!"
    END

    REM --- Random number generator
200 LET S=(42*S+127)-((42*S+127)/126*126)
    LET R=S
    RETURN

I paid more attention to the choice of line numbers in this game than I did in Wumpus, to ensure that the line numbers would fall within the limits of the original interpreter without tedious renumbering. Here's the version as it would run on the original interpreter.

  1 PRINT "Think of a number."
  2 INPUT S
  3 GOSUB 200
  4 LET G=R-(R/10*10)
  5 GOSUB 200
  6 LET H=R-(R/10*10)
  7 LET M=0
 10 PRINT "Where is the hurkle? Enter column then row."
 11 INPUT X,Y
 12 IF X>=0 THEN IF X<=9 THEN IF Y>=0 THEN IF Y<=9 THEN GOTO 20
 13 PRINT "That location is off the grid!"
 14 GOTO 10
 20 LET M=M+1
 21 PRINT "The Hurkle is..."
 22 IF G<X THEN IF H<Y THEN PRINT "...to the northwest."
 23 IF G=X THEN IF H<Y THEN PRINT "...to the north."
 24 IF G>X THEN IF H<Y THEN PRINT "...to the northeast."
 25 IF G>X THEN IF H=Y THEN PRINT "...to the east."
 26 IF G>X THEN IF H>Y THEN PRINT "...to the southeast."
 27 IF G=X THEN IF H>Y THEN PRINT "...to the south."
 28 IF G<X THEN IF H>Y THEN PRINT "...to the southwest."
 29 IF G<X THEN IF H=Y THEN PRINT "...to the west."
 30 IF G=X THEN IF H=Y THEN GOTO 40
 31 IF M>6 THEN GOTO 50
 32 PRINT "You have taken ",M," turns so far."
 33 GOTO 10
 40 PRINT "...RIGHT HERE!"
 41 PRINT "You took ",M," turns to find it."
 42 END
 50 PRINT "You have taken too long over this. You lose!"
 51 END
200 LET S=(42*S+127)-((42*S+127)/126*126)
201 LET R=S
202 RETURN

It would take only a trivial modification to adapt this to play the game of Mugwump, so you can expect to see that listing pretty soon.