The Psylonian race is known to wield by far the most advanced military battle-robots. During the fight for Terra, it took four of these battle-robots only three hours to completely wipe out one of the ancient cities with adjacent territories. You’d better watch your back with them. The Earth Defense Forces command is utterly preoccupied. Personnel is being trained for military operations against Psylonians in case the armed conflict bursts out again. But working out good tactics requires modeling of the battle-robot’s artificial intelligence unit. And you are to help us!
The robot’s behavior turned out to be rather simple. He can use just four basic patterns: “Defense”, “Attack”, “Guard” and “Patrol”. Moreover, the behavior control unit you have to model implements a rather simple scheme: it takes some parameters as input and outputs one of the following commands for the robot to execute:
LEFT X – spend X energy units for turning left;
RIGHT X – spend X energy units for turning right;
FRONT X – spend X energy units for moving forward;
BACKWARD X – spend X energy units for moving backward;
FIRE P – spend P fire units for attacking the enemy;
STOP – nothing to do.
In all these cases X is calculated as follows: If the robot’s power supply has more than 100 energy units available, then X = 100; otherwise, X is the amount of power units remaining. Similarly, P is calculated as the smallest of two values: 20 and the actual amount of ammunition units remaining.
The most simple behavioral pattern is “Guard”. When it’s active, robot does not walk, it can only turn. It picks the most dangerous target, and determines angle between robot’s current line of sight and direction to the target. If the angle is less than 5 degrees (by absolute value), robot shoots. Otherwise, if the angle is greater than or equals to 5, the robot turns left; if the angle is less than or equals to -5, the command is to turn right. If there are no targets around, robot does nothing.
According to the “Defense” pattern, robot’s actions are defined as follows: calculate the number of enemies and multiply it by 20. If the result is not less than the amount of ammunition units left, the robot will “Retreat and Return Fire”. Otherwise, it will act as if following the “Guard” pattern.
The “Attack” pattern works as follows: If N*NP > M*MP*3, then the robot will “Advance and Return Fire”; else it will “Retreat and Return Fire”. Here: N is the total number of allied battle-robots; NP is the average amount of energy units they have remaining; M is the total number of enemy robots; MP is the average amount of energy units the enemy robots have remaining.
When the battle-robot “Retreats and Returns Fire”, it checks the angle to the most dangerous enemy. If the angle is 5 degrees or more, or there are no enemies, the robot just moves backward. Otherwise, it fires its guns.
Similarly, when the battle-robot “Advances and Returns Fire”, it checks the angle to the most dangerous enemy. If the angle is 10 degrees or more, or there are no enemies, the robot just moves forward or shoots otherwise.
When “Patrolling”, the robot follows its waypoint route, if there are no enemies. If the robot encounters enemy when patrolling, then it acts as if the “Defense” pattern was active. When following a route, robot uses this algorithm to move to the next waypoint:
If the angle to the next waypoint exceeds 20 degrees by absolute value, the robot turns into direction to waypoint. Note that it does not matter whether the robot is moving forward or backward while following the route. You should consider this when calculating the turn direction - the turn angle should be minimal.
Otherwise, if the angle to the next waypoint does not exceed 20, then the robot just moves towards the next waypoint.
The first line contains two integers separated by space; the first integer is the amount of energy units available, the second one is the amount of ammunition available. The second line contains a single character, which determines the operating pattern: G stands for “Guard”, D for “Defense”, A for “Attack”, and P for “Patrol”. On the third line there are three integers: amount of enemies, average amount of energy units enemy bots possess, and angle to the most dangerous enemy target.
If the robot follows the “Attack” pattern, then the fourth line contains two integers: amount of allied bots and average amount of power units remaining in their power supplies, respectively. If the robot follows the “Patrol” pattern, then the fourth line contains only one integer: angle to the next waypoint.
Angle values range from -179 to 180 inclusive, all other integers are non-negative and
none of them exceeds 1000.
The command for the robot using the format described above.
0 0 0
1 10 30
1 10 4
Problem Author: Pavel Egorov
Problem Source: IX Open Collegiate Programming Contest of the High School Pupils (13.03.2004)