Build the best — destroy the rest!
The TypeScript/JavaScript Bot API for Robocode Tank Royale — the next evolution of the classic Robocode programming game where you code virtual tanks (bots) to battle in a virtual arena.
Robocode is a programming game where your task is to code a bot (a virtual tank) that competes against other bots in a real-time battle arena. You are the programmer — the bot acts entirely on your code.
Tank Royale brings Robocode to the next level with:
Install the TypeScript/JavaScript Bot API using npm:
npm install @robocode.dev/tank-royale-bot-api
To install a specific version:
npm install @robocode.dev/tank-royale-bot-api@1.0.2
The ws package is required at runtime in a Node.js environment:
npm install ws
import { Bot, HitByBulletEvent, ScannedBotEvent } from "@robocode.dev/tank-royale-bot-api";
class MyFirstBot extends Bot {
static main() {
new MyFirstBot().start();
}
override run() {
while (this.isRunning()) {
this.forward(100);
this.turnGunRight(360);
this.back(100);
this.turnGunRight(360);
}
}
override onScannedBot(e: ScannedBotEvent) {
this.fire(1);
}
override onHitByBullet(e: HitByBulletEvent) {
const bearing = this.calcBearing(e.bullet.direction);
this.turnRight(90 - bearing);
}
}
MyFirstBot.main();
The bot reads its name, version, and authors from a MyFirstBot.json file placed alongside the source,
or from environment variables set by the Robocode booter.
npm install @robocode.dev/tank-royale-bot-apiThe TypeScript/JavaScript Bot API provides:
async/await in bot logicThe API closely mirrors the Java, .NET, and Python Bot APIs. Key classes and interfaces:
| Export | Description |
|---|---|
Bot |
Full bot with independent gun/radar movement |
BaseBot |
Low-level bot with event-driven control |
IBot |
Interface for Bot |
IBaseBot |
Interface for BaseBot |
Droid |
Marker interface for team droid bots |
BotInfo / BotInfoBuilder |
Bot metadata for handshake |
Constants |
Game constants (max speed, rates, etc.) |
GameSetup |
Arena and game configuration |
BotState |
Snapshot of bot state during a tick |
BulletState |
Snapshot of bullet state during a tick |
BotResults |
Final round/battle results |
Color / ColorUtil |
Color representation utilities |
IGraphics / SvgGraphics |
Graphics API for painting overlays |
DefaultEventPriority |
Default priorities for bot events |
EnvVars |
Environment variable names for configuration |
Bot code is written in a synchronous, sequential style — identical to the Java, C#, and Python Bot APIs.
There is no async/await in bot code:
// ✅ Correct — sequential, blocking
override run() {
while (this.isRunning()) {
this.forward(100); // blocks until bot has moved 100 units
this.turnRight(90); // blocks until turn is complete
this.fire(1);
}
}
// ❌ Wrong — do NOT use async/await in bot code
async run() {
await this.forward(100); // incorrect — forward() is not a Promise
}
How it works internally: The API uses a Worker thread (worker_threads in Node.js) with
SharedArrayBuffer + Atomics.wait() to provide true blocking. The WebSocket runs on the main thread;
bot logic runs on the worker thread. When a tick arrives, the main thread calls Atomics.notify() to
wake the bot, just like Java's notifyAll(). This means forward(100) genuinely blocks the bot thread —
no Promises, no callbacks, no generator yields.
The bot reads all settings from environment variables (matching the Java, .NET, and Python APIs):
Connection settings:
| Variable | Default | Description |
|---|---|---|
SERVER_URL |
ws://localhost:7654 |
WebSocket server URL |
SERVER_SECRET |
(none) | Secret for server authentication |
Bot identity (set by the booter; override manually for testing):
| Variable | Required | Description |
|---|---|---|
BOT_NAME |
✅ | Bot name |
BOT_VERSION |
✅ | Bot version string |
BOT_AUTHORS |
✅ | Comma-separated list of authors |
BOT_DESCRIPTION |
— | Short description |
BOT_HOMEPAGE |
— | Homepage URL |
BOT_COUNTRY_CODES |
— | Comma-separated ISO 3166-1 alpha-2 country codes |
BOT_GAME_TYPES |
— | Comma-separated supported game types |
BOT_PLATFORM |
— | Platform name (e.g. Node.js) |
BOT_PROG_LANG |
— | Programming language (e.g. TypeScript) |
BOT_INITIAL_POS |
— | Initial position override (x,y,direction) |
Set them before starting:
SERVER_URL=ws://localhost:7654 SERVER_SECRET=abc123 node MyFirstBot.js
The package ships both ESM and CommonJS outputs:
// ESM (recommended)
import { Bot } from "@robocode.dev/tank-royale-bot-api";
// CommonJS
const { Bot } = require("@robocode.dev/tank-royale-bot-api");
TypeScript declarations (.d.ts) are included for both formats.
Robocode Tank Royale runs on:
The TypeScript/JavaScript Bot API works with Node.js 22 (LTS) or higher on all supported platforms.
🚧 Work in Progress: The TypeScript/JavaScript Bot API is currently under active development. Features and APIs may change before the stable release.
Licensed under the Apache License 2.0
Copyright © 2022 Flemming N. Larsen
Ready to build the best tank and destroy the rest? Start coding your bot today! 🚀🎯