Created
November 27, 2019 02:35
-
-
Save gervasiocaj/b23f133e6561b000178f0c6224ea7c6b to your computer and use it in GitHub Desktop.
This file contains 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 compal; | |
import robocode.*; | |
import java.awt.Color; | |
import robocode.ScannedRobotEvent; | |
import robocode.util.Utils; | |
// API help : https://robocode.sourceforge.io/docs/robocode/robocode/Robot.html | |
/** | |
* NewLaziness - a robot by (Compal Team) | |
*/ | |
public class NewLaziness extends AdvancedRobot | |
{ | |
double previousEnergy = 100; | |
int movementDirection = 1; | |
int weaponDir = 1; | |
/** | |
* run: NewLaziness's default behavior | |
*/ | |
public void run() { | |
initialize(); | |
newMovement(); | |
} | |
private void newMovement(){ | |
setTurnGunRight(99999); | |
} | |
/** | |
* Initializes this robot before a new round in a battle. | |
*/ | |
private void initialize() { | |
// Set robot colors | |
setBodyColor(Color.GRAY); | |
setGunColor(Color.BLACK); | |
setRadarColor(Color.BLACK); | |
setBulletColor(Color.BLUE); | |
setScanColor(Color.GRAY); | |
} | |
/** | |
* onScannedRobot: What to do when you see another robot | |
*/ | |
public void onScannedRobot(ScannedRobotEvent e){ | |
getTheRobotNow(e); | |
} | |
private void getTheRobotNow(ScannedRobotEvent e){ | |
double absoluteBearing = getHeading() + e.getBearing(); | |
double bearingFromGun = Utils.normalRelativeAngleDegrees(absoluteBearing - getGunHeading()); | |
setTurnRight(e.getBearing()+90-30*movementDirection); | |
turnGunRight(bearingFromGun); | |
// Check if the robot was damaged | |
double changeInEnergy = previousEnergy-e.getEnergy(); | |
if (changeInEnergy > 0 && changeInEnergy <= 3) { | |
movementDirection = -movementDirection; | |
setAhead((e.getDistance()/4+25)* movementDirection); | |
} | |
// When a bot is spotted, | |
// sweep the gun and radar | |
weaponDir = -weaponDir; | |
setTurnGunRight(99999*weaponDir); | |
// Fire the target!! | |
if (getGunHeat() == 0) fire(2); | |
// get the energy level from scanned robot | |
previousEnergy = e.getEnergy(); | |
} | |
/** | |
* onHitByBullet: What to do when you're hit by a bullet | |
*/ | |
public void onHitByBullet(HitByBulletEvent e){ | |
if (getVelocity() == 0) movementDirection *= -1; | |
// circle our enemy | |
setTurnRight(e.getBearing() + 90); | |
setAhead(1000 * movementDirection); | |
} | |
/** | |
* onHitWall: What to do when you hit a wall | |
*/ | |
public void onHitWall(HitWallEvent e){ | |
double bearing = e.getBearing(); | |
turnRight(-bearing); | |
ahead(100); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment