Created
June 7, 2017 15:58
-
-
Save cbilson/95381d09308188ef0af63298d21cd2b8 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
import java.awt.Color; | |
import ihs.apcs.spacebattle.BasicEnvironment; | |
import ihs.apcs.spacebattle.BasicSpaceship; | |
import ihs.apcs.spacebattle.Point; | |
import ihs.apcs.spacebattle.RadarResults; | |
import ihs.apcs.spacebattle.RegistrationData; | |
import ihs.apcs.spacebattle.commands.IdleCommand; | |
import ihs.apcs.spacebattle.commands.RadarCommand; | |
import ihs.apcs.spacebattle.commands.RotateCommand; | |
import ihs.apcs.spacebattle.commands.ShipCommand; | |
import ihs.apcs.spacebattle.commands.ThrustCommand; | |
public class SurvivorShip extends BasicSpaceship { | |
@Override | |
public ShipCommand getNextCommand(BasicEnvironment env) { | |
Point p = env.getShipStatus().getPosition(); | |
int heading = env.getShipStatus().getOrientation(); | |
RadarResults r = env.getRadar(); | |
if (r != null) { | |
for (int i = 0; i < r.getNumObjects(); i++) { | |
double distance = r.get(i) | |
.getPosition().getDistanceTo(p); | |
int angle = r.get(i) | |
.getPosition().getAngleTo(p); | |
if (distance < 50.0 | |
&& Math.abs(heading - angle) < 30) { | |
return new RotateCommand(90); | |
} | |
} | |
return new ThrustCommand('B', 0.5, 0.5); | |
} | |
return new RadarCommand(5); | |
} | |
@Override | |
public RegistrationData registerShip( | |
int numImages, | |
int worldWidth, | |
int worldHeight) { | |
return new RegistrationData( | |
"Chris's Survivor", | |
new Color(50, 50, 200), | |
0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment