Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Arjan Dikhoff committed Mar 22, 2013
2 parents c246dd7 + 9b5c9fb commit 2b57e77
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions your_code_here/src/nl/ordina/nerdingout/round_3/Veamer.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ public class Veamer extends AdvancedRobot {
private static final int DISTANCE = 100;
private Random random = new Random();
private volatile String nameToKill = "";
private double maxHeight;
private double maxWidth;

@Override
public void run() {
maxHeight = getBattleFieldHeight() - 20;
maxWidth = getBattleFieldWidth() - 20;
// setAdjustRadarForRobotTurn(true);
setColors(Color.BLACK, Color.BLACK, Color.WHITE);
while (true) {
Expand All @@ -28,18 +32,19 @@ public void run() {

@Override
public void onScannedRobot(final ScannedRobotEvent e) {
System.out.println("e.getDistance() = " + e.getDistance());
System.out.println("e.getName() = " + e.getName());
if (e.getDistance() < DISTANCE && nameToKill.isEmpty()) {
nameToKill = e.getName();
System.out.println("Go get m!!!");
}
if (!nameToKill.isEmpty()) {
System.out.println("kill someone");
setTurnRight(e.getBearing());
setFire(Math.min(250 / e.getDistance(), 3));
setAhead(e.getDistance() - 10);
turnGunRight(normalRelativeAngleDegrees(((getHeading() - getRadarHeading()) + e.getBearing())));
if (getGunHeat() == 0) {
fire(Math.min(250 / e.getDistance(), 3));
}
avoidWalls();
return;
}

Expand All @@ -56,6 +61,7 @@ public void onScannedRobot(final ScannedRobotEvent e) {
} else {
turnRight(180);
}
avoidWalls();
}

private boolean chance(final double chance) {
Expand Down Expand Up @@ -90,6 +96,25 @@ public void onHitWall(final HitWallEvent e) {
}
}

private void avoidWalls() {
if (nearingNorth() || nearingSouth() || nearingEast() || nearingWest()) {
back(100);
}
}

private boolean nearingNorth() {
return getY() > maxHeight;
}
private boolean nearingSouth() {
return getY() < 20;
}
private boolean nearingEast() {
return getX() > maxWidth;
}
private boolean nearingWest() {
return getX() < 20;
}

public void onWin(WinEvent e) {
// Victory dance
turnRight(36000);
Expand Down

0 comments on commit 2b57e77

Please sign in to comment.