Another way to automate / test the game

    Do you have a friend who constantly plays a game in contact? I don’t know about you, but it makes me nervous when an adult spends 12 hours on a not-so-smart game. So looking at one such friend I wanted to write a robot that would play instead of him.

    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 methods have already been sorted out, but recently I came across another very interesting and less time-consuming method.

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


    Instruments

    The tool 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 don’t need to invent an object search algorithm. Sikuli will take care of this. And it remains for us to take up the invention of the algorithm.

    Algorithm

    My choice fell on the game "Zombie Farm." The meaning is simple: dig up, plant, harvest. That's just to do it a lot and constantly. I didn’t complicate the algorithm much, and this is what happened in the end: The most difficult thing (although what the hell is the difficulty!) Was to buy seeds for planting. In the seed selection window - a bunch 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 we want to plant. But there is a simpler way. By default, if you call the click function and pass a picture to it as a parameter, you will click on its center. But you can set the offset for any picture. Therefore, just take a picture of our plant along with the buy button and put the logical center on the button.

    Делать вечно:
    1) вскопать 15 грядок
    2) засадить 15 грядок
    3) собрать 15 плодов









    The code

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

    The language does not lend itself well to highlighting due to the presence of pictures in the code, so all code is represented by a picture.
    Source code

    How it works



    PS

    Sikuli project site - sikuli.org

    Also popular now: