### robocode.control

# Class RobocodeEngine

- `java.lang.Object`
- - `robocode.control.RobocodeEngine`

`public class RobocodeEngine`
`extends Object`

The RobocodeEngine is the old 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 class of the `robocode.control` package, and the reason for having this control package. The RobocodeEngine is used by RoboRumble@Home, which is integrated in Robocode, but also RoboLeague and RobocodeJGAP. In addition, the RobocodeEngine is also used by the test units for testing the Robocode application itself.

Authors:
  Mathew A. Nelson (original)
  Flemming N. Larsen (contributor)
  Robert D. Maupin (contributor)
  Nathaniel Troutman (contributor)
  Joachim Hofer (contributor)
  Pavel Savara (contributor)

  ## Constructor Summary

  `RobocodeEngine()`
    Creates a new RobocodeEngine for controlling Robocode.

  `RobocodeEngine(File robocodeHome)`
    Creates a new RobocodeEngine for controlling Robocode.

  ## Method Summary

  `void`

  `abortCurrentBattle()`
    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.

  `RobotSpecification[]`

  `getLocalRepository()`
    Returns all robots available from the local robot repository of Robocode.

  `RobotSpecification[]`

  `getLocalRepository(String selectedRobotList)`
    Returns a selection of robots available from the local robot repository of Robocode.

  `String`

  `getVersion()`
    Returns the installed version of Robocode.

  `static void`

  `printRunningThreads()`
    Print 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`

  `setVisible(boolean visible)`
    Shows or hides the Robocode window.

  `protected @Override`

  `void finalize()`

  `void`

  `waitTillBattleOver()`
    Will block caller until current battle is over

## Constructor Details

### RobocodeEngine

    public RobocodeEngine()

> Creates a new RobocodeEngine for controlling Robocode. The JAR file of Robocode is used to determine the root directory of Robocode.
> Since:
>   1.6.2
> See Also:
>   `RobocodeEngine(File)`, `close()`

### RobocodeEngine

    public RobocodeEngine(File robocodeHome)

> Creates a new RobocodeEngine for controlling Robocode.
> Parameters:
>   `robocodeHome` - the root directory of Robocode, e.g. C:\Robocode.
> Since:
>   1.6.2
> See Also:
>   `RobocodeEngine()`, `close()`

## Method Details

### abortCurrentBattle

    public void abortCurrentBattle()

> Aborts the current battle if it is running.
> See Also:
>   `runBattle(BattleSpecification)`, `RobocodeListener.battleAborted(BattleSpecification)`

### addBattleListener

    public void addBattleListener(IBattleListener listener)

> Adds a battle listener that must receive events occurring in battles.
> Parameters:
>   `listener` - the battle listener that must retrieve the event from the battles.
> Since:
>   1.6.2
> See Also:
>   `removeBattleListener(IBattleListener)`

### close

    public void close()

> Closes the RobocodeEngine and releases any allocated resources. You should call this when you have finished using the RobocodeEngine. This method automatically disposes the Robocode window if it open.

### getLocalRepository

    public RobotSpecification[] 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.
> Returns:
>   an array of all available robots from the local robot repository.
> See Also:
>   `RobotSpecification`, `getLocalRepository(String)`

### getLocalRepository

    public RobotSpecification[] getLocalRepository(String selectedRobotList)

> 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. 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.
> Parameters:
>   `selectedRobotList` - 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.
> Since:
>   1.6.2
> See Also:
>   `RobotSpecification`, `getLocalRepository()`

### getVersion

    public String getVersion()

> Returns the installed version of Robocode.
> Returns:
>   the installed version of Robocode.

### printRunningThreads

    public static void printRunningThreads()

> Print out all running threads to standard system out.
> Since:
>   1.6.2

### removeBattleListener

    public void removeBattleListener(IBattleListener listener)

> Removes a battle listener that has previously been added to this object.
> Parameters:
>   `listener` - the battle listener that must be removed.
> Since:
>   1.6.2
> See Also:
>   `addBattleListener(IBattleListener)`

### runBattle

    public void runBattle(BattleSpecification battleSpecification)

> Runs the specified battle.
> Parameters:
>   `battleSpecification` - the specification of the battle to play including the participation robots.
> See Also:
>   `runBattle(BattleSpecification,boolean)`, `RobocodeListener.battleComplete(BattleSpecification, RobotResults[])`, `RobocodeListener.battleMessage(String)`, `BattleSpecification`, `getLocalRepository()`

### runBattle

    public void runBattle(BattleSpecification battleSpecification,
                          boolean waitTillOver)

> Runs the specified battle.
> Parameters:
>   `battleSpecification` - the specification of the battle to run including the participating robots.
>   `waitTillOver` - will block caller till end of battle if set
> Since:
>   1.6.2
> See Also:
>   `runBattle(BattleSpecification)`, `RobocodeListener.battleComplete(BattleSpecification, RobotResults[])`, `RobocodeListener.battleMessage(String)`, `BattleSpecification`, `getLocalRepository()`

### setVisible

    public void setVisible(boolean visible)

> Shows or hides the Robocode window.
> Parameters:
>   `visible` - `true` if the Robocode window must be set visible; `false` otherwise.

### void finalize

    protected @Override void finalize()
                throws Throwable

### waitTillBattleOver

    public void waitTillBattleOver()

> Will block caller until current battle is over
> Since:
>   1.6.2
> See Also:
>   `runBattle(BattleSpecification)`, `runBattle(BattleSpecification,boolean)`