← Back to RTS Arena

Bot Directory

All bots for RTS Arena. Built-in bots load automatically; you can also write your own.

Built-in Bots

Random Built-in
Makes random decisions each turn: random harvest count, random unit training, random attacks or defense. Useful as a baseline opponent.
Key strategies: Random harvest (1-3 workers) • 30% chance to build barracks • Random unit training • 40% chance to attack random enemy
Worker Rush Built-in
Masses workers and sends them to attack early. No barracks needed — overwhelms opponents who are slow to build military.
Key strategies: Minimal harvest (1 worker) • Mass worker training • All-in attack at turn 30 • Target enemy base
Light Rush Built-in
Builds barracks quickly and spams light units for an early rush. Attacks once 3 light units are ready. The default enemy opponent.
Key strategies: Fixed 2-worker harvest • Immediate barracks • Light unit spam (3 at a time) • Attack at army size 3
Heavy Rush Built-in
Builds barracks and trains heavy units. Attacks once 2 heavies are ready. Heavy units have high HP and damage but are slow.
Key strategies: Fixed 2-worker harvest • Immediate barracks • Heavy unit training • Attack at army size 2
Economy Boom Built-in
Prioritises economy: trains extra workers, harvests with 4, then builds a mixed army of heavy and light units. Attacks at army size 5 or turn 200.
Key strategies: Heavy economy (4 harvesters, 5 workers) • Late barracks • Mixed heavy + light army • Timing attack at turn 200
Turtle Built-in
Defensive strategy: harvests with 3 workers, masses ranged units, and only attacks after turn 250 with 6+ army units.
Key strategies: 3-worker harvest • Ranged unit mass (3 at a time) • Defend until turn 250 • Late push with 6+ army
Balanced Built-in
Builds a mixed army of light, ranged, and heavy units. Attacks when the army reaches 4 units and outnumbers the enemy. A solid all-round strategy.
Key strategies: Mixed army composition • Light + ranged balance • Heavy units when resources allow • Attack when outnumbering enemy

Community Bots

Mayari Advanced
Strategies adapted from the MicroRTS Mayari bot by barvazkrav, the 2021 MicroRTS AI Competition winner. Achieves 100% win rate against all built-in AIs and the MCTS bot in headless testing.
Key strategies: Adaptive harvester allocation • Heavy-unit priority with ranged fallback • Overpowering detection • Worker rush counter • Combat target scoring (barracks priority) • Mid-game timing attacks • Late-game pressure
MCTS Bot Intermediate
Demonstrates Monte Carlo Tree Search over the RTS command space. Uses UCB1 for tree navigation and lightweight heuristic rollouts across 200 iterations per decision to select from diverse strategic plans.
Key strategies: UCB1 tree selection • Heuristic simulation with noise for diversity • Counter-unit evaluation (ranged vs heavy, heavy vs light) • Resource efficiency scoring • Late-game attack pressure • Mixed army compositions
Example Bot Beginner
A minimal example showing the bot API. Implements a simple rush strategy: harvest with 2 workers, build barracks, train light units, and attack once the army reaches 4 units. Use this as a starting template for your own bot.
Key strategies: Fixed 2-worker harvest • Single barracks build • Light unit spam • Attack at army size 4 • Target enemy base

How to Load a Bot

All built-in and community bots load automatically when the page opens. To load an additional bot:

  1. Open RTS Arena
  2. In the Load Custom Bot section, paste a URL into the text field (e.g. https://example.com/my-bot.js) or use Load File to pick a local .js file
  3. Click Load URL
  4. The bot appears in both the Player and Enemy dropdowns — select it for either side
  5. Start a battle

Writing a New Bot

A bot is a single JavaScript file that registers a class with the RTS Arena API. Your class needs two methods:

Minimal Template

class MyBot {
    constructor(playerId) {
        this.playerId = playerId;
    }

    getCommands(gs) {
        const cmds = [];

        // Always harvest with 2 workers
        cmds.push({ type: 'harvest', count: 2 });

        // Build barracks if we don't have one
        const hasBarracks = gs.myUnits.some(u => u.isBuilding && u.type === 'barracks');
        if (!hasBarracks) {
            cmds.push({ type: 'build', buildingType: 'barracks' });
        }

        // Train heavy units
        if (hasBarracks) {
            cmds.push({ type: 'train', unitType: 'heavy', count: 2 });
        }

        // Attack when we have enough army
        const army = gs.myUnits.filter(u => !u.isBuilding && u.type !== 'worker');
        if (army.length >= 3 && gs.enemyUnits.length > 0) {
            const target = gs.enemyUnits[0];
            cmds.push({ type: 'attack', x: target.x, y: target.y });
        } else {
            cmds.push({ type: 'defend' });
        }

        return cmds;
    }
}

// Register your bot (this name appears in the dropdown)
RTSArena.registerBot('MyBot', MyBot);

Game State

The gameState object passed to getCommands() has this shape:

{
    turn:            Number,     // current tick (0-based)
    maxTurns:        Number,     // game ends at this tick (default 500)
    myResources:     Number,     // your gold
    enemyResources:  Number,     // opponent's gold
    myUnits:         Entity[],   // your units and buildings
    enemyUnits:      Entity[],   // opponent's units and buildings
    terrain:         Number[][],         // 2D grid: 0 = empty, 1 = resource
    resourceAmounts: Number[][],         // gold remaining at each resource tile
}

Each Entity has:

{
    id:         Number,
    type:       'base' | 'barracks' | 'worker' | 'light' | 'heavy' | 'ranged',
    playerId:   Number,      // 0 or 1
    x:          Number,
    y:          Number,
    hp:         Number,
    maxHp:      Number,
    isBuilding: Boolean,
    damage:     Number,
    range:      Number,
    speed:      Number,
}

Available Commands

CommandDescriptionCost
{ type: 'harvest', count: N } Assign N workers to gather resources Free
{ type: 'build', buildingType: 'barracks' } Build a barracks near your base 5 gold
{ type: 'train', unitType: '...', count: N } Train N units. Workers at base; others at barracks Per unit
{ type: 'attack', x: N, y: N } Send combat units toward target coordinates Free
{ type: 'defend' } Army holds position near your base Free
{ type: 'retreat' } All units fall back toward base Free

Unit and Building Stats

Accessible at runtime via RTSArena.UNIT_STATS and RTSArena.BUILDING_STATS:

UnitHPCostBuild TicksSpeedDamageRange
Worker114111
Light425221
Heavy838141
Ranged226113
BuildingHPCostBuild TicksProduces
Base101015Worker
Barracks5510Light, Heavy, Ranged

Tips for Strong Bots

Study the Mayari bot source code for a well-tested example of all these principles in action.

← Back to RTS Arena