Robocode Documentation

repository·main·Indexed 21 days ago

https://github.com/robo-code/robocode

An educational programming game where users design and program virtual battle tanks to compete in a simulated combat environment. Primarily supporting Java and Kotlin, Robocode is used to teach programming skills, algorithmic thinking, and AI. The documentation covers environment configuration (Java 8-23), the Robot, Robot Interfaces, and Control APIs, and guidance for using external IDEs like IntelliJ IDEA, Eclipse, NetBeans, and VS Code.

Tokens
14.3K
Snippets
48
Records
116
Agent score
72%

What's inside Robocode

  1. Overview of Robocode

    main

    Robocode is an educational programming game where users code, test, and improve virtual battle tanks. The platform is designed to teach programming skills, algorithmic thinking, and problem-solving through robot combat.

    Key Features:

    • Programming Languages: Primarily supports Java and Kotlin.
    • Robot Creation: Design and program virtual tanks to compete in battles.
    • Skill Development: Focuses on improving coding proficiency and algorithmic strategies.
  2. What is Robocode Tank Royale?

    main

    Robocode Tank Royale is the next-generation version of the Robocode platform featuring a modernized architecture. Unlike the original Robocode, Tank Royale expands language support to include:

    • Java
    • Kotlin
    • Python
    • C#

    Note: As of the current version, Tank Royale does not yet support LiteRumble for competitive rankings.

  3. Security restrictions on Event Dispatch Thread (EDT) access

    main
    Robocode enforces strict security boundaries. Robots that attempt to access the Event Dispatch Thread (EDT) will be disabled. This is a security measure to prevent robots from executing unauthorized code through the UI thread.
  4. Manage robot files and the robotcache

    main

    Robocode uses a robots directory to manage robot files. When you place a robot .jar file in this directory, Robocode automatically extracts its contents into a folder named robotcache.

    • Unique Identification: The filename of the .jar serves as the unique key for the robotcache.
    • Caution: Do not edit files directly inside the robotcache as they may be overwritten. If you need to modify extracted files, copy them from the robotcache back to your robots directory first.
  5. Avoid taking actions inside Condition.test()

    main
    When implementing custom events in an AdvancedRobot, you must not attempt to take any robot actions (like moving or firing) inside the Condition.test() method. If you need to respond to a condition being met, you should instead handle the logic within the onCustomEvent method to avoid robocode.exception.RobotException.
  6. Understand event processing order and priority

    main

    Robocode processes events in the following manner:

    1. Chronological Order: Events in the robot event queue are sorted chronologically. Events that occurred earlier are processed before newer events.
    2. Priority within Timeframes: If multiple events occur within the same time frame, they are sorted by priority. Higher priority events are processed before lower priority events.
    3. DeathEvent Priority: The DeathEvent has a priority of -1 (the lowest possible priority). This ensures that a robot processes all other pending events in its queue before it finally dies.
  7. How to create a Droid

    main

    A Droid is a specialized robot that lacks radar and scanning abilities. Droids are useful for specific tactical roles and start with 120 energy due to the weight savings from not having a radar.

    To create a droid, simply add implements Droid to your TeamRobot class.

    Important Notes:

    • The API remains unchanged, but scanning functionality will not work.
    • Droids do not show up in the 'New Battle' dialog by default (this can be changed in Options -> Preferences).

    For an implementation reference, see sampleteam.MyFirstDroid.

    // Example pattern for creating a droid
    public class MyDroid extends TeamRobot implements Droid {
        // Scanning will not work in this robot
    }
  8. Manage Event Priorities in AdvancedRobot

    main

    In the Robocode API, you can manage the execution order of events using setEventPriority. Note the following default priority values and behaviors:

    • BulletHitBulletEvent: Default priority is 55.
    • MessageEvent: Default priority is 75.
    • CustomEvent: Default priority is 80.
    • BulletHitEvents: Default priority is 50.

    To interact with message events specifically, use the getMessageEvents() method available in the TeamRobot class.

  9. Handle HitRobotEvent for damage detection

    main

    The HitRobotEvent is triggered when a robot receives damage.

    Note on Collisions: To prevent redundant events, HitRobotEvents are only sent when actual damage is dealt. If a collision occurs between a moving robot and a stationary robot where no damage is inflicted, no HitRobotEvent will be sent.

  10. Control battle speed with the TPS slider

    main

    The Turns Per Second (TPS) slider controls the speed of the battle:

    • 0 TPS: The game is paused.
    • 1-30 TPS: Slow speed.
    • 30-120 TPS: Higher speed.
    • 120-1000 TPS: Fast speed.
    • Max TPS: The game runs as fast as possible.

    When the TPS is set to 0, the Pause/Resume button enters a paused mode. Pressing the Pause/Resume button while at 0 TPS will resume the game at 1 TPS.