← 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
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
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
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
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
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
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
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
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
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
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:
- Open RTS Arena
- 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
- Click Load URL
- The bot appears in both the Player and Enemy dropdowns — select it for either side
- 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:
constructor(playerId) — called once when the game starts. playerId is 0 (blue/top) or 1 (red/bottom).
getCommands(gameState) — called every consultation interval (~20 ticks). Return an array of command objects.
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
| Command | Description | Cost |
{ 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:
| Unit | HP | Cost | Build Ticks | Speed | Damage | Range |
| Worker | 1 | 1 | 4 | 1 | 1 | 1 |
| Light | 4 | 2 | 5 | 2 | 2 | 1 |
| Heavy | 8 | 3 | 8 | 1 | 4 | 1 |
| Ranged | 2 | 2 | 6 | 1 | 1 | 3 |
| Building | HP | Cost | Build Ticks | Produces |
| Base | 10 | 10 | 15 | Worker |
| Barracks | 5 | 5 | 10 | Light, Heavy, Ranged |
Tips for Strong Bots
- Economy first. Train a 3rd worker early. You need steady income to fund barracks and military units.
- Build barracks ASAP. Barracks cost 5 gold. The sooner you start producing military, the sooner you can attack.
- Counter-pick units. Ranged counters Heavy (fires from distance). Heavy crushes Light (high HP, high damage). Light is cheap and fast for early pressure.
- Detect rushes. If the enemy has many workers and no barracks, they may be worker-rushing. Counter by mass-producing workers and fighting back.
- Don't turtle too long. Games have a 500-turn limit. If you only defend, you'll draw or lose on HP at timeout.
- Attack when ahead. Track your army's total damage vs the enemy's. When you overpower them, push immediately.
- Target buildings. Destroying the enemy barracks cuts off their production. Destroying their base wins the game.
← Back to RTS Arena