Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The Hunt the Wumpus game. (C++) *** NOTE: Please read the requirements carefully. Event class needs to be polymorphic, using virtual functions only. Please include

The Hunt the Wumpus game. (C++) *** NOTE: Please read the requirements carefully. Event class needs to be polymorphic, using virtual functions only. Please include a screenshot proving your code works! Thanks!

Hunt the Wumpus is a game set inside the cave of the Wumpus, a scary, gold-harding monster who likes to eat people who disturb its sleep. The player's goal is to guide an adventurer to kill the Wumpus, find its hidden gold, and escape alive. The Wumpus lives in a large cave of rooms arranged in a grid, where each room at has four tunnels leading to the rooms to the north, east, south, and west.

The adventurer starts the game in a random empty room in the Wumpus cave. Her starting position is also the location of the escape rope that she must use to escape after she's completed her task.

Each room may be empty, or it may contain one (and only one) of four "events" (all described below): two kinds of dangerous hazards, the terrifying Wumpus, and the gold treasure. When the adventurer is in a room thats adjacent to one containing an "event", the player will receive a percept (a message) to inform them about the event the adventurer is close to.

If the adventurer perishes while searching for the Wumpus, the player should be presented with the option to start the game over with the same cave configuration, start the game over with a new random cave configuration, or quit the game entirely.

The player wins the game if they can safely guide the adventurer through the cave to kill the Wumpus, pick up the gold, and make it back to the escape rope unharmed!

Game elements

The adventurer

Each turn you may take one of two actions to guide the adventurer:

  • Move: You can move through a tunnel to an adjacent room.

  • Fire an Arrow: The adventurer begins the game with three arrows. As long as the adventurer still has at least one arrow, the player can choose to fire one in any direction (i.e. north, south, east, or west). The arrow continues flying in the same direction until it hits a wall or travels through three rooms. If the arrow enters the Wumpus room, it pierces the Wumpus heart and kills the monster. If the adventurer runs out of arrows without having killed the Wumpus, you lose.

The Wumpus

Usually, the Wumpus is peacefully asleep in its cave. Two things wake the Wumpus up, however: the adventurer entering its room or shooting an arrow and missing it. If the Wumpus wakes up while in the same room as the adventurer, the Wumpus will angrily eat the adventurer, ending the game. If the Wumpus just wakes up from hearing an arrow being fired, though, theres a 75% chance it will move to a random empty room in the cave to avoid being found.

Hazards

There are two kinds of hazards in the Wumpus' cave:

  • Bottomless pits: Two of the cave's rooms have bottomless pits in them. If the adventurer enters a room with a bottomless pit, she falls in and dies, and the player loses.

  • Super bats: Two rooms have super bats. If the adventurer enters a room that contains super bats, an angry bat grabs her and takes her to some other room at random (which could be dangerous!).

The gold

The gold is a treasure sitting in a room that contains neither a hazard nor the wumpus. If the adventurer is in a room containing the gold, she automatically picks it up and takes it with her.

Percepts

When the adventurer is in a room directly adjacent to to a room containing an "event", the player receives the following messages:

  • Wumpus: "You smell a terrible stench."
  • Super bats: "You hear wings flapping."
  • Bottomless pit: "You feel a breeze."
  • Gold: "You see a glimmer nearby."

Notice that theres no percept for the escape rope! That means the player will have to remember where they started and find their way back to that tile after theyve completed their task.

As an example of how the percepts work, if the adventurer is standing in an empty room with the Wumpus one room to the North, the Gold one room to the East, and Bats two rooms to the South, they would receive the following messages at the beginning of their turn:

You smell a terrible stench. You see a glimmer nearby. 

Remember, the percepts dont tell you where the hazard or gold is, just that its somewhere close!

Program requirements

  • Your program should allow the user to play Hunt the Wumpus, as described above.

  • The Wumpus' cave is represented by a square grid. The size of the grid (i.e. the number of rooms on one side of the square) should be specified as a command line parameter to your program. Caves smaller than four rooms on a side aren't allowed. You should visualize the grid to allow the user to play the game. In particular, you should display the grid, and indicate within the grid which room the player is in. An example visualization of a 4x4 grid might look like this, where the * character represents the location of the adventurer:

    +---+---+---+---+ | | | | | | | | | | | | | | | +---+---+---+---+ | | | | | | | | | | | | | | | +---+---+---+---+ | | | | | | | | * | | | | | | | +---+---+---+---+ | | | | | | | | | | | | | | | +---+---+---+---+ 
  • Your code must have the following classes: Room, Event, Wumpus, Bats, Pit, and Gold. You may create more classes if they would be helpful.

  • The Event class must be abstract (i.e. it must contain purely virtual functions), and the Wumpus, Bats, Pit, and Gold classes should all be derived from Event. Remember, any event does something when the adventurer enters the same room as the event, and will display a message when the adventurer is nearby. Your design of the Event class should reflect this. For example, your Event class might have a percept() method that is called whenever the adventurer is in a room adjacent to the event, where the Wumpus, Bats, Pit, and Gold classes implement their own specific versions of the percept() method. Similarly, your Event class might have an encounter() method that is called when the adventurer enters the same room as the event, with the individual event classes implementing their own specific versions of encounter().

  • You must use the Event classes polymorphically. In other words, your Room class may only contain a member of the Event class but not members of the Wumpus, Bats, Pit, or Gold classes.

  • Each Room contains at most one Event, but it may not contain any Event. The design of your Room class should reflect this.

  • The grid representing your cave should be implemented using the std::vector class.

Hints

  • Polymorphism only works when you are working with references or pointers. If you use the value of an object directly, it may not select the correct member function.

  • Hunt the Wumpus is a game all about hiding information from the player, which might make it hard to debug! To get around this problem, you might want to create a debugging-only map display so that you can tell exactly whats in the cave while youre testing your program. Just make sure you disable this before submitting the assignment!

  • Hunt the Wumpus is a very common introductory programming project. This assignment, however, is designed to specifically include the programming concepts youve seen in this class so far. Its very likely that other versions of Hunt the Wumpus you could find do not correctly implement whats described above.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions