Dye — bot reference
all sections
Try programs live in the playground: it runs the real engine in your browser.
overview
Dye is a programming game on a big shared grid. You never move units by hand. You write tiny assembly programs, upload them, and spawn units that run them on their own. Every step a unit takes paints the tile it leaves in your colour. Your score is how much connected territory you hold, summed over every tick of a 10-minute match.
So there are two layers of play:
- Unit tactics: what each tiny program does with the five tiles it can sense.
- Macro strategy: your bot (a WebSocket client) sees the whole board and decides which programs to field, when, where and how much energy each unit gets. It can rewrite its programs mid-match.
quick start
- Download the Python scaffold: dye_bot.py (needs
pip install websockets). - Run it against a server:
python dye_bot.py ws://HOST:9091. (In a tournament match the server isws://coresrv:9091and thePLAYERenvironment variable is set for you; locally, usePLAYER=open.) - Prototype the
PROGRAMin the playground, which shows each unit's registers and current line as it runs. - Edit the
PROGRAMstring (your units) and thedecide()function (your spawns). - Package it as a Docker image and push it to play real matches: see Playing on hyxor.com.
The whole conversation looks like this:
# bot → server
UPLOAD 0
loop: SENSE A, 1
CMP A, 3
JZ turn
STEP
JMP loop
turn: TURN R
JMP loop
# server → bot
OK UPLOAD 0 len=7 fee=9
{"type":"state","tick":1,...} ← one per tick
# bot → server
SPAWN 0 140 77 60
# server → bot
OK SPAWN 17 cost=69connection & messages
- Open a WebSocket to the match server on port 9091. Everything is text messages.
- In a tournament match the server is
ws://coresrv:9091, and you're identified by the source IP of your connection. You don't send a name. If the connection drops, reconnect: same address, same player. - Your player name (
player/bot) is in the environment variablePLAYERof your bot's container. Find yourpidby matching it in a state frame'splayers. On the local demo server your first command claims an open slot, namedopen, so run your bot withPLAYER=open. - Messages starting with
{are JSON frames (state or result). Everything else is a one-line reply to one of your commands:OK …orERR ….
Commands (bot → server)
| Command | Effect | Reply |
|---|---|---|
UPLOAD <slot> followed by program source on the next lines | Assembles the program into slot 0–3. Free. Affects future spawns only; deployed units keep their program. | OK UPLOAD <slot> len=<n> fee=<e> or ERR UPLOAD: line <k>: … |
SPAWN <slot> <x> <y> <energy> | Spawns a unit running that slot's program on tile (x, y), loaded with energy from your reserve. The tile must be yours and empty. | OK SPAWN <unit id> cost=<e> or ERR SPAWN: … |
fee is the per-unit spawn fee for that slot (base + code size); a spawn costs fee + energy. Fees and costs in replies are rounded up to whole energy, so budgeting from them is always safe. Rejected commands cost nothing. The reasons are: empty slot, slot out of range, out of bounds, tile not owned, tile occupied, unit cap reached, insufficient energy, negative energy. You can send any number of commands. They're applied at the start of the next tick, in arrival order.
the state frame
{
"type": "state",
"tick": 1234,
"match_ticks": 24000,
"ticks_per_second": 40,
"width": 512, "height": 512,
"players": [
{ "pid": 1, "name": "alice/painter", "reserve": 87, "score": 9938211,
"tiles": 41250, "units": 32, "eliminated": false }
],
"units": [
{ "id": 17, "pid": 1, "x": 140, "y": 77, "heading": 2, "energy": 41 }
],
"paint": ["0011122200…", …],
"marks": ["00000000a3…", …]
}| Field | Meaning |
|---|---|
paint | height strings, row y = 0 at the top. Character x is one hex digit, the owning pid (0 = neutral). Ids stay below 16. |
marks | Same layout with two hex digits per tile: the tile's mark byte (0–255). Tile x is at characters 2x, 2x+1. |
units | Every living unit, yours and everyone else's. heading: 0 north (y−1), 1 east (x+1), 2 south, 3 west. |
players | reserve and energy are whole energy units. score is the running match score (see Scoring). |
Coordinates: x grows to the right, y grows downwards, and the board is walled. Uploaded programs, registers and program counters are never sent, so your code stays secret.
When the match ends you get one result frame:
{ "type": "result", "tick": 24000,
"placements": [ { "pid": 3, "name": "…", "score": … }, … ] } best firstA frame on the standard board is about 0.8 MB. Decoding the grids is the costly part in a slow language, so in Python consider only decoding the rows you need, or using numpy.
rules of the world
- Everyone starts with a 9×9 patch of their own paint, placed evenly around the board.
STEPmoves a unit one tile forward and paints the tile it leaves. The destination keeps its paint until the unit leaves it in turn. So a unit stands on the ground it's crossing and pays that ground's drain.- One unit per tile. Stepping into a wall or an occupied tile is blocked: the unit stays put, paints nothing, and its tick is spent.
- Last writer wins a tile, for paint and marks alike.
- A player is eliminated with zero tiles and zero living units. The match ends at
match_ticksor when one player is left.
Each tick runs in a fixed order, which makes it fully deterministic:
- Commands, in arrival order (units spawned now act this same tick).
- Every unit, oldest first: pay drain, then run its program for one tick's cycle budget. So when two units want the same tile, the older one gets it.
- Income to every player still in.
- Score accrues.
- Eliminations.
energy & economy
- Income is flat and identical for everyone: 320 energy/sec (8 per tick). It never scales with territory, so a big empire defends a long border on the same budget as the underdog.
- Starting reserve: 800.
- Spawn cost = 5 + 0.5 × instructions + energy you load. Past 512 instructions the fee grows quadratically (+(n−512)²/2). The hard limit is 1024 instructions.
- Drain per unit per second, by the tile it stands on: own paint 0.4, neutral 2.0, enemy 6.0 (0.01, 0.05, 0.15 per tick). A unit dies when its energy runs out.
- At most 800 living units per player.
scoring
Your score is a running total, added to every tick, and it rewards connected territory:
- Twice a second (every 20 ticks) your territory is split into clusters: groups of your tiles connected through shared edges. A corner touch doesn't connect.
- Each cluster is worth size1.5, computed as
size × floor(√size). Your value is the sum over your clusters. - That value is added to your score every tick until the next recount.
So one 400-tile blob is worth 8000, while four separate 100-tile patches are worth 4000. Cutting an enemy cluster in two lowers their value, and reconnecting your own pieces raises yours. Holding territory early and keeping it matters more than a last-second grab.
the unit VM
Machine state
- Registers
A B C D: 16-bit, wrapping. All start at 0. - RAM: 16 words,
[0]–[15]. - Flags
eq,lt, set byCMP(unsigned). - Return stack, 4 deep.
- The program counter wraps: running off the end loops to the start.
- A private random-number generator, seeded per unit.
- Heading: every unit spawns facing north.
What a unit senses
Only its own tile and the four next to it, relative to its heading:
| dir | 0 | 1 | 2 | 3 | 4 |
|---|---|---|---|---|---|
| here | ahead | right | behind | left |
SENSEgives the paint: 0 neutral, 1 yours, 2 enemy, 3 wall.LOOKgives the unit there: 0 none, 1 friend, 2 enemy.MARKgives the tile's mark byte.
One tick
Each tick a unit gets 192 cycles. It runs instructions until one of two things happens:
- It executes an actuator,
STEPorSLEEP. That ends its tick and forfeits the remaining cycles. - The next instruction costs more cycles than are left. The unit pauses there and resumes next tick, but it still pays that tick's drain without having moved.
TURN and WRITE are not actuators. A unit can write a mark, turn, sense in its new direction and step, all in one tick.
A unit dies when its energy runs out, when it runs DIE, or when it traps: RET with an empty stack, CALL deeper than 4, or a direction outside 0–4 given to SENSE/LOOK/MARK at run time.
instruction set
| Instruction | Cycles | Effect |
|---|---|---|
MOV dst, src | 1 | dst = src |
ADD dst, src | 1 | dst = dst + src (wrapping) |
SUB dst, src | 1 | dst = dst − src (wrapping) |
CMP a, b | 1 | eq = (a = b), lt = (a < b), unsigned |
JMP t | 1 | jump to label or relative offset |
JZ t / JNZ t | 1 | jump if eq / if not eq |
JLT t | 1 | jump if lt |
CALL t | 2 | push return address, jump |
RET | 1 | return |
RND dst | 2 | dst = random 0–65535 |
ENG dst | 1 | dst = own energy left (whole units) |
SENSE dst, dir | 3 | paint in dir: 0 neutral, 1 self, 2 enemy, 3 wall |
LOOK dst, dir | 3 | unit in dir: 0 none, 1 friend, 2 enemy |
MARK dst, dir | 2 | mark byte of the tile in dir |
STEP † | 4 | move forward one tile; paints the tile left behind |
TURN L / TURN R | 2 | rotate 90°; does not end the tick |
WRITE src | 3 | set this tile's mark to src's low byte; does not end the tick |
SLEEP n † | 1 | idle for n ticks |
DIE | 0 | self-destruct |
† actuator: ends the unit's tick.
assembler syntax
- One instruction per line.
;starts a comment. - Labels:
name:, before an instruction or on a line of their own. Labels are case-sensitive; mnemonics and registers aren't. - Operands: registers
A–D, immediates (5,0x1F,-1, masked to 16 bits) and RAM[0]–[15]. A destination can't be an immediate. - Jump targets: a label, or a signed offset from the jumping instruction.
- Errors are reported with the source line:
ERR UPLOAD: line 4: ….
Example: claim neutral ground first
; Read ahead/right/left once into registers (9 cycles), then decide.
loop: SENSE A, 1 ; A = ahead
SENSE B, 2 ; B = right
SENSE C, 4 ; C = left
CMP A, 0
JZ go ; neutral ahead: take it
CMP B, 0
JZ right
CMP C, 0
JZ left
CMP A, 3
JZ right ; wall ahead
RND D
CMP D, 8192 ; otherwise turn ~1/8 of the time
JLT right
go: LOOK D, 1
CMP D, 0
JNZ right ; a unit is in the way
STEP
JMP loop
right: TURN R
JMP go
left: TURN L
JMP gosettler reference bot, which is close to the example above, on a 16×16 board. Recorded from the game engine. It claims neutral ground first, painting the tile behind each step, and turns at the walls.marks: the shared byte
Every tile also carries one mark byte (0–255). Any unit can read it (MARK) or overwrite it (WRITE, only the tile it stands on), friend or foe. Marks survive repainting and the writer's death. WRITE doesn't end the tick, so a unit can drop a mark on the tile it's about to leave and step off in the same tick.
Use marks for trails, frontier flags, rally points, or messages between your units. They're unauthenticated, so opponents can read your scheme and forge or erase your marks. Every bot sees the full mark grid every tick, so the information war runs at both levels: units write and read marks, and your bot can study an opponent's marks and upload a counter-program mid-match.
standard settings
| Setting | Value |
|---|---|
| Players | 3 to 6 per match |
| Board | 512 × 512, walled; 9 × 9 starting patch |
| Match | 24000 ticks at 40 ticks/sec (10 minutes) |
| Income / starting reserve | 320 per sec (8 per tick) / 800 |
| Spawn cost | 5 + 0.5 per instruction + energy loaded (quadratic past 512 instructions) |
| Program limit | 1024 instructions; 4 upload slots |
| Cycles per unit per tick | 192 |
| Drain own / neutral / enemy | 0.4 / 2.0 / 6.0 per sec |
| Units per player | 800 at once |
| Scoring | sum of cluster size1.5, edge-connected, recounted twice a second |
| Unit memory | 4 registers, 16 RAM words, return stack 4 deep |
| Marks | one 8-bit byte per tile, shared |
tips
- Sense once. Read the directions you need into registers, then compare registers. Re-sensing burns cycles, and a unit that runs out of cycles stands still while still paying drain.
- Every step paints. Any movement off your own paint gains territory. Steps across your own paint are cheap but gain nothing.
- Keep it connected. Under cluster scoring a stray patch is worth little. Spawning inside your main cluster and growing it as one blob pays off.
- Where you spawn is strategy. You can spawn on any tile you own, so fresh units can go straight to the border you care about.
- Duels and free-for-alls differ. Pure aggression tends to win one-on-one but gets worn down when everyone fights everyone.
testing offline
The engine is deterministic, and the dye command-line tool runs the real engine without a server:
dye check prog.asm: assemble, and report the size, spawn fee and errors.dye run --bot prog.asm --bot spreader --stats: a full headless match against the built-in reference bots (spreader,settler,raider,guard,cutter,react:settler+raider+guard, …).dye league --bot prog.asm --bot settler --bot raider: a round-robin with win rates and an efficiency breakdown.dyedemo --bots spreader,settler,open: a local server with a live viewer on port 9090. Your bot takes theopenslot. Each match waits up to 60 seconds (--join-timeout) for every open slot to be claimed.
Both come in the Docker image registry.hyxor.com/akama/dye (pull it after docker login registry.hyxor.com). Run it as is for the test server, whose default line-up is the site's reference bots (raider, guard@100, react:settler+raider+guard, cutter) plus an open slot, and each match waits up to 60 seconds for your bot to connect; dyedemo flags such as --board 64, --ticks 2400, --join-timeout 300 or --once go after the image name. Run dye with --entrypoint dye:
docker run --rm -p 9090:9090 -p 9091:9091 registry.hyxor.com/akama/dye --board 64 --ticks 2400
docker run --rm -v "$PWD":/w -w /w --entrypoint dye registry.hyxor.com/akama/dye \
league --bot prog.asm --bot settler --bot raiderplaying on hyxor.com
Getting your bot into matches
- Register and activate an account, then create a bot for the game Dye.
- Build your bot as a Docker image whose entrypoint starts it. It gets no arguments, only the environment variable
PLAYER, and connects tows://coresrv:9091. - Push it to
registry.hyxor.com/<handle>/<bot>. Thelatesttag is what plays. - Enable the bot. Only enabled bots are picked for matches.
docker login registry.hyxor.com -u alice # site password, or an API token (hx_…)
docker build --platform linux/amd64 -t registry.hyxor.com/alice/k1 .
docker push registry.hyxor.com/alice/k1Repository names are lowercase (a Docker rule): handles and bot names use lowercase letters, digits, - and _, starting and ending with a letter or digit. If your account is older and your handle has capitals, log in with your handle as it is and push to the lowercased name (Carol pushes registry.hyxor.com/carol/k1). You can only push your own bots.
A match has 3 to 6 bots. Matchmaking picks one fewer bot than are enabled for the game, at random, so line-ups change from match to match, except that a newly pushed version of a bot plays its first 5 matches before anyone else. Every bot's place is recorded, and the leaderboard counts wins.
What your bot runs in
Each bot gets its own small virtual machine (a Firecracker microVM):
| Limit | Value |
|---|---|
| Image | linux/amd64 only. At most 128 layers, 1 GiB compressed, 2 GiB unpacked, manifest and config at most 4 MiB each. Env, WorkingDir and User from the image are used; volumes, ports and healthchecks are ignored. Device files, setuid bits and file capabilities are removed. |
| CPU and memory | 1 vCPU on a core of its own, 2 GiB RAM |
| Files | Read-only root. /tmp and /dev/shm are 64 MiB in memory, and nothing there can be executed. |
| Processes | Up to 256 processes and 1024 open files. No capabilities, even as root. |
| Network | Only the match server, coresrv:9091. No DNS, no internet, no other bots: put everything your bot needs in the image. |
A match, start to finish
- The runner pulls every bot, starts the match server, then starts all the bots at once.
- The match waits up to 60 seconds for every bot to connect, then plays 24000 ticks at 40 a second (10 minutes), or until one player is left. Connect as soon as your bot starts, and retry until it works.
- A bot that hasn't connected within those 60 seconds forfeits: it is out before tick 0 (eliminated, no tiles, no units), its starting patch becomes neutral ground, and it places last. If it connects later it can watch, but every command gets
ERR eliminated. If only one bot connected, it wins by walkover; if none did, the match has no result. - After the result frame, the bots are stopped: SIGTERM, then SIGKILL two seconds later.
Logs, replay and video
Your bot's stdout and stderr are saved: the first 30 MiB of each, with a note at the end if anything past that was dropped. Once the match has completed, they're linked next to the match on your bot's page (Stdout, Stderr; only you can see them), and available through the API. The files are xz-compressed. Print what you'll want to read afterwards, such as your decisions and rejected commands. Every completed match also has a public replay (every state frame, as xz-compressed JSON lines) and a video.
The JSON API
Everything above can be scripted through https://hyxor.com/api/v1. Log in once for a token and send it as Authorization: Bearer <token>. The same token works as your docker login password.
TOKEN=$(curl -s https://hyxor.com/api/v1/tokens \
-d '{"user": "alice", "password": "…", "name": "laptop"}' | jq -r .token)
H="Authorization: Bearer $TOKEN"
curl -s -H "$H" https://hyxor.com/api/v1/bots -d '{"name": "k1", "game": "dye"}' # create a bot
curl -s -H "$H" -X PATCH https://hyxor.com/api/v1/users/alice/bots/k1 -d '{"enabled": true}'
curl -s -H "$H" https://hyxor.com/api/v1/registry # login and push commands
curl -s -H "$H" "https://hyxor.com/api/v1/matches?game=dye&limit=5"
curl -sL -H "$H" https://hyxor.com/api/v1/matches/<id>/bots/alice/k1/stderr | xz -dRevoke a token with DELETE /api/v1/tokens/<id> (current for the one you're using).
Dev log
Each version of a bot can carry a short dev log: what you saw in its matches, what you changed and why, and what you expect to happen. It shows under the version on the bot's page, and anyone can read it. A paragraph or two is plenty.
curl -s -H "$H" https://hyxor.com/api/v1/users/alice/bots/k1/devlog -d '{
"text": "Raiders cut v3 off from home in most matches.\n\nv4 keeps the first ten units within 20 tiles of the start before spreading. I expect a slower start and fewer collapses after tick 8000.",
"digest": "sha256:…"
}'
curl -s https://hyxor.com/api/v1/users/alice/bots/k1/devlog # read it backLeave out digest and the note goes on the bot's newest version. Posting again for the same version replaces it. It's plain text, up to 2000 characters; a blank line starts a new paragraph. A version exists about a minute after you push (while the bot is enabled), so post after that; before then you get a 409.