Downloads per day
Last 90 days · 79 total · peak 18
Dossier
What robocode does.
Provides a model interface for tank combat simulations in the style of Robocode.
From the crate: “Robot Combat Simulator”
- Codename
- The Tank Commander
- Role
- Tank combat model
- Character
- Blunt and strategic. Sees every arena as a grid of firing lines.
- Domain
- System
- Enlisted
- 8 October 2026
- Last release
- v0.7.0, 19 November 2026
- Keywords
simulator
Use cases
Put it to work.
- Write a tank-combat bot against a typed model of the arena.
Getting started
Call it in.
Add it to a Rust project, then follow the example. The full API is on docs.rs.
Install
cargo add robocode cargo install robocode
Example
use robocode::api::{Commands, HitWallEvent, Robot, ScannedRobotEvent, Status, relative_bearing};
use robocode::physics::{BattleConfig, SpawnSpec};
use robocode::robots::SittingDuck;
use robocode::runner::{Battle, boxed};
#[derive(Default)]
struct Hunter {
backward: bool,
}
impl Robot for Hunter {
fn name(&self) -> &str { "Hunter" }
fn run(&mut self, _status: &Status, cmd: &mut Commands) {
cmd.set_ahead(if self.backward { -100.0 } else { 100.0 });
cmd.set_turn_radar_right(45.0);
}
fn on_hit_wall(&mut self, _e: &HitWallEvent, _s: &Status, _cmd: &mut Commands) {
self.backward = !self.backward; // turn around at walls
}
fn on_scanned_robot(&mut self, e: &ScannedRobotEvent, s: &Status, cmd: &mut Commands) {
let aim = relative_bearing(e.absolute_bearing, s.gun_heading);
cmd.set_turn_gun_right(aim);
if aim.abs() < 3.0 { cmd.set_fire(1.0); }
}
}
fn main() {
let spawns = [SpawnSpec::new(0, 100.0, 100.0, 0.0), SpawnSpec::new(1, 700.0, 500.0, 0.0)];
let mut battle = Battle::new(BattleConfig::default(), &spawns,
vec![Box::new(Hunter::default()), boxed(SittingDuck)]);
let outcome = battle.run(5000);
println!("winner: {:?} after {} turns", outcome.winner.map(|i| battle.name(i)), outcome.turns);
}Build with a prompt
Add the Rust crate `robocode` (version 0.7.0) to this project with `cargo add robocode`. I want to use it for this: Provides a model interface for tank combat simulations in the style of Robocode. Before writing code, read its README at https://crates.io/crates/robocode and the API docs at https://docs.rs/robocode. Use only the functions, types and signatures that appear there; do not invent API names. Write a minimal working example and one test that runs it.
Paste this into Claude Code or another coding agent.
Specs
- Version
- 0.7.0
- License
- EPL-1.0
- Edition
- Rust 2024
- MSRV
- 1.85
- Size
- 5,480 lines of code, 81 of comments
- Package
- 118.0 KB compressed
- Dependencies
- vstd
- Used by
- 0 crates on crates.io
- Features
- verus
- Binaries
- parity
- Docs
- docs.rs, built
- Repository
- cryptopatrick/robocode · 0★ · 0 forks · 0 open issues · pushed 20 Nov 2026
Release history
| Version | Date | Downloads |
|---|---|---|
| 0.7.0 | 19 Nov 2026 | 10 |
| 0.6.0 | 18 Nov 2026 | 10 |
| 0.5.0 | 12 Nov 2026 | 12 |
| 0.4.0 | 12 Nov 2026 | 11 |
| 0.3.0 | 6 Nov 2026 | 11 |
| 0.2.0 | 5 Nov 2026 | 16 |
| 0.1.0 | 8 Oct 2026 | 9 |
Documentation
The manual.
The crate's README as published on crates.io. The full API reference is on docs.rs.
Read the README
robocode
Robot Combat Simulator: program a robot tank in Rust, battle it, and, if you like, prove it safe with Verus.
Overview
robocode is a Rust take on Robocode, the classic programming game where you write the brain of a robot tank and send it into an arena. It has:
- a deterministic battle engine that follows the original game's physics and rules;
- a Robot API modelled on Robocode's
AdvancedRobot; - RoboVerus: an optional
verusfeature and guide for learning formal verification with Verus by proving things about robots.
Key Features
- Robot API (
robocode::api): event handlers (on_scanned_robot,on_hit_by_bullet,on_hit_wall, …) plusset_ahead,set_turn_gun_right,set_fireand friends, in pixels and degrees. - Verifiable strategies (
robocode::strategy): robots written as a single fixed-pointdecide(&Observation) -> Action, the same code whether Verus proves it or a battle runs it. - Optional Verus support: with
--features verus, Verus checks the crate's specs. The sample robotSafeShooteris proved never to fire unless it has the energy, a cool gun and an aimed gun. Without the feature, no Verus crate is compiled. - Battles and recordings: run battles headless, and save turn-by-turn recordings for the browser viewer.
- Sample robots:
SafeShooter,Circler,Spinner,SittingDuck,Tactician. - Tactician and the maneuver library (
robocode::strategy::maneuver): Tactician picks a maneuver each turn by priority with hysteresis, uses Search/Patrol when no target is seen, and has stuck recovery and a wall guard. Each maneuver runs at a risk level (cautious, normal, aggressive), and the viewer shows it. - Radar blocked by buildings: on the urban map, a building between two robots hides one from the other, and the viewer draws the beam as it is blocked.
- Battlefield ratios: 4:3, 2:1, 16:9 or 1:1 at a height of 600, in the viewer and with
cargo robocode battle --ratio. - Five tanks: pick a Leopard 2A8, Abrams, K2, Leclerc or Merkava for each robot; the viewer draws them in 2D and 3D, with the team colour on the muzzle.
- No dependencies in the default build.
Bullet modes
Bullets fly in one of two modes. Realistic (the default) sends every bullet 300 px per turn whatever its power, and a bullet hits the first robot or building along its path. Arcade is Robocode's classic 20 - 3 * power. Power sets damage, gun heat, energy cost and hit bonus in both modes. Pick one with cargo robocode battle --bullets realistic|arcade, in the viewer's New battle, or in the library with BattleConfig { bullet_mode: BulletMode::Arcade, .. }. Recordings say which mode they used in the "bullets" header field; older recordings play as arcade. See docs/robot-api.md.
Architecture
| Module | What it does |
|---|---|
physics |
The f64 engine: movement, turning, gun heat, bullets, radar scans, collisions with walls |
api |
The Robot API: Robot trait, Status, events, Commands |
runner |
Runs battles between robots; boxed turns a Strategy into a robot |
strategy, units |
Fixed-point observations and actions for verifiable robots |
robots |
Sample robots |
recording, roster |
Battle recordings (format v2; v1 still opens) and the built-in robot list |
The engine uses f64 and follows the Java original. Verifiable strategies see the world in whole-number units (milli-energy, decidegrees, pixels), so the decide that Verus proves is exactly the code that fights. The runner converts between the two, rounding in the safe direction.
Quick Start
[dependencies]
robocode = "0.7"
use robocode::api::{Commands, HitWallEvent, Robot, ScannedRobotEvent, Status, relative_bearing};
use robocode::physics::{BattleConfig, SpawnSpec};
use robocode::robots::SittingDuck;
use robocode::runner::{Battle, boxed};
#[derive(Default)]
struct Hunter {
backward: bool,
}
impl Robot for Hunter {
fn name(&self) -> &str { "Hunter" }
fn run(&mut self, _status: &Status, cmd: &mut Commands) {
cmd.set_ahead(if self.backward { -100.0 } else { 100.0 });
cmd.set_turn_radar_right(45.0);
}
fn on_hit_wall(&mut self, _e: &HitWallEvent, _s: &Status, _cmd: &mut Commands) {
self.backward = !self.backward; // turn around at walls
}
fn on_scanned_robot(&mut self, e: &ScannedRobotEvent, s: &Status, cmd: &mut Commands) {
let aim = relative_bearing(e.absolute_bearing, s.gun_heading);
cmd.set_turn_gun_right(aim);
if aim.abs() < 3.0 { cmd.set_fire(1.0); }
}
}
fn main() {
let spawns = [SpawnSpec::new(0, 100.0, 100.0, 0.0), SpawnSpec::new(1, 700.0, 500.0, 0.0)];
let mut battle = Battle::new(BattleConfig::default(), &spawns,
vec![Box::new(Hunter::default()), boxed(SittingDuck)]);
let outcome = battle.run(5000);
println!("winner: {:?} after {} turns", outcome.winner.map(|i| battle.name(i)), outcome.turns);
}
Documentation
- API documentation
- Robot API guide, with a table mapping Java's
AdvancedRobotmethods to the Rust API cargo robocode: write a robot in one file, battle it, and watch it in your browser (installed from the repository for now)- Battle viewer: watch and replay battles in the browser
- RoboVerus guide: learn Verus by proving things about robots
- Verus integration: how the optional
verusfeature works - RoboCheck: verify a candidate strategy (such as AI-generated code) against a human-written Verus spec, then battle the same code
Examples
cargo run --example my_robot # a robot defined in the example file, vs SittingDuck
cargo run --example battle -- circler # SafeShooter vs Circler, Spinner or SittingDuck
Contributing
Contributions are welcome! Please see our contributing guidelines for details on:
- Code style and testing requirements
- Submitting bug reports and feature requests
- Development setup and workflow
License
This project is licensed under the Eclipse Public License v1.0 (EPL-1.0), the license of the original Robocode. See LICENSE for details.
Resources
Same unit
Other agents.
-
radarRealistic radar and sensor simulation for games and simulations: scanning, probabilistic detection, measurement noise, tracking and electronic warfare.
-
curfewA deadline-aware fork-join model where multiple tasks run in parallel, but only those that finish before a specified absolute clock time are joined and their results collected.
-
graph_mvccRust library for working with Multi-Version Concurrency Control in Graph Databases.
-
harelHarel Statecharts Parser.