Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Python to play Mini Program Games with one Stroke

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

In this issue, the editor will bring you about how to play small program games with Python. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.

one. Running environment and libraries used

Speaking of the running environment, if the py script runs on windows, you need to install the adb toolkit, android phone (resolution is 1920x1080).

The following libraries are used in the program, PIL is used to process images, and os is used to execute some adb commands.

two. The whole train of thought.

one. Convert the grid in the picture into a two-dimensional map matrix, in which 2 represents the starting point, 1 represents the gray grid, and-1 represents the blank grid. At the same time, the position of the center point of each grid is placed in another location matrix, which is used to click on the corresponding position of the mobile phone.

two. Use depth-first search to search the two-dimensional matrix of the map to get the route. I haven't learned much about the algorithm, and the more the level goes back, the slower the search. Interested bosses have good ways to improve.

three. Using the ADB tool, click on the appropriate location to complete a stroke.

three. Analysis and realization

Let's see what the characteristics of the picture are. First, we use ps to look at the next picture (the mobile phone resolution is 1920x1080). The RGB value of the center point of each gray lattice is around (209209209), and the RGB value of the center point of the white lattice is around (249249249). The center point of every two squares is 159 pixels apart.

You can see that the grid of the picture begins at a certain distance from the top of the picture, and this distance of 365 pixels will be used when traversing later. We first traverse the image horizontally to find the first pixel with a RGB value near (209209209), move the pixel down 72 pixels, traverse the line from left to right, find the first pixel near the RGB value (209209209), and then move the pixel to the right 72 pixels to get the location information of the center point of the first gray grid. Taking this position as the starting point, traverse in the upper left, upper right, lower left and lower right directions with a step size of 159 pixels. Let's take a look at this part of the code.

Send the screenshot of the phone to the computer and find the center of the first gray grid.

Convert to map two-dimensional matrix

Find the starting point and calculate the number of gray squares

Then let's talk about the pathfinding function, using depth-first search, searching in the direction of upper, right, lower and left, and using a function to judge whether a certain position can go or not.

The following is part of the code for depth-first search. Click with the ADB tool after finding the path.

Finally, just let the program run in a loop, sometimes the program will die and will not tune. And the pathfinding function will be very slow in the back.

The above is the editor for you to share how to use Python to play a stroke to finish the mini program game, if you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report