public abstract class RobotTestBed<R extends IBasicRobot> extends BattleAdaptor
The user must set the system property robocode.home to the location of the robocode installation, otherwise we cannot set up the Robocode engine. If robocode.home is not a system property, we throw a RuntimeException.
| Modifier and Type | Field and Description |
|---|---|
protected BattlefieldSpecification |
battleFieldSpec
The battlefield specification, which is the default.
|
protected static IRobocodeEngine |
engine
The Robocode game engine instance used for this test.
|
protected robocode.control.RobotTestBed.EngineErrorsListener |
engineErrorsListener |
protected int |
errors
The number of errors generated during this battle so far.
|
protected StringBuilder |
errorText |
protected Throwable |
lastError |
protected int |
messages
The number of messages generated during this battle so far.
|
protected R |
robotObject
Instance of tested robot
|
protected static String |
robotsPath |
protected robocode.control.RobotTestBed.TestErrorListener |
testErrorListener |
| Constructor and Description |
|---|
RobotTestBed() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
after() |
protected void |
afterInit()
Called after the engine is initialized to perform additional setup.
|
protected void |
before()
The setup method run before each test, which sets up the listener on the engine for testing.
|
protected void |
beforeInit() |
static void |
cleanup()
Releases any resources used by this test bed.
|
String |
getEnemyName()
Must return a fully qualified enemy robot name to be in this battle.
|
protected int |
getExpectedErrors() |
int |
getExpectedRobotCount(String robotList)
Provides the number of robots in this battle.
|
String |
getInitialPositions()
Returns a comma or space separated list like: x1,y1,heading1, x2,y2,heading2, which are the
coordinates and heading of robot #1 and #2.
|
int |
getNumRounds()
Provides the number of rounds in this battle.
|
abstract String |
getRobotName()
Must return a fully qualified robot name to be in this battle.
|
boolean |
isDeterministic()
Defaults to true, indicating that the battle is deterministic and robots will always start
in the same position each time.
|
static boolean |
isDumpingErrors()
Gets whether error messages should be printed out.
|
static boolean |
isDumpingMessages()
Gets whether robot messages should be printed out.
|
static boolean |
isDumpingOutput()
Gets whether robot output should be printed out.
|
static boolean |
isDumpingPositions()
Gets whether robot positions should be printed during each turn.
|
static boolean |
isDumpingTurns()
Gets whether each turn should be printed out.
|
boolean |
isEnableRecording() |
boolean |
isEnableScreenshots() |
protected void |
run() |
protected void |
run(String enemyName) |
protected void |
run(String robotName,
String enemyName) |
protected void |
runBattle(String robotList,
int numRounds,
String initialPositions) |
protected void |
runSetup() |
protected void |
runTeardown() |
static void |
setDumpingErrors(boolean dumpingErrors)
Sets whether error messages should be printed out.
|
static void |
setDumpingMessages(boolean dumpingMessages)
Sets whether robot messages should be printed out.
|
static void |
setDumpingOutput(boolean dumpingOutput)
Sets whether robot output should be printed out.
|
static void |
setDumpingPositions(boolean dumpingPositions)
Sets whether robot positions should be printed during each turn.
|
static void |
setDumpingTurns(boolean dumpingTurns)
Sets whether each turn should be printed out.
|
static void |
setErrorDumping(boolean value)
Thread-safe method to modify the error dumping flag.
|
static void |
setMessageDumping(boolean value)
Thread-safe method to modify the message dumping flag.
|
static void |
setOutputDumping(boolean value)
Thread-safe method to modify the output dumping flag.
|
static void |
setPositionDumping(boolean value)
Thread-safe method to modify the position dumping flag.
|
static void |
setTurnDumping(boolean value)
Thread-safe method to modify the turn dumping flag.
|
onBattleCompleted, onBattleError, onBattleFinished, onBattleMessage, onBattlePaused, onBattleResumed, onBattleStarted, onRoundEnded, onRoundStarted, onTurnEnded, onTurnStartedprotected static volatile IRobocodeEngine engine
protected final BattlefieldSpecification battleFieldSpec
protected int errors
protected StringBuilder errorText
protected Throwable lastError
protected robocode.control.RobotTestBed.EngineErrorsListener engineErrorsListener
protected robocode.control.RobotTestBed.TestErrorListener testErrorListener
protected int messages
protected static volatile String robotsPath
protected R extends IBasicRobot robotObject
public static void setPositionDumping(boolean value)
value - The new value for the flagpublic static void setTurnDumping(boolean value)
value - The new value for the flagpublic static void setOutputDumping(boolean value)
value - The new value for the flagpublic static void setErrorDumping(boolean value)
value - The new value for the flagpublic static void setMessageDumping(boolean value)
value - The new value for the flagpublic static boolean isDumpingPositions()
public static void setDumpingPositions(boolean dumpingPositions)
dumpingPositions - true to enable position dumpingpublic static boolean isDumpingTurns()
public static void setDumpingTurns(boolean dumpingTurns)
dumpingTurns - true to enable turn dumpingpublic static boolean isDumpingOutput()
public static void setDumpingOutput(boolean dumpingOutput)
dumpingOutput - true to enable output dumpingpublic static boolean isDumpingErrors()
public static void setDumpingErrors(boolean dumpingErrors)
dumpingErrors - true to enable error dumpingpublic static boolean isDumpingMessages()
public static void setDumpingMessages(boolean dumpingMessages)
dumpingMessages - true to enable message dumpingpublic abstract String getRobotName()
You must override this event to specify the robot to battle in this test case.
public String getEnemyName()
You must override this event to specify the robot to battle in this test case.
public int getNumRounds()
public String getInitialPositions()
Override this method to explicitly specify the initial positions.
Defaults to null, which means that the initial positions are determined randomly. Since battles are deterministic by default, the initial positions are randomly chosen but will always be the same each time you run the test case.
public int getExpectedRobotCount(String robotList)
robotList - The list of robots.public boolean isDeterministic()
Override to support random initialization.
public boolean isEnableRecording()
public boolean isEnableScreenshots()
protected void beforeInit()
protected void afterInit()
protected void before()
protected void after()
public static void cleanup()
This method should be called when the test framework is being shut down to ensure proper cleanup of resources. It will close the Robocode engine and release all associated resources.
It is recommended to call this method in a finally block or shutdown hook to ensure resources are properly released even if tests fail.
protected void run(String enemyName)
protected void run()
protected int getExpectedErrors()
protected void runSetup()
protected void runTeardown()
Copyright © 2001-2026 Robocode. All Rights Reserved.