Pure, stateless game operations: deterministic, replay-able game state management
Project description
PUREFN
Pure, stateless game engines: deterministic, replay-able game state management
PUREFN is a collection of functional game engines where every operation is a pure function. No database, no side effects—just token in → token out.
Core Principles
- Stateless: All game state lives in compact, portable tokens
- Deterministic: Same seed + same operations = same results, every time
- Pure Functions: No hidden state, no I/O in the core
- JSON API: CLI reads/writes JSON for seamless agent integration
Games
PUREFN includes three game engines:
Cards
Stateless 52-card deck with named players and deterministic shuffling.
# Create a deck
DECK=$(purefn cards deck poker-night | jq -r .deck)
# Deal to players
DECK=$(purefn cards deal $DECK alice 5 | jq -r .deck)
DECK=$(purefn cards deal $DECK bob 5 | jq -r .deck)
# View hands
purefn cards view all $DECK --human
Operations: deck, deal, discard, trade, exchange, view
Token format: d.<base64-json>
Cards Documentation | Cards Specification
Chess
Stateless board manipulation with no rule validation—maximum flexibility for analysis and variants.
# Create a board
BOARD=$(purefn chess new | jq -r .board)
# Make moves (no validation)
BOARD=$(purefn chess move $BOARD e2 e4 | jq -r .board)
BOARD=$(purefn chess move $BOARD e7 e5 | jq -r .board)
# View position
purefn chess view $BOARD --human
Operations: new, move, place, remove, clear, import, export, view
Token format: c.<base64-fen>
Chess Documentation | Chess Specification
Protocol
Cryptographic rule inference game for testing AI procedural learning.
# Initialize a game
export PROTOCOL_SECRET_KEY="your_secret_key"
purefn protocol init --seed 42 --team alpha,beta --profile DEV
# Scout actions
purefn protocol act --scout alpha look
purefn protocol act --scout alpha move HALL_S1_01
purefn protocol act --scout alpha probe 0x3F
Operations: init, status, map, act (move/look/probe/respond), export
State: File-based (protocol_state.json)
Protocol Documentation | Protocol Specification
Installation
# Clone and install
git clone https://github.com/botassembly/purefn.git
cd purefn
pip install -e .
# With dev dependencies
pip install -e ".[dev]"
JSON Envelope API
For agent integration, use the envelope format via purefn run:
echo '{
"game": "cards",
"op": "deal",
"global": "d.eyJzZWVk...",
"args": {"player": "alice", "num_cards": 5}
}' | purefn run
Response:
{
"ok": true,
"global": "d.eyJzZWVk...",
"views": {"player": "alice", "hand": ["AS", "KH", "7D"]},
"commit": "a3f2..."
}
Demos
Run the included demos to see the engines in action:
# Run all demos
./demos/run_all.sh
# Run individual demos
./demos/cards/run.sh
./demos/chess/run.sh
./demos/protocol/run.sh
Testing
# Run all tests
make test
# Run with coverage
make coverage
# Run linting and type checks
make check
Project Structure
purefn/
├── src/purefn/ # Main package
│ ├── core/ # PRNG, codecs, registry, result types
│ ├── games/ # Game engines
│ │ ├── cards/ # Cards engine
│ │ ├── chess/ # Chess engine
│ │ └── protocol/ # Protocol engine
│ └── cli/ # CLI commands
├── docs/ # User documentation
│ ├── cards.md
│ ├── chess.md
│ └── protocol.md
├── spec/ # Technical specifications
│ ├── cards/
│ ├── chess/
│ └── protocol/
├── demos/ # Demo scripts
├── tests/ # Test suite
└── schemas/ # JSON schema validation
Why PUREFN?
For AI agents:
- Deterministic environments for training and testing
- JSON in/out for seamless integration
- Stateless tokens are portable and cacheable
For game simulations:
- Fast, reproducible game state
- No database overhead
- Branch and explore game trees with tokens
For testing:
- Pure functions are trivially testable
- Property-based testing for invariants
- Replay any game from seed + operations
License
MIT License - see LICENSE file
Contributing
Contributions welcome! Please:
- Follow the pure functional design principles
- Add tests for new operations
- Ensure determinism and batching invariance
- Update docs and specs as needed
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file purefn-0.0.0.dev1.tar.gz.
File metadata
- Download URL: purefn-0.0.0.dev1.tar.gz
- Upload date:
- Size: 44.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
98c559ff0602d301dd1da893727fe7eeca333b3d2b6c5613a7a445ee80a5855b
|
|
| MD5 |
7cf0a61de70565965846340b2d66a298
|
|
| BLAKE2b-256 |
e4cf7dba129c02fddd43681d30de07f154db00e7abb762ac2d7c61d5109995d0
|
Provenance
The following attestation bundles were made for purefn-0.0.0.dev1.tar.gz:
Publisher:
on-release-main.yml on botassembly/purefn
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
purefn-0.0.0.dev1.tar.gz -
Subject digest:
98c559ff0602d301dd1da893727fe7eeca333b3d2b6c5613a7a445ee80a5855b - Sigstore transparency entry: 778362860
- Sigstore integration time:
-
Permalink:
botassembly/purefn@1c283bbde063c5987ec14c376fc8ed62287b5f09 -
Branch / Tag:
refs/tags/v0.0.0dev1 - Owner: https://github.com/botassembly
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
on-release-main.yml@1c283bbde063c5987ec14c376fc8ed62287b5f09 -
Trigger Event:
release
-
Statement type:
File details
Details for the file purefn-0.0.0.dev1-py3-none-any.whl.
File metadata
- Download URL: purefn-0.0.0.dev1-py3-none-any.whl
- Upload date:
- Size: 54.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0ab2de0bd4997b643ca190ea03cb4c6cfd32fb53fb1c6a7f224ed91d2b2d74f2
|
|
| MD5 |
fe603d3e4a69caf41fd44b4ebfa1d1cc
|
|
| BLAKE2b-256 |
1bfdedb4f13a5574b08bd7b172da0b1b3fbdde535976e6621f5b27f619c3c5a4
|
Provenance
The following attestation bundles were made for purefn-0.0.0.dev1-py3-none-any.whl:
Publisher:
on-release-main.yml on botassembly/purefn
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
purefn-0.0.0.dev1-py3-none-any.whl -
Subject digest:
0ab2de0bd4997b643ca190ea03cb4c6cfd32fb53fb1c6a7f224ed91d2b2d74f2 - Sigstore transparency entry: 778362869
- Sigstore integration time:
-
Permalink:
botassembly/purefn@1c283bbde063c5987ec14c376fc8ed62287b5f09 -
Branch / Tag:
refs/tags/v0.0.0dev1 - Owner: https://github.com/botassembly
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
on-release-main.yml@1c283bbde063c5987ec14c376fc8ed62287b5f09 -
Trigger Event:
release
-
Statement type: