High-performance core utilities for Quantik game state manipulation
Project description
Quantik Core
A high-performance Python library for manipulating Quantik game states, optimized for Monte Carlo simulations, game analysis, and AI engines.
What is Quantik?
Quantik is an elegant 4×4 abstract strategy game where players compete to complete lines with all four unique shapes.
Game Rules
- Board: 4×4 grid (16 squares)
- Pieces: 4 different shapes (A, B, C, D) in 2 colors (one per player)
- Objective: Be the first to complete a row, column, or 2×2 zone containing all four different shapes
- Gameplay:
- Players alternate placing one of their remaining pieces on an empty square
- A piece cannot be placed if the opponent already has the same shape in the target square's row, column, or 2×2 zone
- Colors don't matter for winning - only the presence of all four shapes in a line
Example Victory
A B C D ← Row with all 4 shapes = WIN!
. . . .
. . . .
. . . .
Features
This library provides the core foundation for building:
- Monte Carlo Tree Search (MCTS) engines
- Game analysis and position evaluation systems
- AI training and recommendation engines
- Opening book generation and endgame databases
- Statistical analysis of game patterns
- Game engines and tournament systems
- Research tools for combinatorial game theory
Current Implementation:
- State Representation: Complete bitboard-based game state management
- Serialization: Binary, QFEN, and CBOR formats
- Canonicalization: Symmetry-aware position normalization
- Move Generation: Coming in next release
- Game Logic: Win detection and move validation (planned)
Core Capabilities
- Blazing Fast Operations: Bitboard-based representation enables O(1) move generation and win detection
- Compact Memory Footprint: Game states fit in just 16 bytes with optional 18-byte canonical serialization
- Symmetry Normalization: Automatic canonicalization under rotations, reflections, color swaps, and shape relabeling
- Cross-Language Compatibility: Binary format designed for interoperability with Go, Rust, and other engines
- Human-Readable Format: QFEN (Quantik FEN) notation for debugging and documentation
- Self-Describing Serialization: CBOR-based format for robust data exchange
Installation
pip install quantik-core
Quick Start
from quantik_core import State
# Create an empty game state
state = State.empty()
# Create a position using QFEN notation
state = State.from_qfen("A.../..b./.c../...D")
# Convert to human-readable format
qfen = state.to_qfen()
print(f"Position: {qfen}") # Output: A.../..b./.c../...D
# Get canonical representation for symmetry analysis
canonical_key = state.canonical_key()
print(f"Canonical key: {canonical_key.hex()}")
# Serialize to binary format (18 bytes)
binary_data = state.pack()
restored_state = State.unpack(binary_data)
# Serialize to CBOR for cross-language compatibility
cbor_data = state.to_cbor(canon=True, meta={"game_id": 123})
restored_from_cbor = State.from_cbor(cbor_data)
Performance
- State Operations: Bitboard-based representation enables fast position manipulation
- Canonicalization: <1µs per position with precomputed lookup tables
- Memory Usage: 16 bytes per game state + 1MB for transformation LUTs
- Serialization: 18-byte binary format, human-readable QFEN, or self-describing CBOR
Use Cases
Position Analysis and Canonicalization
from quantik_core import State
# Create different equivalent positions
pos1 = State.from_qfen("A.../..../..../....")
pos2 = State.from_qfen("..../..../..../.a..") # Rotated + color swapped
# Both have the same canonical representation
assert pos1.canonical_key() == pos2.canonical_key()
Database Storage and Retrieval
# Use canonical keys as database indices
positions_db = {}
canonical_key = state.canonical_key()
positions_db[canonical_key] = {"eval": 0.75, "visits": 1000}
Cross-Language Data Exchange
# Save position with metadata for other engines
data = state.to_cbor(
canon=True,
mc=5000, # Monte Carlo simulations
meta={"depth": 12, "engine": "quantik-py-v1"}
)
# Binary format for high-performance applications
binary = state.pack() # Just 18 bytes
Technical Details
- Representation: 8 disjoint 16-bit bitboards (one per color-shape combination)
- Symmetries: Dihedral group D4 (8 rotations/reflections) × color swap × shape permutations = 384 total
- Serialization: Versioned binary format with little-endian 16-bit words
- Canonicalization: Lexicographically minimal representation across symmetry orbit
Contributing
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
License
MIT License - see LICENSE for details.
Citation
If you use this library in research, please cite:
@software{quantik_core,
title={Quantik Core: High-Performance Game State Manipulation},
author={Mauro Berlanda},
year={2025},
url={https://github.com/mberlanda/quantik-core-py}
}
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
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 quantik_core-0.1.0.tar.gz.
File metadata
- Download URL: quantik_core-0.1.0.tar.gz
- Upload date:
- Size: 12.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6e4dbbc86b3239d625b8515af0a690d0c8a6297bf7496762a3b6716546d8d229
|
|
| MD5 |
627766ba0d43a8f76db3d877b76d1bd7
|
|
| BLAKE2b-256 |
174c964fa63d9a3595eeb1c7b3635570ac26925a3935eb80e63404e1bb6ceee6
|
File details
Details for the file quantik_core-0.1.0-py3-none-any.whl.
File metadata
- Download URL: quantik_core-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e50ef4d36762f01762b9f59728be68d7a137705d2ac2623794883d647f17d69e
|
|
| MD5 |
d38a7777b270950a5d72bdf15a632a19
|
|
| BLAKE2b-256 |
229c530f48bf2c0451ecf88f6f25cae0fdcdd7fb5a2e841f2176c33b303d813d
|