ByteArena · Agent Guide
Build a Game Agent in 5 Minutes
Write a program that plays any of our 6 board games, zip it up, and upload it. ByteArena runs matches in an isolated sandbox, updates Elo ratings, and generates animated replays automatically.
From zero to the ladder in 3 steps
You do not need to read the whole page before playing your first match. Follow these three steps first, then come back for tuning details.
Pick a game & grab a starter
Go to any arena and click “Fork” to get a working v1 in 3 seconds, or download the starter zip to edit locally.
Upload submission.zip
Upload with the same name to save v2, v3… automatically; use a new name to add another agent. Roll back anytime in My Agents.
Battle & watch replays
Challenge built-in bots or other players. Rated games update that game’s Elo ladder, and every match gives a shareable replay link.
How your agent stays alive during a match
Your program starts once at the beginning of a match and stays running until game over. That means your search tree, transposition table, and neural-net weights stay warm in RAM — and you can even keep thinking during your opponent’s turn (pondering).
All 6 Arena Games & Action Encoding
Every turn the platform already sends you the exact list of legal_action_ids. All 6 games follow just two simple numbering patterns, so writing a decoder takes two lines of code:
Placement Games (3)
action_id = r × cols + c
TicTacToe, XGame, Gomoku — just pick which empty cell to place on.
Movement Games (3)
action_id = from_idx × (rows×cols) + to_idx
Ataxx, Tessella, Breakthrough — divmod(action_id, rows*cols) gives (from, to).
Clone (dist 1) or jump (dist 2) and flip adjacent enemy pieces. PASS = 2401.
game: ataxx · ruleset: ataxx-7x7-v1
Place on any empty square; first to get 3 in a row wins.
game: tictactoe · ruleset: tictactoe-3x3-v1
Five in a row wins. 10–15 random trap cells (value 3) cannot be played.
game: gomoku · ruleset: gomoku-15x15-v1
Octagons move 8 ways, squares 4 ways; leap an enemy when backed by a friendly anchor. First to capture 4 wins.
game: tessella · ruleset: tessella-9x9-v1
Fill the board; every 5-cell “X” shape scores 1 point (overlaps count). Most X’s wins.
game: xgame · ruleset: xgame-10x10-v1
Pawns march forward (straight empty, diagonal capture). First to reach the far row wins.
game: breakthrough · ruleset: breakthrough-8x8-v1
Board values are always from YOUR perspective: 0 = empty, 1 = your piece, 2 = opponent piece, 3 = obstacle / trap / blocked corner.
Writing an Agent in Python (Recommended)
You never need to touch sockets or raw JSON. Just subclass bytearena.Agent — the SDK handles all communication and only calls your methods when needed:
setup(config) once at start
Load model weights, opening books, or read config["player"] (0 = first, 1 = second).
act(state, deadline) required
Return ONE integer from state.legal_action_ids before deadline.remaining_ms() runs out.
ponder(state, cancel) optional
Runs during the opponent’s turn. Keep searching until cancel.cancelled becomes True.
update(state) optional
Fired on every board change — handy for keeping an incremental MCTS tree in sync.
Minimal working agent (20 lines)
import sys
from bytearena import Agent, State, Deadline
class MyAgent(Agent):
def setup(self, config):
# Runs once at match start: load weights or init tables
self.game = config.get("game", "ataxx")
def act(self, state: State, deadline: Deadline) -> int:
# state.board is always player-relative: 1 = you, 2 = opp, 0 = empty
best_action = state.legal_action_ids[0]
for action_id in state.legal_action_ids:
# Keep >=150 ms safety margin so you never time out
if deadline.remaining_ms() < 150:
break
best_action = self.pick_better(state, best_action, action_id)
print(f"turn {state.turn}: picked {best_action}", file=sys.stderr)
return best_action
def pick_better(self, state: State, a: int, b: int) -> int:
return a # Replace with your own search or evaluation
if __name__ == "__main__":
MyAgent().run()How to package submission.zip
Zip your project so bytearena.yaml sits directly at the root of the zip (not nested inside an extra folder):
# Zip layout
submission.zip
├── bytearena.yaml # required: name, game, entrypoint
├── agent/
│ └── main.py # your code (or main.cpp)
└── models/ # optional: offline-trained weights# bytearena.yaml example
name: MyFirstFox
game: ataxx
ruleset: ataxx-7x7-v1
runtime: python3.12-basic
entrypoint: [python, -m, agent.main]
protocol: ndjson-v1
supports_ponder: falseChoose one of 3 runtimes
| runtime | Included | entrypoint | Best for |
|---|---|---|---|
| python3.12-basic | Python 3.12 stdlib + SDK | [python, -m, agent.main] | Fastest startup, heuristic & alpha-beta bots |
| python3.12-onnx | + numpy + onnxruntime | [python, -m, agent.main] | Running exported PyTorch / ONNX neural nets |
| cpp20 | g++ -std=c++20 + C++ SDK | [cpp, agent/main.cpp] | Maximum search speed (MCTS / bitboards) |
3 things to avoid when packaging:
- Do NOT bundle the bytearena SDK inside your zip; the platform mounts it automatically.
- Matches have ZERO internet access — bundle any model weights or tables inside models/.
- Never print debug messages to stdout — always use sys.stderr (or std::cerr).
Don’t time out — how the two clocks work
The #1 rule for time management
Do not pace off the 60s match bank alone — every single move also has a ~1000 ms cap! deadline.remaining_ms() already gives you the smaller of the two. Always stop a little early (~150–200 ms margin) because your reply still needs time to travel back over stdout.
| Stage / Limit | Budget | What happens if exceeded? |
|---|---|---|
| Startup (setup) | ~8 s | Forfeit (startup_timeout). Keep model loading lightweight. |
| Single move (act) | ~1000 ms | Forfeit (timeout). Never wait until 0 ms. |
| Total match time bank | 60 s | Shared across all your moves; hitting 0 forfeits (timeout). |
| Opponent-turn ponder | 20 s CPU | No forfeit! Process simply pauses until your next turn. |
| Memory & threads | ~512 MB · 1 thread | OOM kills your process (crash → forfeit). |
| Illegal move | — | Returning an id not in legal_action_ids forfeits immediately. |
Train locally in PyTorch, infer with ONNX
Training happens on your own GPU with zero restrictions. When you are ready to compete, separate inference from PyTorch in 4 quick steps:
- Train your policy / value network offline in PyTorch.
- Export to a compact .onnx file (or JSON weights) and place it inside models/.
- Set runtime: python3.12-onnx in bytearena.yaml and load the session once inside setup().
- Run fast single-thread CPU inference inside act() — keep forward passes under ~10–30 ms so MCTS gets plenty of rollouts.
NDJSON Protocol (only if skipping the SDK)
If you use our Python SDK or bundled C++20 SDK, you can skip this section completely. If you want to implement the wire protocol manually, platform and agent exchange one JSON line at a time over stdin / stdout:
← {"type":"init","protocol":"bytearena-agent/v1","game":"ataxx","ruleset":"ataxx-7x7-v1","player":0,"agent_seed":42,"limits":{...}}
→ {"type":"ready"}
← {"type":"state","seq":1,"turn":0,"phase":"your_turn","board_shape":[7,7],"board":[1,0,...,2],"legal_action_ids":[0,58,...]}
→ {"type":"action","seq":1,"action_id":58}
← {"type":"game_over","result":"win","reward":1.0,"final_score":{...}}Frequently Asked Questions
What is the difference between a new version and a new agent?
Uploading with the same name in the same game saves v2, v3… under that agent (keeping its Elo history) and makes the new version active automatically. Using a new name creates a separate agent with its own Elo ladder entry. All active and historical versions share a 12-version account limit; delete old versions anytime in My Agents.
Why did my agent time out even though it finished in 0.99s locally?
The judge starts the clock when it sends state and stops it only after receiving your action over stdout, plus sandbox CPUs can vary slightly. Always stop searching when deadline.remaining_ms() drops below ~150–200 ms.
Can I import torch or install custom pip packages?
No — matches run completely offline without PyTorch. Train locally with PyTorch, export to ONNX, put the .onnx file in models/, and select runtime: python3.12-onnx (which includes numpy and onnxruntime).
How do I print debug logs without breaking the match?
Always write logs to stderr (print("...", file=sys.stderr) in Python, std::cerr in C++). Never write anything other than protocol messages to stdout.