Question: 1 . Computer generates a 2 D mine _ field array on a 4 x 5 area ( 4 rows and 5 columns ) .

1. Computer generates a 2D mine_field array on a 4x5 area (4 rows and 5 columns).
2. Computer generates 5 random mine locations and write them on the mine_field array. The array is
initialized to 0, and, then, all random mine locations are set to 1.
3. Another 2D 4x5 play_field array is initialized to X.
4. mine_found flag is set to False. This flag is set to true, if we land on a mine and lose the game.
5. cleared counter is set to 0. When this counter reaches to 15, we will win the game.
6. We check the cleared counter if it reaches to rows*columns-mines=4*5-5=15. If it is 15, then, we go to
step 12.
7. We check the mine_found flag if it is True. If it is True, we go to step 12.
8. Otherwise, the player is asked to select a valid coordinate on the mine_field 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.
9. If the selected coordinate contains a mine, then we print a 1 on the selected coordinate of the
play_field array, and set the mine_found flag to True. We go to step 7.
10. Else if the selected coordinate does not contain any mine, then the cleared counter is incremented
by 1. 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 play_field array.
11. We print the play_field array, and go back to Step 6.
12. If the mines_found flag is true, a YOU LOST message is printed. Otherwise, a YOU WON message
is printed.
13. We print both the play_field and mine_field arrays.
14. Then the application terminates.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!