Skip to main content

Python SDK for Grid — Tron-style autonomous bot battles

Project description

grid-sdk-py

Python SDK for Grid — a Tron-style competitive bot battle platform.

Installation

pip install grid-sdk-py

Quick start

import os
from gridbot import Client, Config, StrategyFunc, GameState, Direction
from gridbot.helpers import safe_moves, flood_fill

def my_strategy(state: GameState) -> Direction:
    moves = safe_moves(state)
    if not moves:
        return Direction(state.you.direction)
    # pick the direction with the most open space
    best, best_space = moves[0], -1
    for d in moves:
        nx, ny = d.apply(state.you.x, state.you.y)
        space = flood_fill(nx, ny, state)
        if space > best_space:
            best_space = space
            best = d
    return best

client = Client(Config(
    server_url=os.environ.get("BOT_SERVER", "ws://localhost:8083"),
    token=os.environ["BOT_TOKEN"],
    strategy=StrategyFunc(my_strategy),
))
client.run()
BOT_TOKEN=your-token python bot.py

Architecture

The client uses two threads:

  • WebSocket thread — receives frames, replies to server PINGs immediately (never blocked).
  • Strategy thread — reads the latest game state, computes your move, sends the command.

This prevents disconnection when strategy computation takes longer than the server's 30 s pong timeout.

Key helpers (gridbot.helpers)

Function Description
safe_moves(state) Directions that don't hit a wall or trail
safe_moves_detailed(state) Same, with target position + head-on risk
flood_fill(x, y, state) Reachable empty cells from (x, y)
voronoi_bfs(mx, my, ox, oy, state) Territorial split — (my_cells, opp_cells)
head_on_risk(x, y, state) True if an opponent could also move here
find_closest_opponent(state) Nearest alive opponent bot
manhattan_distance(x1, y1, x2, y2)
wall_count(x, y, state) Adjacent non-empty cells (0–4)

Strategy interface

from gridbot import Strategy, MatchAware, GameState, Direction

class MyBot(Strategy, MatchAware):
    def on_match_start(self, state: GameState) -> None:
        ...  # called at the start of every match

    def on_death(self, state: GameState) -> None:
        ...  # called when your bot dies

    def move(self, state: GameState) -> Direction:
        ...  # called every turn — must return within 500 ms

Requirements

  • Python 3.10+
  • websocket-client >= 1.7.0

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

grid_sdk_py-0.3.1.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

grid_sdk_py-0.3.1-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

Details for the file grid_sdk_py-0.3.1.tar.gz.

File metadata

  • Download URL: grid_sdk_py-0.3.1.tar.gz
  • Upload date:
  • Size: 9.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for grid_sdk_py-0.3.1.tar.gz
Algorithm Hash digest
SHA256 b10e27cf1de5c5e5c254258d13c39902a97255e8dae5119933384ad583aff4c0
MD5 1d62f26e5ed1fe38a791b10d1f2e82e0
BLAKE2b-256 97ee2577d6f4af6a4501fa1718195e4eb0da451acc01fe1b0737e6f757059397

See more details on using hashes here.

Provenance

The following attestation bundles were made for grid_sdk_py-0.3.1.tar.gz:

Publisher: publish.yml on tot0p/grid-sdk-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file grid_sdk_py-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: grid_sdk_py-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 11.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for grid_sdk_py-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4ac3f39b0b6c106b4be2ea9dc212eceeb8ac30ead3d740aa0b16c33ba6f5a15d
MD5 98bb6c5cdb8a877f41deb667cf6d0cb1
BLAKE2b-256 e6e1c0059e1be36b1dd4e847d1ed943a24dce926cb219dedf69e176d757b1ff9

See more details on using hashes here.

Provenance

The following attestation bundles were made for grid_sdk_py-0.3.1-py3-none-any.whl:

Publisher: publish.yml on tot0p/grid-sdk-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page