Skip to main content

fastcatan

PyPI Python License: MIT

A high-throughput Settlers of Catan simulator — C++ core with Python bindings (nanobind), built for reinforcement-learning research. Millions of environment steps per second, a flat observation vector, a legal-action bitmask, and a batched vectorized environment for GPU training.

  • ⚡ Fast — pure-C++ rules engine, ~4.6M batched env-steps/s on a single desktop.
  • 🧠 RL-ready — fixed-size float32 observation, uint64 action mask, scalar reward.
  • 📦 Batched — BatchedEnv steps thousands of games per call (OpenMP, GIL released).
  • 🎯 Deterministic — seeded games are fully reproducible.

Stability: the rules engine and the observation/action interface are frozen and stable — pin an exact version (e.g. fastcatan==1.0.1).

Install

pip install fastcatan

Prebuilt wheels: Linux x86_64 and macOS (Apple Silicon), CPython 3.12+ (one abi3 wheel serves 3.12 / 3.13 / 3.14). Other platforms build from the sdist automatically (needs a C++ toolchain + CMake ≥ 3.27).

Quickstart

Play one game with a random legal policy:

import numpy as np
import fastcatan

env = fastcatan.Env()
env.reset(seed=0)

mask = np.zeros(fastcatan.MASK_WORDS, dtype=np.uint64)   # legal-action bitmask
obs  = np.zeros(fastcatan.OBS_SIZE,  dtype=np.float32)   # observation buffer
rng  = np.random.default_rng(0)

while True:
    env.action_mask(mask)                 # fill legal moves for current player
    env.write_obs(env.current_player, obs)   # fill that player's POV observation
    legal = np.flatnonzero(np.unpackbits(mask.view(np.uint8), bitorder="little")
                           [:fastcatan.NUM_ACTIONS])
    action = int(rng.choice(legal))
    reward, done = env.step(action)
    if done:
        vps = [env.player_vp(p) for p in range(fastcatan.NUM_PLAYERS)]
        winner = next((p for p, v in enumerate(vps) if v >= 10), -1)
        print("winner:", winner, "vps:", vps)
        break

Batched (vectorized) environment

For RL throughput, step many games at once and drive them with a batched policy:

import numpy as np, fastcatan

N = 4096
env = fastcatan.BatchedEnv(N, seed=0)
env.reset()

masks = np.zeros((N, fastcatan.MASK_WORDS), dtype=np.uint64)
obs   = np.zeros((N, fastcatan.OBS_SIZE),  dtype=np.float32)
acts  = np.zeros(N, dtype=np.uint32)
rew   = np.zeros(N, dtype=np.float32)
done  = np.zeros(N, dtype=np.uint8)

env.write_masks(masks)      # all N legal masks in one C++ call
env.write_obs(obs)          # all N current-player observations
# ... your batched policy fills `acts` ...
env.step_raw(acts, rew, done)   # steps all N games (OpenMP, GIL released)

API at a glance

symbol meaning
Env single-game environment (reset, step, action_mask, write_obs, …)
BatchedEnv vectorized environment over N games (step_raw, write_masks, write_obs, …)
OBS_SIZE / OBS_FULL_SIZE observation length (POV / full-information)
NUM_ACTIONS size of the action space
MASK_WORDS uint64 words in a legal-action bitmask (ceil(NUM_ACTIONS/64))
NUM_PLAYERS, NUM_NODES, NUM_EDGES, NUM_HEXES, NUM_PORTS board constants
SKIP_ACTION no-op action id (parked finished games in a batch)

env.step(action) returns (reward, done). Observations are written into caller-provided buffers (no per-step allocation). See examples/ for random and alpha-beta players.

Development

Build from source (tunes -march=native for your machine):

pip install .
pytest tests/

License

MIT © 2026 s1nbo

Release files for fastcatan 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fastcatan 1.0.1
File Size Uploaded
fastcatan-1.0.1.tar.gz 83.7 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for fastcatan 1.0.1
File Interpreter ABI Platform
fastcatan-1.0.1-cp312-abi3-musllinux_1_2_x86_64.whl CPython 3.12 abi3 Linux musl 1.2+ x86-64 Details
fastcatan-1.0.1-cp312-abi3-manylinux_2_28_x86_64.whl CPython 3.12 abi3 Linux glibc 2.28+ x86-64 Details
fastcatan-1.0.1-cp312-abi3-macosx_11_0_arm64.whl CPython 3.12 abi3 macOS 11.0+ ARM64 Details

Total release size: 748.0 kB

Release files / fastcatan-1.0.1.tar.gz

Download URL fastcatan-1.0.1.tar.gz
Size 83.7 kB
Tags Source
SHA-256 checksum
How to use checksums
a9d991839b23505bf419fb97d21b9547993c86066f9528e4aa8582bf530b683b
BLAKE2b-256 checksum
How to use checksums
d53440e62fca9cfb3d1365ee38ede63efeac61a2757a27958e88a24f1bf8371b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 11, 2026.

Transparency log

Release files / fastcatan-1.0.1-cp312-abi3-musllinux_1_2_x86_64.whl

Download URL fastcatan-1.0.1-cp312-abi3-musllinux_1_2_x86_64.whl
Size 356.3 kB
Tags CPython 3.12 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
dce9bf9d6758f5615d3ae086ee2005b45fc7f36df6a336c7ea82dc594b3fd4e7
BLAKE2b-256 checksum
How to use checksums
67f522d06926675f272dea6aa69e6f16a98ed7bf7a09f84da1ae405945224a7e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 11, 2026.

Transparency log

Release files / fastcatan-1.0.1-cp312-abi3-manylinux_2_28_x86_64.whl

Download URL fastcatan-1.0.1-cp312-abi3-manylinux_2_28_x86_64.whl
Size 218.2 kB
Tags CPython 3.12 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
5a9a15c5c537e72d69e3449bb5790b73988e5fd4ae9f6f4b51d9ec789c6693a5
BLAKE2b-256 checksum
How to use checksums
8cf5ae6a3600a05961df4d525d1732273f768ed740e1f2049be8eedd44be84f1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 11, 2026.

Transparency log

Release files / fastcatan-1.0.1-cp312-abi3-macosx_11_0_arm64.whl

Download URL fastcatan-1.0.1-cp312-abi3-macosx_11_0_arm64.whl
Size 89.8 kB
Tags CPython 3.12 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
6540327232451321afe08123accfc5a0f5c732f91193616a92ed9a323b086c03
BLAKE2b-256 checksum
How to use checksums
f1f08fd82f74e9b9a0f8bd7f776813f8a1edb3bd035d442f74ed290e73382918
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 11, 2026.

Transparency log

Release history Release notifications | RSS feed

2.0.0

4 release files

1.0.2

4 release files

This release

1.0.1 This release

4 release files

1.0.0

4 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page