📜 ⬆️ ⬇️

Another way to automate / test the game

Do you have a friend who constantly plays any game in contact? I do not know about you, but it makes me nervous when an adult spends 12 hours on a not very smart game. Looking at one such friend, I wanted to write a robot that would play instead.

Not so long ago on Habré there was a whole wave of articles devoted to bots for browser games: [1] , [2] , [3] , etc.
It would seem that all the ways have already been sorted out, but recently I came across another very interesting and less laborious way.

Who wants to see how to write a bot to play 30 lines of code - please under the cat.

')
Instruments

The tool that we will use is called Sikuli .
This tool allows you to automate actions such as clicks, drag and drop, etc. using screenshots. Those. unlike AutoIt, you do not need to reinvent the object search algorithm. Sikuli will take care of this. And we have to do the invention of the algorithm.

Algorithm

My choice fell on the game "Zombie Farm". The meaning is simple: dig, plant, harvest. That's just to do it a lot and constantly. I did not complicate the algorithm too much and this is what happened:

:
1) 15
2) 15
3) 15


The most difficult (although what the hell is the difficulty!) Was to buy seeds for planting. In the seed selection window there is a lot of everything and everything is very similar.


You can of course find the coordinates of the "buy" button by the offset from the image of what you want to plant. But there is an easier way.
By default, if you call the click function and pass it a picture as a parameter, it will click on its center. But you can set any image offset. Therefore, we simply take a picture of our plant along with the “buy” button and put the logical center on the button.


Code

And about 30 lines of code, I did not lie (if you subtract empty lines). Here they are:

The language is difficult to highlight due to the presence of pictures in the code, so the whole code is represented by a picture.
Sources

How it works



PS

Sikuli project website - sikuli.org

Source: https://habr.com/ru/post/129979/


All Articles