The game Hunt the Wumpus isn’t difficult to code in C. In fact, all you need do is start with the basic number-guessing game presented in last week’s Lesson and you can build just about any text-mode game. That’s what I did when I started my own C language version of Hunt the Wumpus.
Historically speaking, Wumpus was one of the first (if not the first) best-selling computer game. Written by Gregory Yob in 1973, it was was available for the various microcomputers of the era. In fact, I recall a version available for my ancient TRS-80 Model III, which I purchased in 1982. (Wikipedia Entry, Hunt the Wumpus)
The game is text-based. You read a description and type commands based on the description. In this game, the player is trapped in a cave or labyrinth of rooms. Each room is connected to three other rooms. The player moves between the rooms in an effort to hunt and kill the mysterious wumpus.
In addition to the wumpus, the labyrinth is populated with two giant bats and two bottomless pits. Entering a room with a bat causes the bat to lift you up and fly you to another, empty room in the labyrinth. Entering a room with a bottomless pit causes you to die, ending the game. If you’re unfortunate to enter a room with the wumpus, you’re eaten and, of course, die.
Fortunately, the game provides feedback when you’re near a room with the wumpus, a bat, or a pit. Here’s the text output:
If a bat is in a nearby room, the message is: You hear a rustling.
If a bottomless pit is in a nearby room, the message is: You feel a cold wind blowing from a nearby cave.
If the wumpus is nearby, the message is: You smell something terrible nearby.
Upon sensing the wumpus, you can fire an arrow into one of the three rooms. If you guess the room correctly, the wumpus is killed and you win the game. If you guess incorrectly, the wumpus has a 75-percent chance of fleeing to another random room in the labyrinth.
Programmer Yob designed the labyrinth to be more interesting than the grid patterns of early computer games. He chose a layout based on a dodecahedron, or 12-sided shape (Figure 1). The rooms are still interconnected, so it’s possible to navigate forward and background through the rooms in a predictable manner.
The original Hunt the Wumpus was written in BASIC, which was common in the early days of computing. I vaguely remember playing it back back then, though it’s simplistic and gets old quickly. Still, Wumpus provided the basis for other, more complex and involved text-mode games, such as Adventure and Zork.
Based on the information I provided in this Lesson, you could begin coding your own version of Hunt the Wumpus. The details presented were all I started out with. Of course, coding the game took a while, mostly to work out the bugs, but also to re-think my approach several times. I cover the specifics in next week’s Lesson.