Hunt the Wumpus using Racket

Hunt the Wumpus” was the first game I ever typed into a computer. Gregory Yob wrote it in the early 1970s, and I found it in The Best of Creative Computing, Volume 1. I copied the code painstakingly into Disk BASIC on an IBM PC XT. And then I played it for hours.

Street Wumpus Art

Image by tristan_roddis@flickr.

If there’s a language today as suited for beginners to learn with as BASIC was then, I believe that language is Racket. You can’t boot your computer into a copy of it in ROM, but you can download it for most operating systems, and start it as an application complete with its own integrated editor and interpreter.

Racket is a member of the Lisp family of language, and specifically a member of the Scheme sub-family. This means a few things. First, it means you get to type a lot of parentheses. Second, it means you will compose your program with lots of small functions and will have recursion. Recursion might be a difficult concept for some beginning programmers, but I would counter that it is much easier if you expose yourself to it early before you get FOR loops calcified in your brain.

Anyway, on to the fun! I have written a (slightly modified) version of Hunt the Wumpus in Racket that you can play. To run the game, download the source, load it into Racket’s graphical editor, Dr Racket, by using the “File > Open…” menu, click the Run button, and then type (hunt-the-wumpus) into the prompt (called the Interactions window in Racket and known as a REPL to many programmers.) An even better idea if you are trying to learn Racket is to type in the program by hand. You’ll learn more and probably cause some bugs, which is always exciting and eye-opening.

I left out two features that are in the original Wumpus game. In the original, the player only had five arrows and lost when they used all five up. Also, the player could start the game over with the same map if they lost.