/* 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 moves back and forth, making it hard to hit. The 'scan' expression returns the exact range to the opponent in the specified direction.
This range is exactly what the 'cannon' command needs to fire accurately.
Congratulations!
Your solution works, but you can do better. Use 'scan' to tell the cannon how far to shoot.