Difference between revisions of "Robocode/Console Usage"

From Robowiki
Jump to navigation Jump to search
(Move documentation footer to a template)
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
This page describes how to run Robocode from a console.
+
This page describes how to run and use Robocode from a console.
  
 
== Starting Robocode ==
 
== Starting Robocode ==
Robocode is normally started by the robocode.bat (on Windows) or robocode.sh (on Linux and Mac OS) batch files. The batch files is used for setting required parameters for the Java VM in order to start and run Robocode properly.
+
Robocode is normally started by a batch file/shell script, depending on the OS:
 +
* <code>robocode.bat</code> on Windows
 +
* <code>robocode.sh</code> on Unix/Linux
 +
* <code>robocode.command</code> on macOS
  
Robocode is started from a console by writing:
+
The shell script is used for setting required parameters for the Java VM in order to start and run Robocode properly.
  
  java -Xmx512M -Dsun.io.useCanonCaches=false -cp libs/robocode.jar:libs/codesize.jar robocode.Robocode
+
By default, Robocode is started from a console by writing:
  
Here you must stand in the 'robocode' directory where Robocode is installed.
+
  java -Xmx512M -Dsun.io.useCanonCaches=false -cp libs/robocode.jar robocode.Robocode
 +
 
 +
Here you must stand in the 'robocode' directory where Robocode has been pre-installed.
  
* '''java''' is the command used for running the Java VM.
+
* <code>java</code> is the command used for running the Java VM, which is required for starting and running Robocode.
* '''-Xmx512M''' sets the ''maximum'' heap size the Java VM to 512 MB RAM.
+
* <code>-Xmx512M</code> sets the ''maximum'' heap size for the Java VM to 512 MB of heap memory, meaning that Robocode cannot use more than 512 MB of memory.
* '''-Dsun.io.useCanonCaches=false''' prevents SecurityExceptions to occur when running code outside of Robocode's secured sandbox.
+
* <code>-Dsun.io.useCanonCaches=false</code> is used to disable canonical cashing of file names, which would otherwise cause problems under Windows. With future versions of Robocode, this option is not necessary anymore, and will hence be obsolete at that time.
* '''-cp libs/robocode.jar;libs/codesize.jar''' specifies the required .jar files for running Robocode.
+
* <code>-cp libs/robocode.jar</code> tells the Java VM which library (jar file), which is used for starting up Robocode.
* '''robocode.Robocode''' specifies the main entry class of the Robocode game.
+
* <code>robocode.Robocode</code> specifies the main entry class of the Robocode game, which is required for starting Robocode.
  
 
With all of the above, Robocode will startup with a graphical user interface (GUI) waiting for user inputs.
 
With all of the above, Robocode will startup with a graphical user interface (GUI) waiting for user inputs.
But it is possible to change the way Robocode is started how it must run. That is, you can specify additional parameters to the command line that is used for running Robocode. These parameters are described in the following.
+
But it is possible to change the way Robocode is started and how it must run. That is, you can specify additional parameters to the command line above. These parameters are described in the following with the console usage.
  
 
== Console Usage ==
 
== Console Usage ==
   Usage: robocode [-cwd path] [-battle filename [-results filename] [-tps tps]
+
 
                  [-minimize] [-nodisplay] [-nosound]]
+
   Usage: robocode [-?] [-help] [-cwd path] [-battle filename [-results filename]
 +
                  [-record filename] [-recordXML filename] [-replay filename]
 +
                  [-tps tps] [-minimize] [-nodisplay] [-nosound]
 
    
 
    
 
   where options include:
 
   where options include:
      -cwd <path>             Change the current working directory
+
    -? or -help                Prints out the command line usage of Robocode
      -battle <battle file>   Run the battle specified in a battle file
+
    -cwd <path>               Change the current working directory
      -results <file>         Save results to the specified text file
+
    -battle <battle file>     Run the battle specified in a battle file
      -tps <tps>             Set the TPS (Turns Per Second) to use
+
    -results <results file>   Save results to the specified text file
      -minimize               Run minimized when Robocode starts
+
    -record <bin record file>  Record the battle into the specified file as binary
      -nodisplay             Run with the display / GUI disabled
+
 
      -nosound               Run with sound disabled
+
    -recordXML <xml rec file>  Record the battle into the specified file as XML
 +
    -replay <record file>      Replay the specified battle record
 +
    -tps <tps>                 Set the TPS > 0 (Turns Per Second)
 +
    -minimize                 Run minimized when Robocode starts
 +
    -nodisplay                 Run with the display / GUI disabled
 +
    -nosound                   Run with sound disabled
 
    
 
    
   properties include:
+
   Java Properties include:
      -DWORKINGDIRECTORY=<path>  Set the current working directory
+
    -DWORKINGDIRECTORY=<path>  Set the working directory
      -DNOSECURITY=true|false    Enable or disable Robocode's security manager
+
    -DROBOTPATH=<path>        Set the robots directory (default is 'robots')
      -Ddebug=true|false        Enable or disable System.err messages
+
    -DBATTLEPATH=<path>        Set the battles directory (default is 'battles')
 +
    -DNOSECURITY=true|false    Enable/disable Robocode's security manager
 +
    -Ddebug=true|false        Enable/disable debugging used for preventing
 +
                              robot timeouts and skipped turns, and allows an
 +
                              an unlimited painting buffer when debugging robots
 +
    -DEXPERIMENTAL=true|false  Enable/disable access to peer in robot interfaces
 +
    -DPARALLEL=true|false      Enable/disable parallel processing of robots turns
 +
    -DRANDOMSEED=<long number> Set seed for deterministic behavior of random
 +
                              numbers
  
=== Example 1 - Running a battle ===
+
=== Example: Running a battle ===
 
In this first example, Robocode is running the 'sample.battle' from the 'battles' directory without the display (GUI), and where the results are written out to the file named 'results.txt':
 
In this first example, Robocode is running the 'sample.battle' from the 'battles' directory without the display (GUI), and where the results are written out to the file named 'results.txt':
  
 
   java -Xmx512M -Dsun.io.useCanonCaches=false -cp libs/robocode.jar robocode.Robocode
 
   java -Xmx512M -Dsun.io.useCanonCaches=false -cp libs/robocode.jar robocode.Robocode
    -battle battles\sample.battle -nodisplay -results results.txt
+
      -battle battles\sample.battle -nodisplay -results results.txt
 
 
=== Example 2 - Disabling security ===
 
With this example the security manager is disabled, which allows a developer to let robots access files and classes from outside Robocode:
 
  
  java -Xmx512M -Dsun.io.useCanonCaches=false -cp libs/robocode.jar robocode.Robocode
+
=== Example: Disabling security ===
    -DNOSECURITY=true
+
With this example the Robocode security manager is disabled, which allows a developer to let robots access files and classes from outside Robocode:
  
This allows a robot developer to let a robot access 3<sup>rd</sup> party libraries with suport for e.g. neural networks and similar.
+
  java -Xmx512M -DNOSECURITY=true -Dsun.io.useCanonCaches=false
 +
      -cp libs/robocode.jar robocode.Robocode
  
== See also ==
+
This allows a robot developer to let a robot access 3<sup>rd</sup> party libraries with support for e.g. neural networks and similar. Note that disabling security with this option does not disable ''all'' security. The normal Java security mechanisms still apply. But most of the security mechanisms added by Robocode are disabled.
  
=== Robot API ===
+
=== Example: Running in Debug Mode ===
* [http://robocode.sourceforge.net/docs/robocode/ Robot API]
+
When trying to debug a robot by single stepping in an external IDE (e.g. Eclipse or NetBeans), it is important that the debug mode is enabled. Otherwise, the robot will receive skipped turns and by stopped by the game very quickly.
  
=== Tutorials ===
+
  java -Xmx512M -Ddebug=true -Dsun.io.useCanonCaches=false
* [[Robocode/System Requirements|System Requirements for Robocode]]
+
      -cp libs/robocode.jar robocode.Robocode
* [[Robocode/Download|How to download and install Robocode]]
 
* [[Robocode/Robot Anatomy|The anatomy of a robot]]
 
* [[Robocode/Getting Started|Getting started with Robocode]]
 
* [[Robocode/My First Robot|My First Robot Tutorial]]
 
* [[Robocode/Game Physics|Robocode Game Physics]]
 
* [[Robocode/Scoring|Scoring in Robocode]]
 
* [[Robocode/Robot Console|Using the robot console]]
 
* [[Robocode/Downloading_Robots|Downloading other robots]]
 
* [[Robocode/Learning from Robots|Learning from other robots]]
 
* [[Robocode/Package Robot|Package your robot]]
 
* [[Robocode/FAQ|Frequently Asked Questions (FAQ)]]
 
* [[Robocode/Articles|Articles about Robocode]]
 
* [[Robocode/Graphical_Debugging|Graphical debugging]]
 
* [[Robocode/Eclipse|Using Eclipse as IDE]]
 
* [[Robocode/Eclipse/Create_a_Project|Creating a project for your robots]]
 
* [[Robocode/Eclipse/Create_a_Robot|Creating a robot in Eclipse]]
 
* [[Robocode/Running from Eclipse|Running your robot from Eclipse]]
 
* [[Robocode/Eclipse/Debugging Robot|Debugging your robot with Eclipse]]
 
  
=== News and Releases ===
+
== See also ==
* [http://sourceforge.net/export/rss2_project.php?group_id=37202 RSS Feeds for the Robocode project]
 
* [http://sourceforge.net/project/showfiles.php?group_id=37202&package_id=29609 Robocode file releases]
 
  
=== Home pages ===
+
{{RobocodeDocsList}}
* [http://robocode.sourceforge.net/ Classic homepage]
 
* [http://sourceforge.net/projects/robocode Robocode project at SourceForge]
 
* [http://robocoderepository.com/ Robocode Repository]
 
* [[wikipedia:Robocode|Wikipediaentry for Robocode]]
 
  
 
[[Category:Robocode Documentation]]
 
[[Category:Robocode Documentation]]
 
[[Category:Tutorials]]
 
[[Category:Tutorials]]

Latest revision as of 22:55, 9 August 2017

This page describes how to run and use Robocode from a console.

Starting Robocode

Robocode is normally started by a batch file/shell script, depending on the OS:

  • robocode.bat on Windows
  • robocode.sh on Unix/Linux
  • robocode.command on macOS

The shell script is used for setting required parameters for the Java VM in order to start and run Robocode properly.

By default, Robocode is started from a console by writing:

 java -Xmx512M -Dsun.io.useCanonCaches=false -cp libs/robocode.jar robocode.Robocode

Here you must stand in the 'robocode' directory where Robocode has been pre-installed.

  • java is the command used for running the Java VM, which is required for starting and running Robocode.
  • -Xmx512M sets the maximum heap size for the Java VM to 512 MB of heap memory, meaning that Robocode cannot use more than 512 MB of memory.
  • -Dsun.io.useCanonCaches=false is used to disable canonical cashing of file names, which would otherwise cause problems under Windows. With future versions of Robocode, this option is not necessary anymore, and will hence be obsolete at that time.
  • -cp libs/robocode.jar tells the Java VM which library (jar file), which is used for starting up Robocode.
  • robocode.Robocode specifies the main entry class of the Robocode game, which is required for starting Robocode.

With all of the above, Robocode will startup with a graphical user interface (GUI) waiting for user inputs. But it is possible to change the way Robocode is started and how it must run. That is, you can specify additional parameters to the command line above. These parameters are described in the following with the console usage.

Console Usage

 Usage: robocode [-?] [-help] [-cwd path] [-battle filename [-results filename]
                 [-record filename] [-recordXML filename] [-replay filename]
                 [-tps tps] [-minimize] [-nodisplay] [-nosound]
 
 where options include:
   -? or -help                Prints out the command line usage of Robocode
   -cwd <path>                Change the current working directory
   -battle <battle file>      Run the battle specified in a battle file
   -results <results file>    Save results to the specified text file
   -record <bin record file>  Record the battle into the specified file as binary
 
   -recordXML <xml rec file>  Record the battle into the specified file as XML
   -replay <record file>      Replay the specified battle record
   -tps <tps>                 Set the TPS > 0 (Turns Per Second)
   -minimize                  Run minimized when Robocode starts
   -nodisplay                 Run with the display / GUI disabled
   -nosound                   Run with sound disabled
 
 Java Properties include:
   -DWORKINGDIRECTORY=<path>  Set the working directory
   -DROBOTPATH=<path>         Set the robots directory (default is 'robots')
   -DBATTLEPATH=<path>        Set the battles directory (default is 'battles')
   -DNOSECURITY=true|false    Enable/disable Robocode's security manager
   -Ddebug=true|false         Enable/disable debugging used for preventing
                              robot timeouts and skipped turns, and allows an
                              an unlimited painting buffer when debugging robots
   -DEXPERIMENTAL=true|false  Enable/disable access to peer in robot interfaces
   -DPARALLEL=true|false      Enable/disable parallel processing of robots turns
   -DRANDOMSEED=<long number> Set seed for deterministic behavior of random
                              numbers

Example: Running a battle

In this first example, Robocode is running the 'sample.battle' from the 'battles' directory without the display (GUI), and where the results are written out to the file named 'results.txt':

 java -Xmx512M -Dsun.io.useCanonCaches=false -cp libs/robocode.jar robocode.Robocode
      -battle battles\sample.battle -nodisplay -results results.txt

Example: Disabling security

With this example the Robocode security manager is disabled, which allows a developer to let robots access files and classes from outside Robocode:

 java -Xmx512M -DNOSECURITY=true -Dsun.io.useCanonCaches=false
      -cp libs/robocode.jar robocode.Robocode

This allows a robot developer to let a robot access 3rd party libraries with support for e.g. neural networks and similar. Note that disabling security with this option does not disable all security. The normal Java security mechanisms still apply. But most of the security mechanisms added by Robocode are disabled.

Example: Running in Debug Mode

When trying to debug a robot by single stepping in an external IDE (e.g. Eclipse or NetBeans), it is important that the debug mode is enabled. Otherwise, the robot will receive skipped turns and by stopped by the game very quickly.

 java -Xmx512M -Ddebug=true -Dsun.io.useCanonCaches=false
      -cp libs/robocode.jar robocode.Robocode

See also

Robocode API

Beginner Guides

External Editors

.NET Robots

Links