Skip to content

Instantly share code, notes, and snippets.

@oyvindrobertsen
Created September 3, 2013 19:14
Show Gist options
  • Save oyvindrobertsen/6428288 to your computer and use it in GitHub Desktop.
Save oyvindrobertsen/6428288 to your computer and use it in GitHub Desktop.
package testBot1;
import robocode.*;
import java.awt.Color;
import java.util.Random;
public class Marvin extends Robot {
/**
* run: Fubot's default behavior
*/
public void run() {
// Initialization of the robot should be put here
// After trying out your robot, try uncommenting the import at the top,
// and the next line:
// setColors(Color.red,Color.blue,Color.green); // body,gun,radar
// Robot main loop
setAllColors(Color.BLACK);
setScanColor(Color.YELLOW);
while(true) {
if (getX() / getBattleFieldWidth() > 0.9 || getX() / getBattleFieldWidth() < 0.12) {
turnLeft(90);
}
if (getY() / getBattleFieldHeight() > 0.9 || getY() / getBattleFieldHeight() < 0.12) {
turnLeft(90);
}
turnGunLeft(360);
ahead(50);
}
}
/**
* onScannedRobot: What to do when you see another robot
*/
public void onScannedRobot(ScannedRobotEvent e) {
// Replace the next line with any behavior you would like
this.turnRight(e.getBearing());
fire(Rules.MAX_BULLET_POWER - e.getDistance()/100);
ahead(10);
}
public void turnRandom(){
Random generator = new Random();
if ( generator.nextBoolean() )
turnRight( generator.nextInt(180) );
else
turnLeft( generator.nextInt(180) );
}
/**
* onHitByBullet: What to do when you're hit by a bullet
*/
public void onHitByBullet(HitByBulletEvent e) {
//turnRandom();
}
/**
* onHitWall: What to do when you hit a wall
*/
// public void onHitWall(HitWallEvent e) {
//
// }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment