In defly.io, the you take control of a drone to fly around and capture territory by surrounding it with nodes and walls. Pressing space will drop a node that automatically connects a wall to the previous node. Once you complete a loop, the interior is filled in with your color and you gain some points proportional to the size of the area captured. As you gain points your drone will level up and allow you to choose from 7 different upgrades. When you encounter enemy drones you can break their territory by shooting at their nodes or by using special abilities that are unlocked at level 18.
You can buy cool ships by earning coins when playing the game. The most expensive ships cost 25000 coins which takes a long time to get. Instead of doing it manually I would rather make a program to play the game for me.
99% of the "players" one encounters in defly.io are bots included to make the game seem active to people that try it out. These bots are quite bad and struggle to accomplish much more than not flying into enemy walls. My bot will use simple decision making to conquer the map and make bank.
Replace UI areas with the background color.
This includes the scoreboard, minimap, upgrade menu, the player's drone, and the area where some status messages show up in red.
Scale down the image by a factor of 8, keeping 1 of every 64 pixels. This reduces the image size from
1920x937
to240x118
Notice that the purple bullet still shows up as a few pixels. This is important for the bot to be able to avoid enemy bullets.
Convert to HSV and detect ownership of each pixel:
→ saturation < 20 is background
→ 6 < hue < 20 is friendly territory or walls (orange)
→ anything else is enemy territory or walls (these pixels aren't orange but they are colorful enough to not be background)
Processing the minimap is fairly simple.
Remarks:
Discovering which upgrades the player has unlocked is a trivial task.
It is sufficient to query a pixel near the top of each cell in the table and check if it is orange.
Below is an example with 1 level in "Player speed" and nothing else.
Move in 8 different directions using combinations of W A S D
Move the mouse cursor and click to shoot.
Press E to use special ability.
Press 1-7 to choose upgrades.
The bot is governed by 2 very simple rules.
These two rules alone result in decent performance as the bot is good at surviving but not very efficient at capturing territory.
A few tricks help the bot by making it more greedy when it is safe
The bot always moves the mouse cursor onto the nearest enemy pixel and periodically clicks and presses E to throw grenade.
Even though this strategy is not focused and results in lots of misses, it will slowly chip away at enemy territory.