- #1
needOfHelpCMath
- 72
- 0
4.12 Lab 5 : Visualizing Wumpus World
In this lab you are going to explore visualizing a grid-based Wumpus World using ASCII art. We will build this program incrementally.
1.) You need to take as input from the user the number of rows and columns, in that order. You also need to check if the inputs are within the accepted range of 2 to 9 inclusive. If the row size is invalid, output an error message: "Row size is illegal!" and similarly for the column size. For valid sizes, you print the grid.
For example, where the user enters 3 and 5:
Another example, where the user enter 1 and 3:
Each grid element consists of :
'-' for the horizontal (row)
'|' for the vertical (column)
2.) You need to add the user into the grid. We will use '*' to represent the user. The user's starting location should be random. You will output this location in the form "User location: (i, j)", where i is the row and j is the column. When you display the grid, you should output '*' in the user's location. In this lab, we will use a fixed seed value of 13 for the random generator.
For example, where the user enters 2 and 4:
3.) You are probably wondering what in the world is a wumpus. A wumpus is a monster that will devour the poor user! Of course, at the moment, Wumpus World does not actually contain a wumpus. So let's change that! Generate a random location on the grid for the wumpus. The user and the wumpus cannot start at the same location. You will output this location in the form "Wumpus location: (i, j)". For output, use 'W' to represent the wumpus' location.
For example, where the user enters 6 and 3:
4.) The last part of Wumpus World is adding in a pit. Create a random starting location for the pit. Again, ensure that the pit, the wumpus and the user are not starting on the same spot. You will output this location in the form "Pit location: (i, j)". For output, use 'o' to represent the pit.
For example, where the user enters 4 and 5:
** MY CODE BELOW**
In this lab you are going to explore visualizing a grid-based Wumpus World using ASCII art. We will build this program incrementally.
1.) You need to take as input from the user the number of rows and columns, in that order. You also need to check if the inputs are within the accepted range of 2 to 9 inclusive. If the row size is invalid, output an error message: "Row size is illegal!" and similarly for the column size. For valid sizes, you print the grid.
For example, where the user enters 3 and 5:
Code:
--- --- --- --- ---
| | | | | |
--- --- --- --- ---
| | | | | |
--- --- --- --- ---
| | | | | |
--- --- --- --- ---
Code:
Row size is illegal!
'-' for the horizontal (row)
'|' for the vertical (column)
2.) You need to add the user into the grid. We will use '*' to represent the user. The user's starting location should be random. You will output this location in the form "User location: (i, j)", where i is the row and j is the column. When you display the grid, you should output '*' in the user's location. In this lab, we will use a fixed seed value of 13 for the random generator.
For example, where the user enters 2 and 4:
Code:
User location: (0, 1)
--- --- --- ---
| | * | | |
--- --- --- ---
| | | | |
--- --- --- ---
For example, where the user enters 6 and 3:
Code:
User location: (0, 2)
Wumpus location: (3, 1)
--- --- ---
| | | * |
--- --- ---
| | | |
--- --- ---
| | | |
--- --- ---
| | W | |
--- --- ---
| | | |
--- --- ---
| | | |
--- --- ---
For example, where the user enters 4 and 5:
Code:
User location: (2, 1)
Wumpus location: (3, 1)
Pit location: (0, 4)
--- --- --- --- ---
| | | | | o |
--- --- --- --- ---
| | | | | |
--- --- --- --- ---
| | * | | | |
--- --- --- --- ---
| | W | | | |
--- --- --- --- ---
Code:
#include <iostream>
using namespace std;
int main ()
int numRows;
int numCols;
cin >> numRows;
cin >> numCols;
if (numRows > 9) {
cout << "Row size is illegal!" << endl;
}
if (numCols > 2) {
cout << "Row size is illegal!" << endl;
}