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

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

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.2
File Size Uploaded
fastcatan-1.0.2.tar.gz 83.8 kB Details

Built distributions (wheels)

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

Total release size: 743.0 kB

Release files / fastcatan-1.0.2.tar.gz

Download URL fastcatan-1.0.2.tar.gz
Size 83.8 kB
Tags Source
SHA-256 checksum
How to use checksums
047123cf81f6c2a5551c9fc51ce7f8e3e92ac66d507471afc0756940fbe654f0
BLAKE2b-256 checksum
How to use checksums
4140bc95594c3a770b7e1887735d8c3b42979f010393946b196276a235c32209
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.2-cp312-abi3-musllinux_1_2_x86_64.whl

Download URL fastcatan-1.0.2-cp312-abi3-musllinux_1_2_x86_64.whl
Size 354.2 kB
Tags CPython 3.12 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
544ff4a445ce1676aa52a87de1bd12afcd4dab03701a5502bd070c67bb94ad41
BLAKE2b-256 checksum
How to use checksums
8876f588f37fada0d7cfafa067eec15ebca05c7dbe4816ed3b571212c2514409
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.2-cp312-abi3-manylinux_2_28_x86_64.whl

Download URL fastcatan-1.0.2-cp312-abi3-manylinux_2_28_x86_64.whl
Size 217.0 kB
Tags CPython 3.12 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
b3ec56b5c8221a435ab7b122baed5ee04f5470f6051f0089fa3b1d1e9a2a404f
BLAKE2b-256 checksum
How to use checksums
cf9c6105f7acc147bb6f3ac106627ecc892b02d2d9829563f98d01e965483d2e
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.2-cp312-abi3-macosx_11_0_arm64.whl

Download URL fastcatan-1.0.2-cp312-abi3-macosx_11_0_arm64.whl
Size 87.9 kB
Tags CPython 3.12 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
e1dfacb627bc6cbd71e8378fa399ddf1a17985f3aa7ea19a97bb6a097b96e47a
BLAKE2b-256 checksum
How to use checksums
88ecdd650079d7efac173784b1ccdb8c81b6a14cb31c67e16530679130e40dfa
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

This release

1.0.2 This release

4 release files

1.0.1

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