AI of a robot is programmed as a script in the Angel Script Language. A script fully describes the behavior of a robot and is evoked at each cycle of the game for each robot of a team. All the robots of the same team share the same script. Angel Script Language syntax is very close to the syntax of C++.
Main function of a script is the function Execute. This function is called from a game simulator. Function prototype:
void Execute(RobotState&, const Environment&);
Function arguments are described below.
An Environment object specifies parameters of a game world.
class Environment
{
public:
int bases_count;
int field_width;
int field_height;
int robot_hp;
int base_hp;
int shoot_range;
int view_range;
int transmit_range;
int reload_time;
int robot_construction_time;
int msg_size;
int memory_size;
int iter;
int last_iter;
int timeout;
int dist(int x1, int y1, int x2, int y2);
bool shift(int x, int y, int dir, int &dx, int &dy);
int get_dir(int x1, int y1, int x2, int y2);
};
Class members:
Class member | Meaning |
bases_count | Total number of bases in the field |
field_width | Field width in cells |
field_height | Field height in cells |
robot_hp | Maximum of robot hitpoints |
base_hp | Maximum of base hitpoints |
shoot_range | Shooting range |
view_range | View range |
transmit_range | Transmission range |
reload_time | Weapon reload time |
robot_construction_time | Robot construction time |
msg_size | Message size in bytes |
memory_size | Robot’s memory size in bytes |
iter | Current cycle number |
last_iter | Maximal cycle number (end of game parameter) |
timeout | Maximal time of game simulation in seconds (end of game parameter) |
This attributes are set before the first cycle of a game, are common for all robots and bases and cannot be changed during the game.
Member functions:
Function | Action |
dist | Computes distance between the cells (x1, y1) and (x2, y2) |
shift | Computes coordinates of the target cell (dx, dy) as a result of a move from the cell (x, y) in the direction dir. The function returns false, if the move is invalid |
get_dir | Computes the direction of the move from the cell (x1, y1) to the cell (x2, y2) |
The RobotState object defines the state of a robot. So, the state of the robot is preserved in such an object between the cycles and passed each cycle to the Execute function to be processed.
class RobotState
{
public:
int x, y;
int team;
int hitpoints;
int cooldown;
bool shoot;
bool transmit;
int move_direction;
int shoot_x, shoot_y;
uint get_msgs_num();
uint get_robots_num();
uint get_bases_num();
Unit get_robot(uint ind);
Unit get_base(uint ind);
void set_mem_int(uint pos, int val);
void set_msg_int(uint pos, int val);
int get_mem_int(uint pos);
int get_msg_int(uint pos);
int get_msgs_int(uint ind, uint pos);
void copy_to_msg(uint ind);
};
First group of members describes characteristics of the robot that cannot be changed by the robot (that is by Execute function):
Class member | Meaning |
x, y | Current coordinates of the robot |
team | Owner of the robot |
hitpoints | Current hitpoints value |
cooldown | Cycles to reload a weapon |
Second group describes robot’s decisions to act at the current cycle. These values are computed by the Execute function.
Class member | Meaning |
shoot | Shooting flag; true means the robot desires to shoot |
transmit | Broadcasting flag; true means the robot wishes to broadcast a message |
move_direction | Direction in which the robot wished to move (0, if the robots does not want to move) |
shoot_x, shoot_y | Coordinates of a target cell to shoot |
Member-functions of the RobotState class return different information on the units (robots or bases) in the view range of the robot:
Function | Action |
get_robots_num | Returns the number of visible robots |
get_bases_num | Returns the number of visible bases |
get_robot(ind) | Returns information on the robot number ind in the list of visible robots, 0 ≤ ind < get_robots_num() |
get_base(ind) | Returns information on the base number ind in the list of visible bases, 0 ≤ ind < get_bases_num( |
Unit class is used to represent information about visible units:
class Unit
{
public:
int x, y;
int team;
int dist;
};
Unit class members:
Class member | Meaning |
x, y | Unit coordinates |
team | Owning team number (-1 for a neutral base) |
dist | Distance to the unit |
Member-functions of the class RobotState to handle memory and messages:
Function | Action |
set_mem_int | Put the value val (of the type int) into the memory location pos |
set_msg_int | Put the value val (of the type int) into the “main” message buffer location pos |
get_mem_int | Get a value (of the type int) from the memory location pos |
get_msg_int | Get a value (of the type int) from the “main” message buffer location pos |
get_msgs_num | Get the number of received messages |
get_msgs_int | Get a value (of the type int) from the received message number ind from the location pos, 0 ≤ ind < get_msgs_num() |
copy_to_msg | Copy received message number ind into the “main” message, 0 ≤ ind < get_msgs_num() |
All the incoming messages are received before the call to the Execute function. If the robot wished to broadcast a message, it has to put on the broadcasting flag and prepare the “main” message. Memory state can be used to keep information between the cycles.