Android jigsaw puzzle game development full record 2

Source: Internet
Author: User

Today, we will mainly discuss the feasibility of solving the puzzle game. In fact, we should not underestimate the puzzle game. He is actually a well-known 15puzzle in AI algorithms, I already have a lot of explanations on the Internet, so I will be a porter.

About % 50 of the randomly generated 15puzzle is unsolvable. This article will discuss the comprehensibility of the randomly generated puzzle.

The following matrix is provided:

12 1 10 2

7 11 4 14

5x9 15

8 13 6 3

Arrange them horizontally, including 12, 1, 10, 2, 7, 11, 4, 14, 5, X, 9, 15, 8, 13, 6, and 3. And the sequence is

Definition: "Inverted variable value" T, Ti indicates the number of elements in sequence A that are smaller than Ai after the I bit

That is to say, the inverted variable values of the above sequence are: 11,0, respectively. Sum to get the total Tsum = 49.

There are several principles to determine whether the current problem is resolved:

Set: The problem width to W.

Set: the inverse variable of the problem is T.

1. For a problem where W is an odd number, any legal movement will not change its parity of "Inverted variable value.

Proof:> horizontal mobility does not change the problem T.

> Vertical movement, that is, the value of blank across the (W-1) Square, because the problem Width W is odd, then (W-1) must be an even number, again set the number of n in the number of W-1 is greater than the current number of moving, there is (W-1-n) number less than the current number of moving, then after moving, the T brought about by the change is: (W-1-n) -n = W-1-2n, because the W-1 is an even number, the W-1-2n must also be an even number, indicating that the problem T parity unchanged.

2. When W is an even number, the following formula is provided: (T is an even number) = (spaces are located in the odd rows that are numbered up from the bottom of the matrix)

Proof:> horizontal mobility does not change the problem T.

> Vertical movement, meaning the value of blank across the (W-1) Square, because the problem Width W is even, then (W-1) must be odd, again set the number of n in the number of W-1 is greater than the current number of moving, there is (W-1-n) number less than the current number of moving, then after moving, the T brought about by the change is: (W-1-n) -n = W-1-2n, because the W-1 is an odd number, the W-1-2n must also be an odd number, indicating that the parity of T will change alternately, but the space position is also changing, this change also complies with the formula defined above.

OK. With the above two theorems, we can infer the feasible solution principle:

1. If the problem width is odd, the T defined for each solvable problem must be even.

2. If the problem width is an even number, the problem T must be an even number when the space is in an odd row from bottom to top; when spaces are in an even number of rows from bottom to top, the problem T must be odd.


Finished ---------------------------------------------------------------------------

What we need is the two conclusions: Next we will start to generate a solvable puzzle game based on this algorithm.


Related Article

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.