The Core algorithms of connected video games

Source: Internet
Author: User

I recently wanted to create a continuous watching game, but I never started it because I felt that my idea was not mature enough. I made a small game. I usually started it only when my idea was quite mature, haha. I think this is the right thing. We should first consider it carefully before doing it. Now we advocate writing documents for major projects and detailed design ideas (the more detailed the better, otherwise it will be in a mess, and it will be the same for you to make small games again and again. Okay.

There are two basic problems to be solved when you are playing a connected video game:

The first is to provide you with an initial layout for serialization and use the program to automatically solve it.

The second is how to survive and view the initial layout of the game and ensure that the layout is well understood.

The first problem is relatively simple. You can use breadth-first search or deep-first search to easily solve the problem. The second problem is more complicated. It is somewhat difficult. I thought that there is no good solution. I went to baidu and google looked for it. I first saw someone on csdn saying that I could do this:

Method 1:

1. randomly generate a continuous layout. This layout may be unsolvable (the total number of chess pieces in the layout must be an even number, and the various chess pieces must appear in pairs; otherwise, they must not be resolved)

2. The layout of the automatic solution.

3. If the layout appears, it will go to 4. If it does not appear, it will be done.

4. Change the positions of any two pawns in the dead board and then go to 2.

Although this algorithm can generate a solution layout, it is not efficient and complicated.

First, every time a dead board is found, an array is used to record the dead board, so as to avoid repeated searches (turning back) and exchange the positions of any two pawns in the dead board, check whether the residual State after the switch is repeated with the dead state in the array. If it is repeated, you must continue to change the dead state until it is not repeated with the records in the array.

Second, the process from 2 to 3 is quite troublesome. The function that needs to be automatically solved consumes a lot of resources and cannot be switched to 4 in case of a final problem when the problem is solved, it is very likely that there will be no solution in the process of solving the problem ., The process from 2 to 3 also involves backtracking. When we use an automatic solution function to solve the layout, we finally find that the layout is dead and there is no solution, then we will get several dead scenes that we encounter in the automatic solution process. We also need to select the dead scenes with the least number of chess pieces, and then we can go to step 1.

Therefore, this algorithm is too troublesome. Today we have found a better way to generate a layout on the Internet.

This algorithm is as follows:

Method 2:

1. First determine the size of the link to be generated, such as 12x8, 16x24...

2. Randomly place a piece in the central area of the layout. The first pair of chess pieces can be eliminated no matter how they are put. Therefore, do not care about anything and go to 3.

3. Continue placing the next pair of pawns

4. Is there any space available to play the pawns? If not, go to step 2. If yes, go to step 1.

5. Check whether the new pair of chess pieces can be eliminated according to the serialization rules. If yes, go to 3. If NO, go to step 2.

6. Undo the placement of the pawns and record the placement of the new pawns with arrays, so as not to repeat the placement next time and go to 3.

7. Use the automatic solving function to verify whether the newly generated layout has been resolved. If there is a solution, the result is success. If there is no solution, the jump is to step 2.

8. start backtracking from the last piece, and change the layout of the piece through backtracking, and then go to step 2.

Why is verification required? The last two pairs of chess pieces can make the entire game unsolvable, but the number of backtracking times should be small. I guess the average is two or three times. The disadvantage of this method is that the sample space of the randomly generated layout is smaller than that of method 1 and method 3,

In fact, step 1 can be changed to an automatic solution function to solve the current problem. If there is no backtracing function, the next pair is placed. However, as a result, the sample space is large and the efficiency is low.

Method 3:

1. randomly generate a continuous view layout, which may be unsolvable.

2. The layout of the automatic solution.

3. If there is any solution, the success will be achieved. If there is no solution, go to step 2.

After practice:

Finally, when I made the connected video game, I found that automatic resolution is not a necessary function for a connected video game. If the function is not automatically solved, the user can still play very high, the automatic solution should be the most difficult module in the development process of the connected video game, which is more difficult to generate than the layout of the connected video.

The generation of the continuous view layout is not as complicated as I think. When I use method 3 to generate a solution layout, I find that if the algorithm is disrupted, the layout generated is not messy enough, after using the automatically solved function I wrote, I found that almost 100% of them had solutions, but many of them were directly adjacent to each other. At a glance, I found that many of them could be eliminated immediately, in this way, the game is difficult, and cainiao can easily pass the game. After I complicate the algorithm, it will be difficult to generate the layout. cainiao basically cannot pass the customs without prompting, or it will take a long time to pass the customs, at this time, there is also a 40% chance to generate a solution layout at a time, and the generation of a solution layout has not yet been one failure for four times.

In addition, it doesn't matter whether the initial layout of the continuous view is unsolvable. However, you must ensure that at least one pair of pawns can be eliminated, and that each pair of pawns can be eliminated during the game. If a user encounters a dead scene during the game (no piece can be eliminated), the layout will be changed so that at least one piece can be eliminated. In this case, the initial layout will be completely eliminated.

Thoughts:

1. When determining whether a pair of chess pieces can be eliminated, we recommend that you use breadth-first search. When you automatically solve the problem, we recommend that you use depth-first search.

2. breadth-first search and deep-first search are very common algorithms in chess games.

3. If you do not want to do it, you cannot do it. If you do not want to do it, you have to make a detour.

4. Make a front-end program. If you want to write something to play with it, you can make it.

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.