npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@robocode.dev/tank-royale-bot-api

v0.42.0-1

Published

Tank Royale Bot API for TypeScript/JavaScript

Readme

Robocode Tank Royale — TypeScript/JavaScript Bot API

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.

About Robocode Tank Royale

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:

  • Network-based battles via WebSocket connections
  • Multiple programming languages and platforms
  • Real-time battles with multiple bots

Installation

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/[email protected]

The ws package is required at runtime in a Node.js environment:

npm install ws

Requirements

  • Node.js 22 (LTS) or higher
  • TypeScript 5+ (for writing bots in TypeScript)

Quick Start

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.

Getting Started

  1. Install the package: npm install @robocode.dev/tank-royale-bot-api
  2. Download Robocode Tank Royale: Get the game GUI and server from the official releases
  3. Create your bot: Follow the TypeScript tutorial or copy the MyFirstBot sample
  4. Run battles: Start the GUI, add your bot process, and watch the fight

Features

The TypeScript/JavaScript Bot API provides:

  • Full Bot Control: Move your tank, rotate gun and radar, fire bullets
  • Event Handling: Respond to hits, bot scanned, bullet impacts, and more
  • Battle Information: Access to battle state, opponent positions, and game rules
  • Synchronous API: Sequential, blocking style — no async/await in bot logic
  • Dual Module Formats: Ships both ESM and CommonJS outputs with TypeScript declarations
  • Debugging Support: Built-in debugging and logging capabilities

API Overview

The 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 |

Synchronous API Model

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.

Configuration via Environment Variables

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

Module Formats

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.

Documentation & Resources

  • 📖 Official Documentation: robocode-dev.github.io/tank-royale
  • TypeScript API Reference: https://robocode-dev.github.io/tank-royale/api/typescript/
  • Getting Started: https://robocode-dev.github.io/tank-royale/tutorial/getting-started.html
  • 🤖 My First Bot (TypeScript): https://robocode-dev.github.io/tank-royale/tutorial/typescript/my-first-bot-for-typescript
  • Sample Bots: https://github.com/robocode-dev/tank-royale/tree/main/sample-bots/typescript
  • Source Code: https://github.com/robocode-dev/tank-royale/tree/main/bot-api/typescript

Supported Platforms

Robocode Tank Royale runs on:

  • Windows
  • macOS
  • Linux

The TypeScript/JavaScript Bot API works with Node.js 22 (LTS) or higher on all supported platforms.

Community & Support

Development Status

🚧 Work in Progress: The TypeScript/JavaScript Bot API is currently under active development. Features and APIs may change before the stable release.

License

Licensed under the Apache License 2.0

Copyright

Copyright © 2022 Flemming N. Larsen


Ready to build the best tank and destroy the rest? Start coding your bot today! 🚀🎯