Question
C++ Project: Minesweeper Counter In the game of Minesweeper, a player searches for hidden mines on a rectangular grid. The game board is represented by
C++ Project: Minesweeper Counter
In the game of Minesweeper, a player searches for hidden mines on a rectangular grid. The game board is represented by a greed of Boolean values stored as 0s and 1s marking the hidden mines locations with 1. Given such a grid, create a new grid of integers storing the count of mines in each neighborhood. The neighborhood for a location includes the location itself and its eight adjacent locations.
Grading: 1. The readGrid function 15 2. The makeGrid function 25 3. The writeScreen function 10 4. The writeGrid function 10
========================================================================
Given input .txt files:
"g0.txt":
3 5
1 0 0 0 1
0 0 0 0 1
0 0 0 1 1
"g1.txt":
6 5
1 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 1 1
"g2.txt":
5 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
"g3.txt":
15 10 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 0 0 0 0 1 1 0 0 0 1 1 1 0 0 0 0 0 1 1 0 0 0 0 1 0 1 0 1 0 0 0 1 0 0 0 0 1 0 0 1 0 1 0 1 0 0 0 0 1 0 0 0 0 0 1 1 0 0 0 1 0 1 0 0 0 0 0 1 1 0 0 0 0 1 0 1 0 1 0 0 0 1 0 0 0 0 0 1 1 0 0 0 0 1 0 1 0 1 0 0 0 1 0 0 0 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 0 0 0 0 1 1 0 0 0 1 1 1 0 0 0
================================================================= Given .cpp template to edit:
#include
using namespace std;
const int MAXGRIDSIZE = 100; // the maximum table size is 100
bool readGrid(string,int[][MAXGRIDSIZE],int, int); ///makeGrid(grid, rows, cols, cntGrid); void makeGrid(int[][MAXGRIDSIZE],int, int,int[][MAXGRIDSIZE]);
int main( void ) { string infileName[] = {"g0.txt", "g1.txt", "abc.txt", "g2.txt", "g3.txt", ""}; string outfileName[] = {"out0.txt", "out1.txt", "abcOut.txt", "out2.txt", "out3.txt", ""}; int grid[MAXGRIDSIZE][MAXGRIDSIZE] = {0}; // given grid int cntGrid[MAXGRIDSIZE][MAXGRIDSIZE] = {0}; // grid of counters int rows; // number of rows int cols; // number of columns int choice = 1; // to stop the program to allow the user to see the results one table at a time bool fileFound;
// test loop: takes the names of the input files from an array of names for (int i = 0; choice == 1 && infileName[i] != ""; i++) { fileFound = readGrid(infileName[i], grid, rows, cols); if (fileFound) { makeGrid(grid, rows, cols, cntGrid); writeScreen(infileName[i], rows, cols, cntGrid, outfileName[i]); writeGrid(outfileName[i], cntGrid, rows, cols); } else { cout > choice; }
return 0; } /** ///fileFound = readGrid(infileName[i], grid, rows, cols, cntGrid); */ bool readGrid(string inFile,int grid [][MAXGRIDSIZE],int rows, int cols) { return false; } /** */ void makeGrid(int[][MAXGRIDSIZE], int rows, int cols, int cntGrid[][MAXGRIDSIZE]);
Example: Given grid: 10 0 0 1 0 0 0 0 1 0 0 0 1 1 The grid of counters: 1 10 2 2 1 1 1 4 4 0 0 1 3 3 Input Data: Data about the grid's number of rows and columns are on the first line in the input file. In our example, the input file appears as follows: // This grid has 3 rows and 5 columns 3 5 1 0 0 0 1 0 0 0 0 1 0 0 0 1 1 Output Data 1. Screen output: display the name of the input file, the grid's number of rows and columns, the values in the four corners (upper left, upper right, lower right, lower left) in the grid of counters, and the name of the output file as shown below Input file name: "grid.txt" Grid size: 3 x 5 Corners: 1, 2, 3, 0 Output file name: "gridout.txt" 2. File output: write to an output file the grid's number of rows and columns and the contents of the grid of counters, as shown below: 3 5 1 1 0 2 2 1 1 1 4 4 0 0 1 3 3 Hint To simplify the counting process, add a "frame" of Os to the original grid: 0 0 0 0 0 o o 0 10 0 0 1 o 0 0 0 0 0 1 o 0 0 0 0 1 1 0 0 0 0 0 0 0 0Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started