How to Build a Tank Bot on battle.training
Home > Tutorials > How to Build a Tank Bot on battle.training
Archive
- Install Apache, MySQL, PHP and phpMyAdmin on Archlinux 2021
- Configure an Apache Virtual Host Server on ArchLinux Jun 12, 2021
- How to Hunt Bug Bounties with Agentic-Bug-Hunter Nov 18, 2026
- How to Deploy a Static Blog to GitHub Pages Nov 17, 2026
- How to Sign Up for make.fun with an Agent and Let the Agent Find Bounties on Its Own Nov 17, 2026
- How to Install Google Analytics 4 and Tag Manager on a Static Blog Nov 26, 2026
- How to Optimize SEO for a GitHub Pages Blog Nov 26, 2026
- How to Join make.fun Bounties with an AI Agent Nov 26, 2026
- How to Build a Tank Bot on battle.training Nov 26, 2026
- How to Make a Bootable Ventoy USB Nov 26, 2026
- How to Mint Free NFTs on BSC Safely Nov 30, 2026
- How to Make Automated Story YouTube Shorts (Stickman + TTS) Nov 30, 2026
battle.training is an online arena where tank bots fight each other — and you program the bot. You write a controller: a small program that commands your tank squad — when to advance, when to dodge, and when to shoot. Once the bot is activated, it fights on its own in the ladder and cups without you having to play it. This tutorial covers the whole flow, from the start until your bot is fighting, and it's all free.
Figure 1: The tank bot workflow — from signing up to the bot fighting in the arena.
What Is battle.training
On battle.training, two tank squads fight in a tactical simulation. Each match runs for up to 4 minutes: the arena calls your controller 20 times per second, and each call (called a tick) has the controller decide orders for every unit — advance, turn, aim the turret, fire.
There are two ways to win: wipe out the entire enemy squad, or collect more objective points when time runs out. The arena has objective points that award points every second while held alone; an APC inside a held objective doubles the points.
The controller is written in JavaScript and runs on an isolated QuickJS engine — no internet and no file access. So what fights is purely your logic.
Tip: An active bot doesn't need to be played — it fights automatically whenever a ladder or cup match is scheduled.
Sign Up and Get an API Key
Open battle.training and create an account. Once you're in, create your first bot — give it a memorable name, because that's the name shown on the ladder.
When the bot is created, you will receive an API key. This API key is used for all commands to the server: uploading a controller, requesting a scrimmage, and checking the bot's status. Keep it somewhere safe, for example a password manager.
Warning: NEVER share your API key with anyone, and never put it in a public repository or in code you share. Anyone holding that key can control your bot.
In this tutorial, every example that needs an API key uses the placeholder
<api-key-kamu>. Replace it with your own key when running the command.
Anatomy of a Tank Controller
One controller is a single JavaScript object with three functions:
draft, hello, and tick.
globalThis.controller = {
draft(h) { /* pilih regu */ },
hello(h) { /* sekali, setelah draft */ },
tick(o) { /* tiap tick, kembalikan perintah */ },
};
draft(h) { /* pilih regu */ },
hello(h) { /* sekali, setelah draft */ },
tick(o) { /* tiap tick, kembalikan perintah */ },
};
draft(h) picks your squad: 3 to 5 units with a maximum total cost of 12 points. Available unit types: scout (2), mbt (4), artillery (4), drone (2), missile (4), engineer (3), apc (3). If you don't write draft, the default squad is used: scout, MBT, and artillery.
hello(h) is called once after the draft, with the full rules, the map, and the finished squad. Use this time for map analysis — distance to objectives, high-ground positions, and crossing routes — because here you have the most time to spare.
tick(o) is called 20 times per second. You receive the observation o: your units, visible enemies (contacts), artillery shells incoming toward you (incoming), the score, and objective status. Reply with orders for each unit: throttle (gas), steer (turn), turret or aimAt (turret aim), and fire (shoot). All numbers must be integers.
Figure 2: The arena from above — your tank moves toward the objective while aiming its turret at the enemy.
Points flow every second from objectives you hold alone. Objectives on the arena's flanks are usually worth 2–3 points per second, while the central hill is worth 1. An APC inside a held objective multiplies its points. When time runs out, the winner is the one with more points — then, if tied, the one with the larger total HP.
Tip: Don't hard-code numbers like weapon range or unit cost — read them all from
h.rules. The rules can change between seasons, and code that reads h.rules keeps working.
Write Your First Controller
Below is the simplest controller skeleton. This bot shoots the first visible enemy, and advances when no enemy is visible. This is not a bot that will win a lot — but it's enough to understand the shape of a controller and the test flow.
globalThis.controller = {
draft(h) {
// Pilih regu: 3-5 unit, total biaya maksimal 12
return ["mbt", "mbt", "scout", "scout"];
},
hello(h) {
// Dipanggil sekali: simpan peta dan objektif kalau perlu
},
tick(o) {
const orders = [];
for (const u of o.units) {
if (!u.alive) continue;
const target = o.contacts[0];
if (target) {
orders.push({ id: u.id, aimAt: [target.x, target.y], fire: true });
} else {
// Tidak ada musuh terlihat: maju
orders.push({ id: u.id, throttle: 65536 });
}
}
return { units: orders };
},
};
draft(h) {
// Pilih regu: 3-5 unit, total biaya maksimal 12
return ["mbt", "mbt", "scout", "scout"];
},
hello(h) {
// Dipanggil sekali: simpan peta dan objektif kalau perlu
},
tick(o) {
const orders = [];
for (const u of o.units) {
if (!u.alive) continue;
const target = o.contacts[0];
if (target) {
orders.push({ id: u.id, aimAt: [target.x, target.y], fire: true });
} else {
// Tidak ada musuh terlihat: maju
orders.push({ id: u.id, throttle: 65536 });
}
}
return { units: orders };
},
};
Save that file as
controller.js. Note two things: aimAt uses the same coordinates as those in o.contacts, so you can use target.x and target.y directly; and fire: true fires in the turret's direction once the weapon has reloaded.
Tip: Start with the default squad (scout, MBT, artillery) if you're not sure about the draft yet. A simple squad is easier to test than a complicated one.
Test and Activate Your Bot
Don't activate a controller before testing it. First download the arena engine and the test tool:
curl -O https://api.battle.training/sdk/arena-sim.mjs
curl -O https://api.battle.training/sdk/local-test.mjs
curl -O https://api.battle.training/sdk/local-test.mjs
Then run the test against all four house bots:
node local-test.mjs controller.js --seeds 20 --vs brawler,holder,random,hunter
That command plays your controller against brawler, holder, random, and hunter on 20 different seeds, from both sides of the arena. Watch the tick errors column: a version with tick errors fails — fix them until it's zero.
If you want to fight a real opponent without changing your rating, request a scrimmage:
curl -X POST https://api.battle.training/api/scrimmage \
-H "Authorization: Bearer <api-key-kamu>" \
-H "content-type: application/json" \
-d '{"bot": "nama-bot-kamu", "vs": "house:hunter", "seed": 12345}'
-H "Authorization: Bearer <api-key-kamu>" \
-H "content-type: application/json" \
-d '{"bot": "nama-bot-kamu", "vs": "house:hunter", "seed": 12345}'
Scrimmages are limited to 60 per day per account and don't affect rating. Use different seeds so your bot isn't only good on one map.
Once the test results are satisfying, upload that controller to your bot via the battle.training site and activate the version. From then on the bot fights automatically on the ladder — you just monitor the results and repeat the cycle: change the controller, test again, activate again.
Tip: Keep the controller light — the arena gives about 10 milliseconds per tick. Move heavy map analysis into
hello(), and don't scan the whole map on every tick.
Join Cups and Climb the Ladder
An active bot automatically enters the ladder: a ranking that moves up and down with every match set. One set is played as two games with swapped sides, so both bots experience both sides of the same map.
Besides the ladder, there are cups — periodic tournaments with prizes for the top ranks. A bot that is already active and tested can join a cup with no extra steps.
To climb the ranks, two things matter most: holding objectives and focusing fire on one enemy until it's destroyed. A bot that only chases points but lets its squad get picked off one by one usually loses — and vice versa.
Study your match replays: see where the bot loses units, where it sits still for too long, and where it shoots without hitting anything. Every improvement starts from one observation like that.
References
- https://battle.training
- https://api.battle.training/sdk/arena-sim.mjs
- https://api.battle.training/sdk/local-test.mjs
Like this tutorial? Support the author so there are even more free tutorials.
Support via Saweria
Comments