Automatic Mine clearance-Determination Analysis

Source: Internet
Author: User

The previous blog post introduced how to obtain and output data from the "mine clearance" game. Now we will explain how to analyze the data:Program. SlavePrefaceWe can see that the analysis of "mine clearance" games can be divided into four models. Here we will introduce the analysis of the first three models.

Data is easier to control than programming logic. Here, we will first introduce the data structure defined by "automatic mine clearance.

The blog class represents a small square in a game scenario. The class diagram is as follows:

M_ishide indicates whether it is hidden; m_aroundminecount indicates the number displayed on the square when m_ishide is false (that is, when the square is displayed); m_minestate indicates that m_ishide is true, the program determines whether the block is thunder or non-Thunder (unkown at the beginning of mine clearance ).

UseTWodimesionarray<Block> m_blocks indicates a two-dimensional game scenario composed of blocks.

The data above can deal with the first and second models. In utility. H, two functions calmine () and calhide () are provided respectively to find the number of mines that have been identified around a block and the undisplayed blocks around a block. If the number of mines around is m_aroundminecount, other unjudged blocks are not mines. If the number not displayed around is equal to the number of mines, these are all mines.

The following describes the analysis of the third model:

Let's start with a brief review -- (for details, seePreface)

If the following conditions occur:

The following mathematical formula can be obtained:

A + B = 1 (1)

D + E = 1 (2)

A + B + C + D + E = 2 (3)

In the program, I have defined the probablemine class to represent this formula. The class diagram is as follows:

Points indicates that the coordinates of a ray block may appear, and minecount indicates the total number of mines in the block. The preceding three formulas are represented by three probablemine objects. Their minecount values are and 2, respectively. Points are coordinates of a, B; D, E; A, B, C, D, and E respectively.

Suranalyse is responsible for the third modelAlgorithm. The class diagram is as follows:

Probables indicates all possible conditions. m_notmines and m_mines are used to record the results in the analysis process.

During analysis, each probablemine object is compared in pairs. If one points is a subset of another, another probablemine object can be generated by their difference sets. If minecount = 0 in the new probablemine object, it can be judged that its points are not thunder; If minecount = points. size (), it can be determined that the points are thunder. If neither of the two conditions is met, add it to probables to participate in the next round of calculation. Until the data does not change.

So far, the analysis of the first three models has been completed. It can be seen that the algorithm is not complex. The most challenging thing is the analysis of the fourth model. The next article in this series will be carefully analyzed (however, when I recently studied the fourth case, I found such a mathematical problem, if you are interested, you can think about it,One permutation and combination question).

Now open the source code of the C ++ project:SVNOnly the first three models and the fourth modelCodeNot complete yet. (I once again stressed that in order to focus, I only study automatic mine clearance under the XP system. If it is Windows 7, you need to copy the clearance game under XP, which is provided below)

Clearance game in 32-bit XP system:Winmine_32cn

The EXE for automatic mine clearance is:Http://files.cnblogs.com/xiangism/mineTerminator.rar

 

The following is my game interface completed with automatic mine clearance.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.