Skip to main content

Chess environment for reinforcement learning

Project description

FastChessEnv

A Chess Environment for Reinforcement Learning with Stockfish integration and OpenMP support.

Installation

Easy Local Installation

Run the installation script:

./install.sh

This will:

  1. Build the MisterQueen libraries
  2. Copy the libraries to the package directory
  3. Build the Python extension
  4. Install the package in development mode

Manual Installation

  1. Build the MisterQueen libraries:
./build_lib.sh
  1. Copy the libraries to the package directory:
python copy_libs.py
  1. Build the Python extension and install:
python build.py
pip install -e .

Remote Installation

You can install directly from the repository:

pip install git+https://github.com/yourusername/fastchessenv.git

Or with uv:

uv pip install git+https://github.com/yourusername/fastchessenv.git

Docker Installation

To build and run with Docker:

./docker_build.sh
docker run -it --rm fastchessenv:openmp

Testing

Run the tests to verify everything is working correctly:

python -m pytest

Usage

Basic Usage

import fastchessenv

# Create a chess environment with 4 parallel environments
env = fastchessenv.CChessEnv(4)

# Reset the environments
state, mask = env.reset()

# Make a move
move_arr = env.random()  # Sample random moves
next_state, next_mask, reward, done = env.step(move_arr)

Using Stockfish for Opponent Moves

import fastchessenv

# Create a chess environment with Stockfish opponents
env = fastchessenv.SFCChessEnv(4, depth=3)

# Reset the environments
state, mask = env.reset()

# Make a move
move_arr = env.random()  # Sample random moves
next_state, next_mask, reward, done = env.step(move_arr)

Using Random Opponent Moves

import fastchessenv

# Create a chess environment with random opponents
env = fastchessenv.RandomChessEnv(4)

# Reset the environments
state, mask = env.reset()

# Make a move
move_arr = env.random()  # Sample random moves
next_state, next_mask, reward, done = env.step(move_arr)

OpenMP Support

FastChessEnv uses OpenMP for parallelization. See OPENMP.md for details on how to enable and configure OpenMP support.

Cross-Platform Support

FastChessEnv is designed to work across multiple platforms and architectures:

  • macOS (Intel x86_64 and Apple Silicon arm64)
  • Linux (x86_64 and aarch64)

The package includes platform-specific binary libraries that are automatically selected at runtime based on your system. If you're building from source, the build system will compile libraries optimized for your current platform.

Building for Multiple Platforms

This package includes Docker-based tools to build wheels for multiple platforms:

Using Docker for Cross-Platform Builds

# Build wheels for multiple platforms using Docker
./docker_build_wheels.sh

This script will:

  1. Build a source distribution
  2. Use Docker to build wheels for Linux x86_64
  3. Use Docker with buildx (if available) to build wheels for Linux aarch64/ARM64
  4. Build a wheel for your current macOS platform

All wheels will be stored in the wheelhouse directory, organized by platform.

Manual Multi-Platform Building

If you prefer to build manually, you'll need to:

  1. Build on each target platform (macOS arm64, macOS x86_64, Linux x86_64, Linux aarch64)
  2. Collect the wheels in one place
  3. Upload all wheels + the source distribution to PyPI

GitHub Actions

This repository includes GitHub Actions workflows that automatically build wheels for multiple platforms when a new release is created.

Requirements

  • Python 3.6+
  • cffi
  • numpy
  • chess
  • Stockfish (optional, for SFCChessEnv)
  • GCC with OpenMP support (for optimal performance)

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

fastchessenv-0.1.1.tar.gz (467.3 kB view details)

Uploaded Source

Built Distribution

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

fastchessenv-0.1.1-cp313-cp313-macosx_11_0_arm64.whl (276.3 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

File details

Details for the file fastchessenv-0.1.1.tar.gz.

File metadata

  • Download URL: fastchessenv-0.1.1.tar.gz
  • Upload date:
  • Size: 467.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for fastchessenv-0.1.1.tar.gz
Algorithm Hash digest
SHA256 98a797b8449a697dff715a4fe8e105f3471804eabcb350aa7778734680a88311
MD5 3bc7c1e2a4716bb2eebdd49a868a1a53
BLAKE2b-256 b1dc4c9f2862462533fd37921cd401bf35bd9d5426ee3417258f060fd59bdd86

See more details on using hashes here.

File details

Details for the file fastchessenv-0.1.1-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for fastchessenv-0.1.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 53411a4deb62a33a02f29246e587ab9fca5da21485486e7c3f268d1a1721e5ef
MD5 180603d0e7e6fc4aa3c78c1adfa4ff7e
BLAKE2b-256 66b1d1a63da47a3851425cfcdc8c7a8d9f73ec73d8eda61376a0cc174d57c209

See more details on using hashes here.

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