This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is a Python implementation of the traditional Sami board game Dablo with reinforcement learning capabilities. The project has two main components:
- Core Game Engine (
dablo/core/) - Complete implementation of Dablo game rules and mechanics - RL Training System (
dablo/rl/) - Gymnasium environment wrapper for training agents with Stable Baselines 3
# Install dependencies
uv sync
# Install with dev dependencies
uv sync --group dev# Run all tests
pytest
# Run tests with coverage
pytest --cov=dablo
# Run specific test file
pytest tests/test_core/test_game.py
# Run tests matching pattern
pytest -k "test_capture"# Format and lint code
ruff format
ruff check
# Fix auto-fixable issues
ruff check --fix# Play Dablo interactively
python play_dablo.py
# Run performance tests between AI players
python performance_test.py# Train RL model with default config
python train_dablo_rl.py --config configs/default.json
# Train with self-play
python train_dablo_rl.py --config configs/selfplay_training.json
# Evaluate trained model
python evaluate_model.py --model_path models/dablo_model.zipDabloGame- Main game state manager with cached board graphs and optimized piece trackingGameRules- Handles move validation, capture sequences, and win conditionsPieceTracker- Event-driven piece position tracking for performance optimizationDabloConfig- Pydantic-based configuration with JSON support for different board setups
DabloRLEnvironment- Gymnasium wrapper implementing action masking for MaskablePPODabloActionSpace- Handles complex move encoding (source→destination with capture positions)DabloObservationSpace- Multi-dict observation space (board state, piece counts, game flags)DabloSelfPlayManager- Manages opponent pools and adaptive self-play training
- Caching Strategy: Board graphs and piece setups are class-level cached for performance
- Event-Driven Updates:
PieceTrackeruses event callbacks to maintain piece positions efficiently - Configuration-Based Training: JSON configs in
configs/directory define all training parameters - Action Masking: Invalid moves are masked during RL training for efficiency
- Graph-based Board: Uses coordinate system with primary (integer) and secondary (half-integer) nodes
- Chain Captures: Mandatory capture sequences like checkers - pieces must continue capturing if possible
- Piece Hierarchy: Warriors < Princes < Kings (capture rules based on hierarchy)
- Win Conditions: Capture opponent's king, reduce them to king only, or cause stalemate
The test suite uses comprehensive fixtures in tests/conftest.py:
- Game State Fixtures:
simple_capture_game,endgame_scenario,optional_chain_capture_scenario - Factory Fixtures:
game_factoryfor parameterized testing - Assertion Helpers:
assert_valid_move,assert_game_state_consistent - Performance Monitoring: Auto-detects slow tests (>1s)
All training configurations are JSON-based in the configs/ directory:
default.json- Basic RL training setupselfplay_training.json- Self-play with opponent poolsproduction_training.json- High-performance training settingsquick_training.json- Fast training for development
Configs use nested structure: game_config, reward_config, training_config, evaluation_config, etc.
- Board graphs are cached at class level to avoid recreation
- Piece tracking uses event callbacks rather than full board scans
- Action masking prevents invalid move exploration during training
- Vectorized environments (
n_envs) supported for parallel training