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.0.tar.gz (361.9 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.0-cp313-cp313-macosx_11_0_arm64.whl (146.4 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: fastchessenv-0.1.0.tar.gz
  • Upload date:
  • Size: 361.9 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.0.tar.gz
Algorithm Hash digest
SHA256 c8b57aee4d2fa127422bd5dbc6d7e89c5340a381dad1f782f4fcf5cafe7d2029
MD5 f5160ee3f9e42c408bd7feb2d1c5df2f
BLAKE2b-256 fe2f6b038a56a590e8930ecfbd5e6b12ef43d1dbad098107d0d4341869bd52bf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastchessenv-0.1.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d3d90e6d8a1024513594664ea519e0b8c932696462a0b643c0766d941e5bdbba
MD5 49d43cdb6e021e2e867970158ad48a06
BLAKE2b-256 1f79a6e9653ed77dc80bb3c644e0a8574b1ca42162310fc292881e04dfb2b66e

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