When I was thinking of implementing a 6-ball puzzle on python, the shit code was completed. I'm tired of it, so let's release it to the sea on the net and finish ...
Method of operation a: Right 60deg rotation b: Left 60deg rotation j: Move left l: Move right k: Start falling
Reference video https://www.youtube.com/watch?v=Q6As1gRT6fE&t=660s
I feel like I'm doing a motion simulation, but it's a little difficult, so I don't think I can make the exact same thing.
Define four directions a, b, c, d for the ball.
conditions
This situation is a little difficult.
Search direction Check if you can move from the lower layer, and move until you can not move
It's a little tricky because the column locations are off by 0.5 at the row locations. Number as follows so as not to bother you
Red, blue, yellow, purple, green, sky 6 kinds of Let the sky be 0
19 columns, 12 rows
(This result is a little different because it is not drawn with opencv in the program below, but the drop processing is the same. There are only two next displays, but it was a simple mistake)
Another pattern 1
Another pattern 2
I am satisfied with the results that I feel quite good.
Pattern 1 which may be a little problem
This is fixed and does not move. I'm worried about whether to drop the blue on the left end. At present, this is because the wall is recognized as having spheres on the left, right, lower right, and lower left.
This is a random pattern chosen
The program has been uploaded to github.
When the ball set (3 pieces) is moved with a keyboard etc. and dropped I want to calculate where the ball set will fall. Move the ball set with the amount of left and right movement entered with the keyboard, and when the ball set drop button is entered, drop it linearly, and when any of the three balls collides with an existing ball and becomes unable to move linearly. The ball set collapses, and from there I'm going to use the drop method I mentioned earlier.
There are many places to look up, so let's do our best
Not bad, but bad starting point With this kind of feeling, it becomes necessary to shift by 0.5. The direction of shifting was to the left if it was to the right, and to the right if it was to the left.
It is properly shifted and dropped.
It's a little unnatural, and the light blue next to yellow should fall to the lower right, if possible, instead of under yellow. .. .. However, at random
In some cases This is because in the current processing, if you can go to either the lower right or the lower left, it is randomly selected.
Postscript:
Conditions
- The ball only moves to $ b, c $
- There is no ball in $ a, b $ to move to $ b $
- There is no ball in $ c, d $ to move to $ c $
- If you can move to either $ b or c $, it doesn't matter if it is in $ a or d $, the direction of movement is $ b, c $ random
Rewrite condition 4 4. If you can move to either $ b or c $, $ c $ if there is a sphere in $ a $, $ b $ if there is a sphere in $ d $, $ b, c $ if neither is random
Change to. It's no longer random, it's natural ...
Finally, think about the detection method I could only think of a primitive method
Like this, scan the start point and try to detect it Do the same for the pyramids.
Detection method to do this
The code has become so long that I can't put it here for a moment. I will put it on a guy called github for the first time. ball6_puzzle_exe.py is the game execution program.
Method of operation a: Right 60deg rotation b: Left 60deg rotation j: Move left l: Move right k: Start falling
q: End of game
Recommended Posts