Merge pull request #1 from delmadord/movement

Movement done
master
delmadord 9 years ago
commit 483cdf4529
  1. 70
      src/myrobot/FirstRobot.java
  2. 3
      src/standalone/RouteFinder.java

@ -1,9 +1,5 @@
package myrobot;
/*******************************************************************************
* Copyright (c) 2001-2014 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
@ -12,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/>
@ -34,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
*/
@ -49,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());
}
}
}

@ -3,7 +3,8 @@ package standalone;
import robocode.control.*;
//import robocode.control.events.*;
//asdfafd
//movement
//...
public class RouteFinder {

Loading…
Cancel
Save