Gladiabots

Gladiabots

Not enough ratings
Fleeing Guide
By Markolainen
The aim of this guide is to provide a simple and beginner friendly way of controlling the fleeing of your bots and create a base which can easily be expanded and modified.
   
Award
Favorite
Favorited
Unfavorite
Intro
The aim of this guide is to provide a simple and beginner friendly way of controlling the fleeing of your bots and create a base which can easily be expanded and modified.

If you find any errors or have any questions contact me on the Gladiabots discord.

First we will look at some typical fleeing modules most players encounter when they start playing and show how they'd look in the system we will create. Then an example motivating the math I used when choosing the values of my AI followed by creating the fleeing module of one of my older AI:s. Lastly I give some ideas on things that could be expanded to make this module more consistent.
Common beginner modules
The first fleeing modules most players encounter looks similar to the ones below.
They provide a clear view of conditions and consequences and are great when debugging. For me they became hard to tinker with, and I could not "get a feeling" for them.
The counter system
The method I'm using assigns a value for things that either does or will do damage to me. When a certain amount of damage is calculated to occur we will start retreating.
Recreating the beginner modules
We will recreate the modules seen above to show how this system works, beginning with the left module.

We use team counter E for storing values. As long as it is not used for anything that goes over several tics or that you assign a value before this module and use it later you can use it freely anywhere else.
This code has 3 columns. The first set team counter E to the number of bots attacking me, it is important that the node setting the value executes first. The second column checks if our shield is below 50%, if so increases E by 3. The third column checks if team counter E is greater than or equal to 3, in which case we flee from all enemies attacking us.
If we are attacked by 3 or more bots or have less than 50% shield results in a retreat from all enemies attacking us.
The right example is the same as the picture above. Here the possibilities of this system starts to show, with incrementing the counter by one if a certain condition is met as seen in the second column.
Stats and maths
Before continuing we will need some bot statistics so we can try to do some approximations and choose our values. All stats are taken from the bot classes[wiki.gladiabots.com] section of the Gladiabots wiki[wiki.gladiabots.com].
Test scenario
Assume your assault walks up to an enemy bot and it starts firing once you enter mid range. If you immediately retreat when entering mid range enemy assault will have the time to fire 5 volleys towards your bot, each with 3x2 shots. This is 30 bullets which each deal 300 damage and have a 15% chance to hit. This leads to 30 * 300 * 0.15 = 1350 average damage. An assault has 3000 in shield so this is not too far from half of your shield.
Creating the module
EDIT: The "set team counter E to number of enemies not out of range" should be "set team counter E to number of enemies attacking me".

Mostly the assault bots you meet won't be at medium range, assuming the average distance to an enemy assault bot is about halfway into long range it gets to fire 2.5 volleys, which is 675 damage on average, which I rounded to ⅕ of full shield. So if 5 enemies are firing at me I flee even if at full shield.
Now taking shield into account we saw that we can do a somewhat smooth transition if we add the shield nodes separately.
Looking at an example let's say we have 33% shield, this makes the 3 topmost shield nodes trigger, E has the value 3 if no enemies are attacking us. If now 2 enemies attack us halfway into long range, assuming they would fire 2.5 volleys each we would on average get hit with 1350 damage, that is 350 health damage when the shield is gone.

Both here and when rounding 675 damage to ⅕ of my shield I have been optimistic in the damage I'll take. This has worked for me but might differ depending on team composition and the rest of the AI.

There are however opponents which caused my bots to lose health almost every time they would flee. And since this is (hopefully) not the case with all opponents we don't want to change our fleeing threshold for all opponents, as it would lead us to flee when we would not need to.

A solution to this is to start fleeing earlier once we take some damage. This will help us not get accidentally killed by bad luck, but for me it is mainly a solution to adjust myself to my opponents playstyle.
While this makes your bots survive it can have a clear effect on their ability to push enemies, it happens that fights start good for me and I push back the enemies, but once my bots start taking damage they become less aggressive and the opponent starts pushing me instead.

Since bots do more damage at mid or close range I added the next node to be a little more prepared for any damage coming in from mid or close range.
This was done by increasing the counter for every enemy bot attacking me in close or medium range. Far from a perfect solution and I'll adress it in the future improvements section, but it is helpful in those cases where more than one bot attacks you in mid range.

The last thing we will cover is the enemy sniper. It can deal a lot of damage, and without the right tools this damage comes out of nowhere. There are better ways to handle snipers than I present here, but this system has worked well for me.
It increments the counter by 2 for every sniper attacking us. So every sniper attacking us is worth 3 points in total. This is due to the sniper taking away ⅔ of your shield at once, which is close enough to ⅗. So if you have less than 75% shield you'll always flee from a sniper attacking you.
One in my opinion important thing to have in mind is that without any other modules than this it is very important to make sure you flee if 2 snipers are attacking you. If both hits land you'll lose ⅕ of your max health from the snipers alone.
Future improvements
This system has a weakness to teams with many assaults, this is due to assaults having the option to quickly change targets. This mechanic has no way of knowing how many enemies are around, which might cause some problems.
A simple solution that has proven effective for me is to increment E by 1 if there are 3 or more enemy assaults in range.

This system sees the 3 non-sniper bot classes as equivalent when doing damage, which I think is a good approximation, with the exception of the MG in mid range. If an enemy MG attacks me in mid range then I step out of mid range at once.
To do this I just increase the counter E by 5 if attacked in mid by an enemy MG. So my bot backs to long range.
This system has some flaws which might cause your bots to back off and re-enter mid range of the MG. A semi-fix is to always start attacking if an enemy MG fires at you. There is no reason to continue pushing forward then.

Another thing is that if you enter mid range of an enemy and you'll have to flee you know that there is a possibility it might fire 5 volleys if it is an assault, or doing about the same amount of damage if it is an MG.
A solution is to tag all enemies attacking you in mid and keep them tagged as long as they attack you. Then incrementing E for every enemy bot tagged and attacking you.

A sniper clock would also help to improve both your bots from taking damage and giving them more time to shoot enemies since you don't flee prematurely. If you use a sniper clock you should no longer take into account for enemy snipers when setting E to the number of enemy bots attacking you.