Error message here!

Hide Error message here!


Error message here!


Hide Error message here!


Error message here!



The cracking idea of ​​the electronic puzzle thinking logic machine

Cocos2d-xx 2022-11-24 23:37:19 阅读数:8 评论数:0 点赞数:0 收藏数:0

Recently, the child went to a friend's house as a guest and fell in love with a toy. He searched the Internet for a long time but couldn't find it. Later, he asked a friend for a link and found out that it was an educational game toy that had just been on the market.

First picture

After booting, there are 500 levels, and the difficulty is getting more and more difficult. The third level played at a friend's house, the children couldn't solve it, and then our parents and children also participated together, and it took a few minutes to finish it.Finding this game is really not easy.

On the way home, I was thinking, can this game be solved by writing a piece of code.Just do it.After finishing work, buy this toy for the child, and then I can’t figure it out, run the code and show off

Then it was done, and the code ran for 3 hours and 49 minutes. No wonder, for the violent attempt method, there were probably more than 180 million attempts.

Then optimize the algorithm:

1. Pruning algorithm

2. Concurrent execution

The program execution has been reduced to 2 minutes, satisfied!

Go directly to the solution of level 500

499 level solutions

Talk about the brute force cracking method:

1. The chessboard has 8 * 8, which is a two-dimensional array, and the initial state is 0
2. Fill in the target trait, and set the corresponding position ️ to 1.
3. There are 12 shapes in total, except for the filled-in level shape blocks, there are 9 pieces left, 1 direction for squares, 2 directions for rectangles, and 4 directions for special shapes.
4. Each block starts traversing from the two-dimensional array, but there is no need to traverse 64 times (you know)
5. As long as they are all put down, or the two-dimensional array is all 1, it is the end condition.
6. Friends who choose the depth-first algorithm remember to use the stack as a data structure.
7. The types of violence mainly include the full arrangement of the order of the remaining 9 shape blocks, and there is a direction for each shape block, that is, the full combination.

Finally, as an old father, being able to be a little bit attached to the code is a kind of feeling!

Copyright statement
In this paper,the author:[Cocos2d-xx],Reprint please bring the original link, thank you