This project provides an implementation of a Robocode robot in Kotlin and some tooling around it.
Edit the gradle.properties
and change the robocodeHome
path to your local Robocode
directory.
You also need to change the path to your Robocode
directory in the KotoRoboTest.kt
file.
To see the robot in action simply run:
./gradlew startRobocode
This project uses gradle
as a build tool and provides some extra convenience tasks.
Most of the paths and stuff are configurable in the gradle.properties
Builds a Robocode
compatible jar
file which contains the KotoRobo
class and the KotoRobo.properties
file.
Does not compute the codesize though.
Copies the built jar
file into the specified Robocode
directory.
Uses the template \config\battles\testBattle.battle
, replaces the selectedRobots
with the configured robots and
copies the file into the Robocode
directory.
This task is executed after each gradle clean
and deletes the generated robot jar
and battle
files from the Robocode
directory.
Executes every task mentioned above and starts the real Robocode
battle using the generated testBattle.battle
.
Lay back and watch your robot fight.
The RobocodeTestEngine.kt
class configures the Robocode
engine for usage in automated tests.
It registers the robots under development and provides a simple way to start a battle and evaluate the TestBattleResult.kt
Example:
val testEngine = RobocodeTestEngine("YOUR_ROBOCODE_HOME")
val result = testEngine.startBattle("MyRobotUnderTest", "sample.SittingDuck")
assertThat(result.winnerName).isEqualTo("MyRobotUnderTest")
assertThat(result.roboUnderTestStatistics.accuracy()).isEqualTo(100)
assertThat(result.roboUnderTestResult.firsts).isEqualTo(result.battleSpec.numRounds).`as` { "roboUnderTest should win every round" }
The robot can use HEAD-ON and LINEAR targeting and chooses the most successful one for each target.
It tracks every of its bullets and stores the accuracy data between rounds
It moves in a combination of risk-based and anti-gravity movement, where it always tries to move away from its current position while keeping a 90° angle to opponents.
Not much so far. It just stops firing if its energy is 1 or less.
This project is inspired by these awesome robocode projects: