Answered step by step
Verified Expert Solution
Question
1 Approved Answer
1 . Computer generates a 2 D mine _ field array on a 4 x 5 area ( 4 rows and 5 columns ) .
Computer generates a D minefield array on a x area rows and columns
Computer generates random mine locations and write them on the minefield array. The array is
initialized to and, then, all random mine locations are set to
Another D x playfield array is initialized to X
minefound flag is set to False. This flag is set to true, if we land on a mine and lose the game.
cleared counter is set to When this counter reaches to we will win the game.
We check the cleared counter if it reaches to rowscolumnsmines If it is then, we go to
step
We check the minefound flag if it is True. If it is True, we go to step
Otherwise, the player is asked to select a valid coordinate on the minefield array. If the input is not a
valid coordinate, this step continues until the user enters either Q to Quit at anytime or a valid
coordinate.
If the selected coordinate contains a mine, then we print a on the selected coordinate of the
playfield array, and set the minefound flag to True. We go to step
Else if the selected coordinate does not contain any mine, then the cleared counter is incremented
by We then, check eight neighbors of the selected coordinate to count the number of mines on the
neighbor cells. Finally, we print the total number of mines on the neighbor cells on the selected
coordinate on the playfield array.
We print the playfield array, and go back to Step
If the minesfound flag is true, a YOU LOST message is printed. Otherwise, a YOU WON message
is printed.
We print both the playfield and minefield arrays.
Then the application terminates.
Step 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