Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@rogerluan
Last active April 9, 2024 19:50
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rogerluan/d62a26039d9bcb9395f5d391fb1a17ae to your computer and use it in GitHub Desktop.
Save rogerluan/d62a26039d9bcb9395f5d391fb1a17ae to your computer and use it in GitHub Desktop.
A simple yet extremely effective Robocode robot.
package a20;
import robocode.*;
import java.awt.Color;
/**
* DefMode - A Robocode robot
* @author: Roger Oba
* @date: September 2014
*
* This robot won 2nd place in an internal Robocode tournament. The 1st place had a complex algorithm with over 1k LOC, and most other participants had over 600 LOC ;)
*
* Benchmark: out of 10000 battles against the "Walls" robot, this robot won 9829 and lost 171 times (98.29%).
*/
public class DefMode extends AdvancedRobot {
int gunDirection = 1;
public void run() {
// Mere aesthetic changes
setBodyColor(Color.black);
setRadarColor(Color.green);
setGunColor(Color.black);
setBulletColor(Color.orange);
// Turns the gun infinitely, looking for enemies
while (true) {
turnGunRight(360);
}
}
public void onScannedRobot(ScannedRobotEvent e) {
// Turn the robot towards the enemy
setTurnRight(e.getBearing());
// Shoots always that it's aiming at the enemy
setFire(3);
// And move forward
setAhead(100);
// Inverts the gun direction on each turn
gunDirection = -gunDirection;
// Turn 360 degrees (clockwise or anti clockwise,)
setTurnGunRight(360 * gunDirection);
// Execute all the pending actions
execute();
}
}
@kikocorex
Copy link

damn!

@Darkempire78
Copy link

not very effective :(

@rogerluan
Copy link
Author

Against what benchmark @Darkempire78 ? :)

I'm sure that in the past 10 years a lot has changed in the space haha

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment