/* Slowly moves east and west. Does not fire. */
var west = false;
while (true) {
if (west) {
if (getX() > 25) {
swim(180, 25);
} else {
west = false;
swim(0, 0);
}
} else {
if (getX() < 75) {
swim(0, 25);
} else {
west = true;
swim(0, 0);
}
}
}
/* Moves south-west when hit. Does not fire. */
var d = damage();
while (true) {
if (d != damage()) {
swim(45, 100);
var t = 0;
for (var t = 0; t < 100; t++) {}
d = damage();
stop();
}
}
This opponent is too far away to use the cannon (which has a limit of 70 meters). Instead, use the 'swim' command to start swimming towards the opponent and crash into it.
Congratulations!
Your solution works, but you can do better. Use 'scan' to tell the cannon how far to shoot.