CS302 / Program 5

Sections 15 & 22
Instructor: Colby O'Donnell

Due Date: Wednesday, Nov 12, 8:30 AM


Hunt the Wumpus

Program Five will demonstrate the use of arrays and files. This program will be somewhat longer than previous assignments. It would be more aptly named a project. Please use this extra time to make a plan of attack before writing code -- design function prototypes and algorithms before digging into the heart of the program. Good luck!

Background

This program is a variation on a very old computer game called Hunt the Wumpus. In this game, you will move a human through a maze in search of a creature known only as The Wumpus. The terrified Wumpus can smell you coming, and will attempt to stay away from you.

The Maze

The maze will be represented on the screen as a rectangle of characters. A . represents open space, a X represents a wall, a * represents the human player, and a # represents The Wumpus. Both the player and the wumpus are free to move one square at a time in any direction (including diagonally) as long as there is no wall in the way. Neither the player or The Wumpus may move off of the top, bottom, left, or right of the maze. An example display including a player and a Wumpus might look like this:
 
........................ 
..X.............XXXXXX..  
..X..XXXXXXXXXXXX..#.... 
..X.............X.......  
XXXXXXXX....X...XXXXXXX. 
.......X....X...X.....X.  
.*.....X....XXX.X.....X. 
.......XXXXXX...X.X.X.X.  
..................X.X.X. 
XXXXXXXXXXXXXXX...X.X.X.  
..X..........X....X.X.X. 
..X..XXXXXXXXXX...X.XXX. 
..................X..... 
The maze your program must use is contained in P:\course\cs302\public\html\C++\wumpus\maze.1. The maze must be loaded from this file at the beginning of your program. Notice that this file also contains the initial positions of the player and The Wumpus. The maze will be 24 characters wide and 13 characters tall. However, do not use these numbers throughout your program. Declare some appropriate global constants and use those instead.

The Game

In every round of the game, your program will display the maze, including the positions of the player and The Wumpus. The program must then ask the user what direction he/she wishes to go. The user may specify a direction by entering a number. The direction is given by that number's position on the numeric keypad. For example, 8 means go north, 9 means go northeast, and 6 means go east. Thus, the player may move one square in any straight or diagonal direction. (You may need to press the NumLock key to make the keypad word).

There are, however, some limitations. The player may not enter a square containing a wall, nor may the player move off the edge of the map. If the player selects a valid direction, the player will move one square in that direction. If the player enters the same location as The Wumpus, the game is over and the player wins. If not, the program decides how the wumpus must move, and then begins a new round. The player may end the program prematurely by entering 'q'.

If the player wins the game, the program should ask if the player wishes to begin again.

The Wumpus

The Wumpus is a poor little creature who does not want to be caught by the player. You may give the Wumpus whatever decision-making ability you feel is necessary to make it evade the player. However, it must follow these two rules:
  • The Wumpus cannot pass through walls or go off the edge of the board.
  • The Wumpus may not sit still. It must move exactly one square every round, unless it is trapped on all sides.
  • You could have the Wumpus move randomly (but legally), or you could make the Wumpus smart enough to move away from the player. It's up to you. No matter what method you use, comment your Wumpus code enough to make its purpose obvious.

    Program Structure

    As always, your program must have the elements of good design: modularity, readability, etc. I strongly suggest you split up your program into the following functions:
    bool	load_maze( ... );		/* Read the maze from a file */
    void	print_maze( ... );		/* Print the maze */
    char	get_player_move( ... );		/* Get the player's action */
    char	get_wumpus_move( ... );		/* Decide The Wumpus' action */
    bool	is_legal_move( ... );		/* Can a player or a wumpus move */
    					/*  to this position? */
    
    Additional functions will probably be necessary. You may add functions as you see fit. Whatever program design you use, provide enough comments so that the reader can easily understand your code.

    The (...) indicates you are free to define whatever parameters you feel are necessary. In class, I have discouraged the use of global variables. This program might be simpler to write using a limited number of globals. Please comment any global variables to provide a brief explanation why using non-global variables is impractical for your purposes.

    Handin Procedure

    • You should turn in the following files:
      • wumpus.cpp
      • prog5.exe
    • The path to your turnin directory is: p:\course\cs302\handin\colbster\YOUR_USER_NAME\P5
    • I will allocate points for correct handin. If you have questions or problems, ask me early on!
    (Last modified: 10/29/97)