Skip to content
Daniel Bruegmann edited this page Mar 4, 2014 · 8 revisions

How to win

Your goal is it to build a flourishing ant colony that gathers sugar and defeats all opponents. In order to win you must own a very high fraction of the total ant population. This can be achieved by gathering sugar, producing ants and killing other ants. The victory condition is not checked before a certain number of ticks found in DONT_CHECK_VICTORY_CONDITION_BEFORE has passed. Similarly, you can access FRACTION_OF_ALL_ANTS_NEEDED_FOR_VICTORY. These values are stored in the file parameters.txt. Your AI can access them via its field parameters, e.g. parameters.DONT_CHECK_VICTORY_CONDITION_BEFORE.

A tick of the game

The game is played in ticks. Every tick, every ant's tick and every hill's tick method gets called. There is no defined order in which this happens, and it does not matter, since the actions are not executed right away. It is not allowed to use static variables to communicate between ants.

Perception

Ants can perceive their environment and act accordingly. They see nearby ants and hills of all players and sugar sources. They can also hear and send messages to communicate with ants of their colony but they cannot hear messages sent by the enemy. These perceptions are found in fields like visibleAnts of type List<Ant>. A full list of available fields and methods can be found in the doc directory.

Action

There are several ways to interact with the environment. The possibilities are

  • moving,
  • attacking,
  • talking,
  • picking up sugar and
  • dropping sugar.

They can all be called during a single tick and in any order. Their execution has a fixed order which is described below. To attack or pick up sugar, you need to specify a target. If an invalid target is given, this particular action will not be executed.

Attack

An attack is successful if the distance between attacker and target is less than the ATTACK_RANGE (parameters.txt). The target takes damage equal to the attack value (see Caste.java) of the attacker. If the target is carrying sugar this is multiplied by VULNERABILITY_WHILE_CARRYING (parameters.txt).

Bystanders also take collateral damage depending on their distance to the target (not the attacker!). This affects only hostile ants (no 'friendly fire'). Ants with zero distance to the original attack target receive full damage. This reduces linearly in distance, becoming zero at distance ATTACK_RANGE (parameters.txt).

Damage is subtracted from health and causes an ant to die at the end of the tick if its health reaches or falls below zero. The dead ant turns into a corpse and is visible to other ants and hills until it disappears after a certain number of ticks, namely CORPSE_DECAY_TIME (parameters.txt).

Snapshots

The objects of class Ant, Hill or Sugar you have access to are all Snapshot instances. This means that they represent the state of these objects at a fixed time. You can save or communicate them but they will always stay as they are and not update (for example Ant.position will not change even if the real ant moves). But given two Ants, Hills or Sugar objects you can check whether they are snapshots of the same real object with hasSameOriginal. If you try to attack an old snapshot you will automatically attack the real object if possible. On the contrary, move will always bring you to the position of the snapshot, which can differ from the position of the real object if the snapshot is outdated.

The order in which things happen

Actions are executed for all ants of all players simultaneously one type of action after the other.

  1. Attacks
  2. Ants pick up sugar
  3. Movements
  4. Hills create the new ants they ordered, if they have enough food. If it does not, the orders are lost, they are not kept for the next tick.
  5. At the end of each tick, ants die, corpses disappear if they decayed completely and empty sugar sources are removed from the game and new ones are added. Every message from ants and hills is saved to be heard during the following tick.

Objects

Castes

Every ant belongs to a caste which does not change during its entire lifetime. There are three castes for ants and a special one for the hill.

Caste Description
Gatherer Rather weak but can carry more.
Soldier More health and a slightly higher attack than gatherer.
Scout Faster and higher hearing & sight ranges, but it cannot attack
Hill Cannot be used for new ants, but this caste is used to look up hearing & sight range of hill

Every ant and hill has a field caste which can be used to look up properties. One can also find them in gameobjects.Caste.

Sugar

Sugar is needed to create new ants. Ants can pick up sugar if they are standing next to a sugar source. Their distance to the source must not be larger than the radius of the source for the action to be successful. After picking up sugar, it will be automatically transferred to the hill by being inside the hill.

While ants carry sugar they move with a smaller speed (see SPEED_WHILE_CARRYING_SUGAR in Caste.java). They are also more vulnerable meaning that any damage they receive gets multiplied by VULNERABILITY_WHILE_CARRYING in settings.txt. To avoid these effects, it is possible to drop sugar.

The sugar sources distribute sugar randomly to one of the requesting ants. This ant then gets as much sugar as it can carry, depending on its caste. After distribution, the source undergoes a cooldown phase in which no sugar will be distributed. This can be accessed with Sugar.ticksUntilNextPickUp, also see TICKS_BETWEEN_PICK_UPS_AT_SOURCE in parameters.txt.

Messages

Ants and hills can communicate with each other using messages. Messages contain several information, the sender (either a hill or an ant) with its position, an int (optional) and a snapshot (optional). A snapshot is a super class for hills, ants and sugar.

Messages can be heard by any ant of the same team which is close enough. The receiver's hearing range (Caste.java) is the critical factor for that. Messages can be heard for one tick only and the sender does not hear his own message in the next tick.

Hill

Each player has one hill where he collects food and produces ants. The hill can neither be attacked nor move. It can communicate like any other ant, with the difference that ants perceive hill messages in the field audibleHillMessage and ant messages in audibleAntMessages. The hills hearing and sight range can be found in Caste.java.

Additionally to communicating the hill has the unique ability to produce ants. A certain amount of food, ANT_COST (parameters.txt) is needed for every ant. Several ants can be produced in one tick. For every new ant, a caste and AntAI class has to specified which cannot change in the ant's lifetime.

The game world

The game takes place on a flat torus, i.e., if an ant goes beyond the left edge, it reappears on the right, and vice versa, and similarly with the top and the bottom edges. You can see all of the torus and you can find the width of the visible area in SIZE_X and the height in SIZE_Y. These lengths are given in the game's unit system, which used for the speed of the ants, too. To get a feeling for the size of the world, note that gatherers not carrying food will take one hundred ticks to move from the left edge to right edge once. The parameters SIZE_X and SIZE_Y in parameters.txt are valid for a two player game. In games with more than two players, the game world scales with the number of players such that its area is proportional to the number of players, i.e. the lengths are proportional the square root of the number of players and parameters.SIZE_X and parameters.SIZE_Y contain the actual values.

Game world initialization

At the beginning of the game, you have some food, STARTING_FOOD, but no ants. You will want to produce some, but note that the victory condition is not checked until DONT_CHECK_VICTORY_CONDITION_BEFORE ticks have passed. The hills are placed randomly ensuring a minimum distance of MINIMUM_DISTANCE_BETWEEN_HILLS. There are three sugar sources per player at any time, and the sugar sources present at the beginning of the game are placed differently than those which appear for depleted ones. The initial sugar sources are no further than MAXIMUM_STARTING_SUGAR_DISTANCE away from the hill they belong to and at least MINIMUM_STARTING_SUGAR_DISTANCE away from the hill they belong to and the other sugar sources. This is to ensure some fairness at the beginning. The initial sugar sources have a relatively small minimum distance of at least MINIMUM_STARTING_SUGAR_DISTANCE_TO_OTHER_HILLS to the other hills, making it harder to guess the location of the enemy hill from the distribution of the sugar sources.

New sugar sources

At the end of each tick, new sugar sources are created to ensure that there always are SUGAR_SOURCES_PER_PLAYER many sugar sources per player. The sugar sources are placed in a random position at least MINIMUM_SUGAR_DISTANCE away from every hill and at least MINIMUM_SUGAR_DISTANCE_TO_OTHER_SUGAR away from every other sugar source.

Note on randomly placed objects

Due to an implementation detail of the random placement of objects, it is possible, although hopefully extremely rare, that one of the rules for placing objects is violated.

Torus geometry

Since the ants live on a torus you have to be careful when measuring distances. Functions like AntAI.vectorToHome() will always return the shortest possible vector on the torus.

Game Control

The file settings.txt in the root directory defines which AI's will play against each other. Note that the game speed can be changed there, but also while the game is running using the hotkeys.

TOURNAMENT = false will let all specified AIs play against each other in a big game. You can also name the same AI multiple times. Setting TOURNAMENT to true will let the AIs play against each other in pairs and print a summary at the end.

Graphics

Sugar is white. The larger circles are the sources and ants carrying sugar will have a white dot inside them. The size of sugar sources is proportional to the remaining sugar. Ants are small and hills larger circles in the players color. Dead ants are smaller dots drawn in a darker color. If two ants occupy the same spot, their colors blend.

Keyboard Hotkeys