From 4ccc98d1df32d53b4812ab1e1c0a9eb8dcc58153 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Babi=C4=8D?= Date: Sun, 8 Mar 2015 00:45:11 +0100 Subject: [PATCH] first commit --- .classpath | 11 +++++ .gitattributes | 2 + .gitignore | 3 ++ .project | 17 +++++++ .settings/org.eclipse.jdt.core.prefs | 11 +++++ README.md | 3 ++ src/myrobot/FirstRobot.java | 58 ++++++++++++++++++++++ src/standalone/RouteFinder.java | 73 ++++++++++++++++++++++++++++ 8 files changed, 178 insertions(+) create mode 100644 .classpath create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 .project create mode 100644 .settings/org.eclipse.jdt.core.prefs create mode 100644 README.md create mode 100644 src/myrobot/FirstRobot.java create mode 100644 src/standalone/RouteFinder.java diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..186b5d5 --- /dev/null +++ b/.classpath @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..70a6a09 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +*.od* filter=lfs diff=lfs merge=lfs -text +*.pptx* filter=lfs diff=lfs merge=lfs -text diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4170712 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/bin/ +/robocode-source/ + diff --git a/.project b/.project new file mode 100644 index 0000000..6f25e4c --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + robocode + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..7341ab1 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/README.md b/README.md new file mode 100644 index 0000000..b589856 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# robocode + +Don't forget to link `./src/myrobot/` to `C:/robocode/robots/myrobot/` diff --git a/src/myrobot/FirstRobot.java b/src/myrobot/FirstRobot.java new file mode 100644 index 0000000..c7dd7ec --- /dev/null +++ b/src/myrobot/FirstRobot.java @@ -0,0 +1,58 @@ +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. + *

+ * 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) { + ahead(100); // Move ahead 100 + turnGunRight(360); // Spin gun around + back(100); // Move back 100 + turnGunRight(360); // Spin gun around + } + } + + /** + * 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()); + } +} diff --git a/src/standalone/RouteFinder.java b/src/standalone/RouteFinder.java new file mode 100644 index 0000000..d03eb4b --- /dev/null +++ b/src/standalone/RouteFinder.java @@ -0,0 +1,73 @@ +package standalone; + +import robocode.control.*; +//import robocode.control.events.*; + +//asdfafd +//... + +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 + + // Setup battle parameters + int numberOfRounds = 1; + long inactivityTime = 10000000; + double gunCoolingRate = 1.0; + int sentryBorderSize = 50; + boolean hideEnemyNames = false; + + // int NumObstacles = (int) Math.round(NumPixelCols * NumPixelRows * 0.3); + int NumObstacles = 5; + + /* + * Create obstacles and place them at random so that no pair of obstacles are at the same position + */ + RobotSpecification[] modelRobots = engine.getLocalRepository("sample.SittingDuck,myrobot.FirstRobot*"); + + RobotSpecification[] existingRobots = new RobotSpecification[NumObstacles + 1]; + RobotSetup[] robotSetups = new RobotSetup[NumObstacles + 1]; + + for (int NdxObstacle = 0; NdxObstacle < NumObstacles; NdxObstacle++) { + + // double InitialObstacleRow = null; + // double InitialObstacleCol = null; + existingRobots[NdxObstacle] = modelRobots[0]; + robotSetups[NdxObstacle] = new RobotSetup(null, null, 0.0); + } + + /* + * Create the agent and place it in a random position without obstacle + */ + existingRobots[NumObstacles] = modelRobots[1]; + // double InitialAgentRow = 1; + // double InitialAgentCol = 1; + robotSetups[NumObstacles] = new RobotSetup(null, null, 0.0); + + /* Create and run the battle */ + BattleSpecification battleSpec = new BattleSpecification(battlefield, numberOfRounds, inactivityTime, gunCoolingRate, + sentryBorderSize, hideEnemyNames, existingRobots, robotSetups); + + // Run our specified battle and let it run till it is over + engine.runBattle(battleSpec, true); // waits till the battle finishes + + // Cleanup our RobocodeEngine + engine.close(); + + // Make sure that the Java VM is shut down properly + System.exit(0); + } + +} \ No newline at end of file