battle.training is an online arena where tank bots fight each other. You program the bot. You write a controller. A controller is a small program that commands your tank squad. It decides 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. You don’t have to play it. This tutorial covers the whole flow, from the start until your bot is fighting. It’s all free.

How to build a tank bot on battle.training: sign up, write a controller, test, activate, fight

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. A tactical simulation is a battle won with strategy, not with fast fingers. Each match runs for up to 4 minutes. The arena calls your controller 20 times per second. Each call is called a tick. At each tick, the controller decides orders for every unit. The orders can be advance, turn, aim the turret, or fire.

There are two ways to win. First, wipe out the entire enemy squad. Second, collect more objective points when time runs out. The arena has objective points. A point awards points every second while held alone. An APC inside a held objective doubles the points. An APC is an armored troop carrier.

The controller is written in JavaScript. It runs on an isolated QuickJS engine. The engine has 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. That’s the name shown on the ladder.

When the bot is created, you will receive an API key. An API key is a special password for your bot. This API key is used for all commands to the server. The commands include uploading a controller, requesting a scrimmage, and checking the bot’s status. A scrimmage is a practice match against another bot. Keep the key somewhere safe, for example a password manager.

Warning: NEVER share your API key with anyone. 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 */ },

            };

            globalThis.controller = {

              draft(h) { /* pilih regu */ },

              hello(h) { /* sekali, setelah draft */ },

              tick(o)  { /* tiap tick, kembalikan perintah */ },

            };

draft(h) picks your squad. The squad holds 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. Here you get the full rules, the map, and the finished squad. Use this time for map analysis. Check the distance to objectives, high-ground positions, and crossing routes. Here you have the most time to spare.

tick(o) is called 20 times per second. You receive the observation o. An observation is data about the state of the arena right now. It holds 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.

Top-down illustration of the battle.training arena: a tank moving toward an objective while shooting at an enemy

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. 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. If tied, the winner is the one with the larger total HP. HP is the units’ remaining health.

Tip: Don’t hard-code numbers like weapon range or unit cost. Hard-coding means writing a number straight into the code. Read them all from h.rules. The rules can change between seasons. Code that reads h.rules keeps working.

Write Your First Controller

Below is the simplest controller skeleton. This bot shoots the first visible enemy. When no enemy is visible, it advances. 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 };

              },

            };

            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 };

              },

            };

Save that file as controller.js. Note two things. First, aimAt uses the same coordinates as those in o.contacts. So you can use target.x and target.y directly. Second, 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/arena-sim.mjs

            curl -O https://api.battle.training/sdk/local-test.mjs

Then run the test against all four house bots. House bots are bots built into battle.training:

node local-test.mjs controller.js --seeds 20 --vs brawler,holder,random,hunter

            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. A seed is a number that sets the map layout. The test runs 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}'

            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}'

Scrimmages are limited to 60 per day per account. They don’t affect rating. Use different seeds. That way 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. Then activate the version. From then on the bot fights automatically on the ladder. You just monitor the results. Then 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(). Don’t scan the whole map on every tick.

Join Cups and Climb the Ladder

An active bot automatically enters the ladder. The ladder is a ranking board. The ranking moves up and down with every match set. One set is played as two games with swapped sides. That way both bots experience both sides of the same map.

Besides the ladder, there are cups. A cup is a regular tournament 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. First, holding objectives. Second, 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. The reverse is true as well.

Study your match replays. A replay is a recording of a match you can watch again. See where the bot loses units. See where it sits still for too long. See where it shoots without hitting anything. Every improvement starts from one observation like that.

References

  1. https://battle.training
  2. https://api.battle.training/sdk/arena-sim.mjs
  3. https://api.battle.training/sdk/local-test.mjs