We continue to understand the
rules of the current Google AI Challenge tournament. Then you can read the translation of the official rules for calculating the results of ant battles.
The basic rule of the result of the battle
The outcome of the battle is determined from two different angles:
The ant dies if the enemy, which is at a distance of attack, is surrounded by a smaller (or the same) number of its own enemies.
or
Our ant kills the enemy if the enemy, which is at a distance of attack, is surrounded by a greater (or the same) number of enemies than its target.
')
If this is not clear yet, do not despair, further detailed explanations will follow.
Obvious facts about the world of ants
The ant is a very simple creature. In fact, he can do only two things on his own.
The first is to create a new ant from food, to which he got close enough. This action, of course, is quite difficult for the ant, requiring precise and hard work (which is why it is necessary to get close to the food). Although the result is quite simple - if the food is close enough, another ant of the same color appears. An exception is the case when several ants of different colors approach the food closely at the same time; food is destroyed when they try to collect it.
The second is to attack the enemy ants. This is much simpler than birth and can occur over a much greater distance (although the details are not known reliably, but you have to quickly sort through your paws). Results may be somewhat more difficult to understand than at birth.
In the simplest case, when two separate ants of different colors approach each other so much that they engage in combat, all their attention is focused on the enemy. Paying an equal amount of attention, opponents kill each other.
When a lone ant collides with two opponents at the same time, it has to divide the attention between the enemies. The enemies at the same time are fully focused on the ant. This means that a lonely ant will be at a loss and perish, and the other two will survive. You see, for the survival of the ant, the concentration of attention must be higher than that of the enemy. If the ant's attention is equal to or less than that of any of the opponents, the ant dies.
Ants do not distinguish enemies by color. If the ants of three different colors, say, green, red and blue at the same time, are within the distance of each other's attack, the attention of each ant will be divided between two enemies, and all three ants will die. But if a green ant has red on one side and blue on the other, red and blue being too far away to attack each other, then only green will die. After all, his attention will be dispersed between two opponents, while each of the enemies of the week will be concentrated only on green.
Hopefully, this description has helped you understand the principle of calculating the outcome of the battle. To consolidate understanding, we consider a more complex example of combat.
Two blue ant Sid and Sam, and two red ant Kent and Kite explored the world. And now, after the next move, Sam went to the distance of the attack of both red ants, while Sid can attack only Kent. Now a question for you. Who will die and who will survive?
Do not answer until you answer the question.
-> .. ... -> . <- ... .. <-
Have you received the answer yet? Do not continue until you get.
In this situation, the attention of the blue ant Sam and the red ant Kent is divided between two enemies. Sid and Kite are each focused on their only enemy, whose attention is divided. Therefore, Sam and Kent will die in this battle, and Sid and Kite will survive in order to fight in the future.
Pretty simple, right? Of course. Each battle proceeds in the same way. If an ant's attention is divided between fewer opponents than the attention of each of its opponents, it survives. You are now ready to go into this document to find a description of some technical details and additional examples.
Some technical details
Each ant in the attack distance may have several opponents. It is believed that he is "busy" with the battle with these ants. Each ant can have its own number of enemies who “occupy” its attention. Ants who are busy with fewer enemies are more focused on killing these enemies than ants who fight more enemies. Equally busy ants can kill each other.
......C CABC ......C
- ant A at distance of attack from ant B
- Ant A is busy (or fighting with) 2nd opponents
- Ant B is busy (or fighting with) 4th opponents
- Ant B has to be tracked and distracted by a larger number of opponents, so it is less effective at fighting than Ant A
- so the ant A can kill the ant B
- if we consider ants C, then the situation will change, but so far we have considered only A and B
- ants C will kill both A and B, even if A and B were not so close to each other
Each ant can kill more than one ant, and each ant can be killed by several ants. The same ant can kill an ant and be killed by another ant in one turn.
To try to count the battle manually, it’s enough to count the number of enemies surrounding each ant:
......1 1 2 4 1 ......1
Then, if there is an enemy with a smaller or equal number near the ant, the ant will die.
......C CxxC ......C
Options
In all cases, the square of the attack radius is 5, and the attack distance is shaped as in the figure (with the calculated squares of the radii)
....... ...9... ..xxx.. .85458. .xxxxx. .52125. .xxAxx. 9410149 .xxxxx. .52125. ..xxx.. .85458. ....... ...9...
One on one
Both die
..... ..... ..... .AB -> .1.1. -> .xx ..... ..... .....
two versus one
A dies
...B. ...1. ...B. .A... -> .2... -> .x... ...B. ...1. ...B.
3 fighters met
All died
...B. ...2. ...x. .A... -> .2... -> .x... ...C. ...2. ...x.
Ant sandwich
The ant in the middle perishes. A and C survive.
..... ..... ..... ABC -> 1.2.1 -> AxC ..... ..... .....
Couple against two singles
B and C die
...B. ...3. ...x. .AA -> .2.2. -> .AA ...C. ...3. ...x.
Wall punching
Many fell
AAAAAAAAA 013565310 AAxxxxxAA ...BBB... -> ...555... -> ...xxx... ...BBB... ...333... ...xBx...
Ant B survives because it is attacked by only 3 central ants A, each of which is occupied much more. In turn, it affects the death of these three central ants A.
???AAA??? ???565??? AAxxxxxAA ...???... -> ...???... -> ...xxx... ...?B?... ...?3?... ...xBx...
Ants A from the edge survive because they are attacked by a single B ant who is busy much more.
?A??????? ?1??????? AAxxxxxAA ...B??... -> ...5??... -> ...xxx... ...???... ...???... ...xBx...
Sid and Sam vs. Kent and Kite:
The upper and lower ants do not reach each other.
One death per side
...... ..1.... ...... ..... -> ..2.2.. -> ..xx. ...... ....1.. ......
Maths
For the position of the ant x, we define the function enemies (x) equal to the number of enemies located at a distance of attack from x.
For ant position a, a survives if

Similarly, for the position of the ant a, a dies if

Pseudocode:
// : : ( ) >= ( )
Python