|
|
|
@ -1,7 +1,5 @@ |
|
|
|
|
package myrobot; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************* |
|
|
|
|
* Copyright (c) 2001-2014 Mathew A. Nelson and Robocode contributors |
|
|
|
|
* All rights reserved. This program and the accompanying materials |
|
|
|
@ -10,13 +8,10 @@ package myrobot; |
|
|
|
|
* http://robocode.sourceforge.net/license/epl-v10.html
|
|
|
|
|
*******************************************************************************/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import robocode.HitByBulletEvent; |
|
|
|
|
import robocode.Robot; |
|
|
|
|
import robocode.ScannedRobotEvent; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* MyFirstRobot - a sample robot by Mathew Nelson. |
|
|
|
|
* <p/> |
|
|
|
@ -32,13 +27,63 @@ public class FirstRobot extends Robot { |
|
|
|
|
public void run() { |
|
|
|
|
|
|
|
|
|
while (true) { |
|
|
|
|
ahead(100); // Move ahead 100
|
|
|
|
|
turnGunRight(360); // Spin gun around
|
|
|
|
|
back(100); // Move back 100
|
|
|
|
|
turnGunRight(360); // Spin gun around
|
|
|
|
|
right(); |
|
|
|
|
ahead(128); |
|
|
|
|
|
|
|
|
|
down(); |
|
|
|
|
ahead(64); |
|
|
|
|
|
|
|
|
|
left(); |
|
|
|
|
ahead(128); |
|
|
|
|
|
|
|
|
|
up(); |
|
|
|
|
ahead(64); |
|
|
|
|
|
|
|
|
|
right(); |
|
|
|
|
ahead(128); |
|
|
|
|
|
|
|
|
|
up(); |
|
|
|
|
ahead(64); |
|
|
|
|
|
|
|
|
|
left(); |
|
|
|
|
ahead(128); |
|
|
|
|
|
|
|
|
|
down(); |
|
|
|
|
ahead(64); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void up() { |
|
|
|
|
turn(0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void right() { |
|
|
|
|
turn(90); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void down() { |
|
|
|
|
turn(180); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void left() { |
|
|
|
|
turn(270); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void turn(int dest) { |
|
|
|
|
int curr = (int) getHeading(); |
|
|
|
|
if (curr != dest) { |
|
|
|
|
int diff = curr - dest; |
|
|
|
|
if (Math.abs(diff) > 180) |
|
|
|
|
turnRight(diff % 180); |
|
|
|
|
else |
|
|
|
|
turnLeft(diff); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Fire when we see a robot |
|
|
|
|
*/ |
|
|
|
@ -47,10 +92,9 @@ public class FirstRobot extends Robot { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* We were hit! Turn perpendicular to the bullet, |
|
|
|
|
* so our seesaw might avoid a future shot. |
|
|
|
|
* We were hit! Turn perpendicular to the bullet, so our seesaw might avoid a future shot. |
|
|
|
|
*/ |
|
|
|
|
public void onHitByBullet(HitByBulletEvent e) { |
|
|
|
|
turnLeft(90 - e.getBearing()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|