Package robocode.control
Class RobocodeEngine
java.lang.Object
robocode.control.RobocodeEngine
- All Implemented Interfaces:
IRobocodeEngine
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.
This class in the main entry class of the robocode.control
package.
The RobocodeEngine is used by e.g. RoboRumble@Home client, which is integrated in Robocode. In addition, the RobocodeEngine is also used by the test units for testing the Robocode application itself.
- Author:
- Mathew A. Nelson (original), Flemming N. Larsen (contributor), Robert D. Maupin (contributor), Nathaniel Troutman (contributor), Joachim Hofer (contributor), Pavel Savara (contributor)
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new RobocodeEngine for controlling Robocode.RobocodeEngine
(File robocodeHome) Creates a new RobocodeEngine for controlling Robocode.RobocodeEngine
(File robocodeHome, RobocodeListener listener) Deprecated.Since 1.6.2.RobocodeEngine
(IBattleListener listener) RobocodeEngine
(RobocodeListener listener) Deprecated.Since 1.6.2. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Aborts the current battle if it is running.void
addBattleListener
(IBattleListener listener) Adds a battle listener that must receive events occurring in battles.void
close()
Closes the RobocodeEngine and releases any allocated resources it holds.protected void
finalize()
static File
Returns the current working directory.Returns all robots available from the local robot repository of Robocode.getLocalRepository
(String selectedRobots) Returns a selection of robots available from the local robot repository of Robocode.static File
Returns the directory containing the robots.Returns the installed version of Robocode controlled by this RobocodeEngine.static void
Prints out all running threads to standard system out.void
removeBattleListener
(IBattleListener listener) Removes a battle listener that has previously been added to this object.void
runBattle
(BattleSpecification battleSpecification) Runs the specified battle.void
runBattle
(BattleSpecification battleSpecification, boolean waitTillOver) Runs the specified battle.void
runBattle
(BattleSpecification battleSpecification, String initialPositions, boolean waitTillOver) Runs the specified battle.static void
setLogErrorsEnabled
(boolean enable) Enables or disables errors logged toSystem.err
.static void
setLogMessagesEnabled
(boolean enable) Enables or disables messages and warnings logged toSystem.out
.void
setVisible
(boolean visible) Shows or hides the Robocode window.void
Will block caller until current battle is over.
-
Constructor Details
-
RobocodeEngine
public RobocodeEngine()Creates a new RobocodeEngine for controlling Robocode. In order for this constructor to work, the current working directory must be the home directory directory of Robocode, e.g. C:\Robocode- Since:
- 1.6.2
- See Also:
-
RobocodeEngine
Creates a new RobocodeEngine for controlling Robocode.- Parameters:
robocodeHome
- the home directory of Robocode, e.g. C:\Robocode.- Since:
- 1.6.2
- See Also:
-
RobocodeEngine
Deprecated.Since 1.6.2. UseRobocodeEngine(File)
andaddBattleListener()
instead.Creates a new RobocodeEngine for controlling Robocode.
- Parameters:
robocodeHome
- the root directory of Robocode, e.g. C:\Robocode.listener
- the listener that must receive the callbacks from this RobocodeEngine.- See Also:
-
RobocodeEngine
Deprecated.Since 1.6.2. UseRobocodeEngine()
andaddBattleListener()
instead.Creates a new RobocodeEngine for controlling Robocode. The JAR file of Robocode is used to determine the root directory of Robocode.
- Parameters:
listener
- the listener that must receive the callbacks from this RobocodeEngine.- See Also:
-
RobocodeEngine
-
-
Method Details
-
finalize
-
addBattleListener
Adds a battle listener that must receive events occurring in battles.- Specified by:
addBattleListener
in interfaceIRobocodeEngine
- Parameters:
listener
- the battle listener that must retrieve the event from the battles.- See Also:
-
removeBattleListener
Removes a battle listener that has previously been added to this object.- Specified by:
removeBattleListener
in interfaceIRobocodeEngine
- Parameters:
listener
- the battle listener that must be removed.- See Also:
-
close
public void close()Closes the RobocodeEngine and releases any allocated resources it holds. You should call this when you have finished using the RobocodeEngine. This method automatically disposes the Robocode window if it open.- Specified by:
close
in interfaceIRobocodeEngine
-
getVersion
Returns the installed version of Robocode controlled by this RobocodeEngine.- Specified by:
getVersion
in interfaceIRobocodeEngine
- Returns:
- the installed version of Robocode controlled by this RobocodeEngine.
-
getCurrentWorkingDir
Returns the current working directory.- Returns:
- a File for the current working directory.
- Since:
- 1.7.1
-
getRobotsDir
Returns the directory containing the robots.- Returns:
- a File for the robot directory containing all robots.
- Since:
- 1.7.1
-
setVisible
public void setVisible(boolean visible) Shows or hides the Robocode window.- Specified by:
setVisible
in interfaceIRobocodeEngine
- Parameters:
visible
-true
if the Robocode window must be set visible;false
otherwise.
-
getLocalRepository
Returns all robots available from the local robot repository of Robocode. These robots must exists in the /robocode/robots directory, and must be compiled in advance, before these robot are returned with this method.- Specified by:
getLocalRepository
in interfaceIRobocodeEngine
- Returns:
- an array of all available robots from the local robot repository.
- See Also:
-
getLocalRepository
Returns a selection of robots available from the local robot repository of Robocode. These robots must exists in the /robocode/robots directory, and must be compiled in advance, before these robot are returned with this method.Notice: If a specified robot cannot be found in the repository, it will not be returned in the array of robots returned by this method.
- Specified by:
getLocalRepository
in interfaceIRobocodeEngine
- Parameters:
selectedRobots
- a comma or space separated list of robots to return. The full class name must be used for specifying the individual robot, e.g. "sample.Corners, sample.Crazy".- Returns:
- an array containing the available robots from the local robot
repository based on the selected robots specified with the
selectedRobotList
parameter. - See Also:
-
runBattle
Runs the specified battle.- Specified by:
runBattle
in interfaceIRobocodeEngine
- Parameters:
battleSpecification
- the specification of the battle to run including the participation robots.- See Also:
-
runBattle
Runs the specified battle.- Specified by:
runBattle
in interfaceIRobocodeEngine
- Parameters:
battleSpecification
- the specification of the battle to run including the participating robots.waitTillOver
- will block caller till end of battle if set- See Also:
-
runBattle
public void runBattle(BattleSpecification battleSpecification, String initialPositions, boolean waitTillOver) Runs the specified battle.- Specified by:
runBattle
in interfaceIRobocodeEngine
- Parameters:
battleSpecification
- the specification of the battle to run including the participating robots.initialPositions
- a comma or space separated list like: x1,y1,heading1, x2,y2,heading2, which are the coordinates and heading of robot #1 and #2. So e.g. 0,0,180, 50,80,270 means that robot #1 has position (0,0) and heading 180, and robot #2 has position (50,80) and heading 270.waitTillOver
- will block caller till end of battle if set- See Also:
-
waitTillBattleOver
public void waitTillBattleOver()Will block caller until current battle is over.- Specified by:
waitTillBattleOver
in interfaceIRobocodeEngine
- See Also:
-
abortCurrentBattle
public void abortCurrentBattle()Aborts the current battle if it is running.- Specified by:
abortCurrentBattle
in interfaceIRobocodeEngine
- See Also:
-
printRunningThreads
public static void printRunningThreads()Prints out all running threads to standard system out.- Since:
- 1.6.2
-
setLogMessagesEnabled
public static void setLogMessagesEnabled(boolean enable) Enables or disables messages and warnings logged toSystem.out
.- Parameters:
enable
- true if log messages must be enabled; false if log messages must be disabled.- Since:
- 1.8.0.0
- See Also:
-
setLogErrorsEnabled
public static void setLogErrorsEnabled(boolean enable) Enables or disables errors logged toSystem.err
.- Parameters:
enable
- true if log errors must be enabled; false if log errors must be disabled.- Since:
- 1.8.0.0
- See Also:
-