Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Climate And Environmental Database Systems

Authors: Michael Lautenschlager ,Manfred Reinke

1st Edition

1461368332, 978-1461368335

More Books

Students also viewed these Databases questions

Question

Describe the appropriate use of supplementary parts of a letter.

Answered: 1 week ago