/* 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 also too far away to use the cannon. But you are too weak to survive a collision. Swim towards the opponent while your horizontal location is less than than 50. Then 'stop' and use the cannon.
Congratulations!
Your solution works, but you can do better. Use 'scan' to tell the cannon how far to shoot.