steps and grid

master
Peter Babič 9 years ago
parent e4c1a06b9b
commit c9616e79f2
  1. 71
      src/myrobot/FirstRobot.java
  2. 34
      src/standalone/RouteFinder.java
  3. 15
      src/world/Generator.java

@ -1,75 +1,38 @@
package myrobot;
/*******************************************************************************
* Copyright (c) 2001-2014 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* 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/>
* Moves in a seesaw motion, and spins the gun around at each end.
*
* @author Mathew A. Nelson (original)
*/
public class FirstRobot extends Robot {
/**
* MyFirstRobot's run method - Seesaw
*/
public void run() {
while (true) {
right();
ahead(128);
down();
ahead(64);
left();
ahead(128);
up();
ahead(64);
right();
ahead(128);
up();
ahead(64);
left();
ahead(128);
down();
ahead(64);
doNothing();
}
}
public void up() {
public void north() {
turn(0);
}
public void right() {
public void east() {
turn(90);
}
public void down() {
public void south() {
turn(180);
}
public void left() {
public void west() {
turn(270);
}
public void steps(int num) {
ahead(num * world.Generator.STEP);
}
private void turn(int dest) {
int curr = (int) getHeading();
@ -84,17 +47,5 @@ public class FirstRobot extends Robot {
/**
* Fire when we see a robot
*/
public void onScannedRobot(ScannedRobotEvent e) {
fire(1);
}
/**
* 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,26 +3,16 @@ package standalone;
import robocode.control.*;
//import robocode.control.events.*;
//movement
//...
public class RouteFinder {
public static void main(String[] args) {
// Create the RobocodeEngine, e.g. "C:/robocode"
RobocodeEngine engine = new RobocodeEngine(new java.io.File("/opt/robocode"));
// Show the Robocode battle view
engine.setVisible(true);
// Create the battlefield
int NumPixelRows = 800;
int NumPixelCols = 600;
BattlefieldSpecification battlefield = new BattlefieldSpecification(NumPixelRows, NumPixelCols); // 800x600
// Location of the robocode, e.g. "C:/robocode"
String location = "/opt/robocode";
// Setup battle parameters
int numberOfRounds = 1;
long inactivityTime = 10000000;
@ -32,6 +22,20 @@ public class RouteFinder {
// int NumObstacles = (int) Math.round(NumPixelCols * NumPixelRows * 0.3);
int NumObstacles = 5;
// Create the RobocodeEngine
RobocodeEngine engine = new RobocodeEngine(new java.io.File(location));
// Show the Robocode battle view
engine.setVisible(true);
// Create the battlefield
int NumPixelRows = world.Generator.HEIGHT;
int NumPixelCols = world.Generator.WIDTH;
BattlefieldSpecification battlefield = new BattlefieldSpecification(NumPixelRows, NumPixelCols);
/*
* Create obstacles and place them at random so that no pair of obstacles are at the same position

@ -0,0 +1,15 @@
package world;
public class Generator {
public static final int STEP = 64;
public static final int WIDTH = 10 * STEP;
public static final int HEIGHT = 8 * STEP;
}
Loading…
Cancel
Save