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.

01 · QUICK START

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.

1

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.

2

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.

3

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.

ByteFox thinking

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).

02 · GAMES & ACTION IDS

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).

ataxx
Ataxx 7×7

Clone (dist 1) or jump (dist 2) and flip adjacent enemy pieces. PASS = 2401.

game: ataxx · ruleset: ataxx-7x7-v1

tictactoe
TicTacToe 3×3

Place on any empty square; first to get 3 in a row wins.

game: tictactoe · ruleset: tictactoe-3x3-v1

gomoku
Gomoku 15×15

Five in a row wins. 10–15 random trap cells (value 3) cannot be played.

game: gomoku · ruleset: gomoku-15x15-v1

tessella
Tessella 9×9 diamond

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

xgame
XGame 10×10

Fill the board; every 5-cell “X” shape scores 1 point (overlaps count). Most X’s wins.

game: xgame · ruleset: xgame-10x10-v1

breakthrough
Breakthrough 8×8

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.

03 · PYTHON SDK

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()
04 · PACKAGING & RUNTIMES

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: false

Choose one of 3 runtimes

runtimeIncludedentrypointBest 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).
05 · CLOCKS & LIMITS

Don’t time out — how the two clocks work

ByteFox timeout

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 / LimitBudgetWhat 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.
06 · NEURAL NETS

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:

  1. Train your policy / value network offline in PyTorch.
  2. Export to a compact .onnx file (or JSON weights) and place it inside models/.
  3. Set runtime: python3.12-onnx in bytearena.yaml and load the session once inside setup().
  4. Run fast single-thread CPU inference inside act() — keep forward passes under ~10–30 ms so MCTS gets plenty of rollouts.
07 · RAW PROTOCOL

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:

Repeats every ply until game over ByteArena Judge Your Agent init game · ruleset · player · limits ready state · your_turn seq · board · legal_action_ids · clock action seq · action_id state · opponent_turn Optional: ponder in background (20s CPU budget) game_over result · reward · final_score
← {"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":{...}}
08 · FAQ

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.

Using single-file Classic Mode (play_games / course tournaments)? Classic Mode Docs →