|
|||||||||
| PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES | ||||||||
See:
Description
| Interface Summary | |
|---|---|
| IRobocodeEngine | Interface for the RobocodeEngine. |
| RobocodeListener | Deprecated. Since 1.6.2. |
| Class Summary | |
|---|---|
| BattlefieldSpecification | Defines the size of a battlefield, which is a part of the
BattleSpecification. |
| BattleSpecification | A BattleSpecification defines battle configuration used by the
RobocodeEngine. |
| RandomFactory | The RandomFactory is used for controlling the generation of random numbers, and supports generating random numbers that are deterministic, which is useful for testing purposes. |
| RobocodeEngine | The RobocodeEngine is the interface provided for external applications in order to let these applications run battles within the Robocode application, and to get the results from these battles. |
| RobotResults | Contains the battle results for an individual robot |
| RobotSpecification | Defines the properties of a robot, which is returned from
RobocodeEngine.getLocalRepository() or |
Control API used for controlling Robocode from an external application.
Here is a simple application that runs a battle in Robocode for 5 rounds on the default battlefield of 800x600 pixels. The robots selected for the battle are sample.RamFire and sample.Corners.
import robocode.control.*;
import robocode.control.events.*;
/**
* Application that demonstrates how to run two sample robots in Robocode using the
* RobocodeEngine from the robocode.control package.
*
* @author Flemming N. Larsen
*/
public class RobocodeRunner {
public static void main(String[] args) {
// Create the RobocodeEngine
// RobocodeEngine engine = new RobocodeEngine(); // Run from current working directory
RobocodeEngine engine = new RobocodeEngine(new java.io.File("C:/Robocode")); // Run from C:/Robocode
// Add our own battle listener to the RobocodeEngine
engine.addBattleListener(new BattleObserver());
// Show the Robocode battle view
engine.setVisible(true);
// Setup the battle specification
int numberOfRounds = 5;
BattlefieldSpecification battlefield = new BattlefieldSpecification(800, 600); // 800x600
RobotSpecification[] selectedRobots = engine.getLocalRepository("sample.RamFire, sample.Corners");
BattleSpecification battleSpec = new BattleSpecification(numberOfRounds, battlefield, selectedRobots);
// Run our specified battle and let it run till it is over
engine.runBattle(battleSpec, true/* wait till the battle is over */);
// Cleanup our RobocodeEngine
engine.close();
// Make sure that the Java VM is shut down properly
System.exit(0);
}
}
/**
* Our private battle listener for handling the battle event we are interested in.
*/
class BattleObserver extends BattleAdaptor {
// Called when the battle is completed successfully with battle results
public void onBattleCompleted(BattleCompletedEvent e) {
System.out.println("-- Battle has completed --");
// Print out the sorted results with the robot names
System.out.println("Battle results:");
for (robocode.BattleResults result : e.getSortedResults()) {
System.out.println(" " + result.getTeamLeaderName() + ": " + result.getScore());
}
}
// Called when the game sends out an information message during the battle
public void onBattleMessage(BattleMessageEvent e) {
System.out.println("Msg> " + e.getMessage());
}
// Called when the game sends out an error message during the battle
public void onBattleError(BattleErrorEvent e) {
System.out.println("Err> " + e.getError());
}
}
|
|||||||||
| PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES | ||||||||