The Goal
Your program must destroy the enemy ships by shooting the closest enemy on each turn.
Rules
On each start of turn (within the game loop), you obtain information on the two closest enemies:
- enemy1 and dist1: the name and the distance to enemy 1.
- enemy2 and dist2: the name and the distance to enemy 2.
Solution
// game loop
while (true) {
var enemy1 = readline(); // name of enemy 1
var dist1 = parseInt(readline()); // distance to enemy 1
var enemy2 = readline(); // name of enemy 2
var dist2 = parseInt(readline()); // distance to enemy 2
if (dist1 < dist2) {
print(enemy1);
} else {
print(enemy2);
}
}