Created
September 25, 2015 09:36
-
-
Save berkes/89e416c0b311d3de93e8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package EB9000; | |
import robocode.*; | |
//import java.awt.Color; | |
// API help : http://robocode.sourceforge.net/docs/robocode/robocode/Robot.html | |
/** | |
* Evilbot9000 - a robot by (your name here) | |
*/ | |
public class Evilbot9000 extends Robot | |
{ | |
/** | |
* run: Evilbot9000'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 | |
while(true) { | |
// Replace the next 4 lines with any behavior you would like | |
//scan(); | |
//turnRadarLeft(90); | |
//scan(); | |
//turnRadarRight(180); | |
//scan(); | |
//turnRadarLeft(90); | |
//scan(); | |
ahead(42); | |
//turnRight(-15); | |
//turnRight(30); | |
turnRight(360); | |
} | |
} | |
/** | |
* onScannedRobot: What to do when you see another robot | |
*/ | |
public void onScannedRobot(ScannedRobotEvent e) { | |
// Replace the next line with any behavior you would like | |
if (e.getDistance() < 100) { | |
fire(3); | |
} else { | |
fire(1); | |
} | |
double enemybearing = e.getBearingRadians(); | |
double enemydistance = e.getDistance(); | |
turnRight(enemybearing); | |
ahead(enemydistance/2); | |
} | |
/** | |
* onHitByBullet: What to do when you're hit by a bullet | |
*/ | |
public void onHitByBullet(HitByBulletEvent e) { | |
// Replace the next line with any behavior you would like | |
back(100); | |
} | |
/** | |
* onHitWall: What to do when you hit a wall | |
*/ | |
public void onHitWall(HitWallEvent e) { | |
// Replace the next line with any behavior you would like | |
back(242); | |
turnLeft(90); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment