Current location - Quotes Website - Personality signature - Introduction to the hardware implementation of Python playing "Jump" iOS+Win?
Introduction to the hardware implementation of Python playing "Jump" iOS+Win?
Original project address: Wang hub/ wechat _ jump _ game.

Teach you to play wechat with Python.

Source code of this project: yangyiLTS/ wechat _jump_game_iOS.

At present, the existing iOS hop-by-hop assistance needs WebDriverAgentRunner in macOS environment. The method introduced now is physically implemented in Windows environment, and neither macOS nor jailbreak is needed.

First effect

Operating environment &; tool

Python 3.6 in Windows

Python pillow library

Lan environment

iToools Airplayer

Raspberry pie or arduino (Raspberry pie is used in this article)

SG90 steering gear

Dupont wire, cardboard

A small sponge

Oranges or other juicy fruits (optional)

The basic idea is to use the Airplay service that comes with iOS to project the game screen onto the computer. Use the pillow library to grab the computer screen and get the game screen. Analyze the picture, calculate the jumping distance, and multiply it by the time coefficient to get the pressing time. The pressing time is sent to the raspberry pie, and the raspberry pie controls the steering gear to click on the screen of the mobile phone. Principle &; step

Steering gear and controller part

Rasp bian Jessie (OS: Raspbian Jessie) connects to the local area network, and servo_control.py is downloaded to Raspbian Jessie. Stick a DuPont wire on the swing arm of the steering gear and fix the steering gear on the cardboard, as shown in the figure:

Take a small sponge, about 10mm* 10mm*5mm, without being too precise. Dig a small hole in the middle of the sponge. Something like this:

Soak the sponge in water and put it in the position of "one more time" on the phone screen. At the other end of the Dubang line, there are oranges. To trigger the capacitive screen, an electric field needs to be formed on the screen. I tried to connect the negative electrode of dry battery, and the effect was not ideal. Finally, I had to take an orange from my roommate. Of course, you can always hold or hold the wire. )

The steering gear is connected with raspberry pie, and the power supply is 5v (pin 04 and pin 06). The steering gear control line is connected with GPIO18 (pin12).

It is necessary to adjust the height position of the steering gear according to the actual installation position (range: 2.5~ 12.5).

Servo Down = 3.8 Servo Up = 5

Final effect

Window part

Download Airplayer (no installation, no binding)

Configure Airplayer and adjust the picture quality to the highest level. Start Airplay on the iPhone, and then you can see the iPhone screen on your computer. When the game is running, Airplayer needs to be displayed in full screen.

Install the pillow library, this paper uses the ImageGrab screenshot of the pillow library, and the screenshot code is:

im = ImageGrab.grab((654,0, 1264, 1080)) im.save('a.png ',' png ')

Download WeChat _ jump _ auto _ IOs _ win.py My monitor resolution is 1920* 1080, and my mobile phone is iPhone7. If different equipment is used, parameters such as time coefficient need to be changed.

Because Airplay will compress the picture during transmission, the game picture will have color difference. I modified some parameters of the original algorithm to increase the color tolerance, and achieved good accuracy in the test.

Wechat _jump_auto_iOS_Win.py will call the socket library to send the jump time to the raspberry pie after calculating the jump distance, and the ip address needs to be changed to the ip address of the actual raspberry pie.

ip_addr = 'rasp_ip '

Run to open the game screen and run servo_control.py on the full-screen raspberry pie in the Airplayer window? , listen to port 9999 and wait for the calculation result of Win. Windows runs WeChat _jump_auto_iOS_Win.py sponge, which can automatically restart in the "Retry" position, and will automatically brush the questions after that &; other

Because it is a physical click on the screen, there will be some operational errors. The operation error is caused by time constant error, steering gear action time and the depth of Du Bang line contact inserted into sponge. However, the current algorithm will have the problem of error superposition in one case.

Z-shaped path error accumulation process

The swing angle and time coefficient of the steering gear have no absolute value, so it needs to be tried slowly. The time coefficient currently used is 2.43.

The combination of Arduino+pyfirmata can be used to control the steering gear, which is relatively low in cost and does not require network transmission of calculation results. Because my arduino gave a female ticket a few days ago, I haven't used arduino's scheme yet.

After jumping 200+ times, the box of this game will become very small (such as the title map), which is beyond the reach of ordinary humans. I didn't know how difficult it was to get high marks by hand until I studied plug-ins. Let's stop marking, we won't have any friends.