Minesweeper

zhaozj2021-02-16  49

The mine profile thinking about the time of my big two, I wrote a mine procedure, and now there are many source downloads. I don't know how their algorithms are, but I think my algorithm should be the clearer and simple. Let's talk about my mine profile. First we randomly put the thunder on the mine, there is no thunder, it will show a number indicating that there are several thunders around it, how is this implementation? We can see the entire mine area as a two-dimensional array a [i, j], such as Ray: 11 12 13 14 15 16 17 18 21 22 23 24 25 25 26 27 28 31 32 33 34 35 36 37 38 41 42 43 44 45 46 47 48 51 52 53 54 55 56 57 58 I want to know a few thunders around A [34], only to detect A [23], A [24], A [25] A [33], A [35] A [43], A [44], A [45] Whether the eight thunder are placed on the thunder, carefully observe their mathematical relationship. Abstract is: A [i, j] of the number of thunders is by A [I-1, J-1], A [I-1, J], A [I-1, J 1] A [i , J-1], a [i, j 1] A [i 1, j-1], a [i 1, j], a [i 1, j 1] (if the boundary is exceeded Judgment) This ranks are determined.

The minesweeping process will automatically launch a mine-free zone that has no thunder. If A [3, 4] is 1 mine mine, A [2, 3] has been labeled as mine, then A [24], A [25], A [33], A [35], A [43] , A [44], A [45] will be deployed, and the unspeakable mine areas. This is also the key to implementation. We can set an element of the array as a class object, and the class sets such an event: When the departure, check whether the mine around the surrounding mine is equal, if equal, if it is equal, unfolding Lei area indicated. In this way, the new mine area is triggered and triggered, so that it is recursive, it has always spread to the non-expandable mine zone. I believe that after learning the above two points, write the mine-like class (if there is a label, whether to expand the mark, the surrounding mine, etc. Simple one thing.

Zg nozg@263.net

转载请注明原文地址:https://www.9cbs.com/read-27078.html

New Post(0)