COP3223 Program #8: Minesweeper Setup (minesweeper.c) solution

$14.99

Original Work ?
Category: You will Instantly receive a download link for .ZIP solution file upon Payment

Description

5/5 - (1 vote)

For this week you will only write one program. Your program will read its input from the file,
“mine.txt” and write output to the screen.
This file will have information about multiple minesweeper boards. In particular, it will tell you
the location of each mine on the board for your program to evaluate. Your program must read in
this information and then print out a version of the board that has a ‘*’ where each bomb is
located and a number indicating the number of adjacent bombs for each non-bomb location.
The format of the input file is as follows:
The first line of the input file contains a single positive integer, n, representing the number of
minesweeper boards to construct.
The first line of each board contains a single positive integer, m, representing the number of
bombs for that board. The following m lines will contain two non-negative integers in between 0
and 7, inclusive, representing the row and column, respectively, of the location of a bomb. No
two of these m lines will be identical.
For each board, output to the screen, the following header line:
Board #k:
where k is the number of the board, starting with 1.
Follow this with the board printed out over 8 lines, with a space in between each entry.
Separate the output for each case with a blank line.
Hints
Store the board in an 8 x 8 integer array. Store the number 9 where bombs are supposed to be
located. When printing the board, use an if statement to screen for bombs. Both 8 and 9 should
be represented by symbolic constants in this program. Watch out for array out of bounds issues
by using if statements to screen for illegal locations. One neat idea to fill the board would be to
initialize all non-bomb squares to 0 and then add one to each square adjacent to each bomb
(except for other bombs!) The other alternative idea is to go to each non-bomb square and look at
each location adjacent to it.
Sample Input
2
3
0 0
2 1
7 7
10
0 0
0 1
0 2
0 3
0 4
0 5
0 6
0 7
7 0
7 1
Corresponding Sample Output
Board #1:
* 1 0 0 0 0 0 0
2 2 1 0 0 0 0 0
1 * 1 0 0 0 0 0
1 1 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
0 0 0 0 0 0 1 *
Board #2:
* * * * * * * *
2 3 3 3 3 3 3 2
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 0 0 0 0 0
2 2 1 0 0 0 0 0
* * 1 0 0 0 0 0