Skip to main content

A mathematically consistent N×N×N Rubik's Cube simulation library.

Project description

PaperCube

A mathematically consistent N×N×N Rubik's Cube simulation library designed primarily for algorithmic research and development.

Built in modern C++20, PaperCube provides a highly optimized, zero-allocation math engine for Reinforcement Learning (RL) and search algorithms, coupled with native Python bindings via Pybind11.

Core API Features

The library exposes a minimal, highly optimized surface area tailored specifically for algorithmic manipulation and state space exploration:

  • Cube::State & High-Performance Hashing: Provides an immutable, zero-allocation snapshot of the cube's permutation. States are inherently hashable out-of-the-box (utilizing blazing-fast std::string_view casting in C++ and native __hash__ in Python). This allows state objects to be dropped directly into standard unordered maps, sets, or Python dictionaries for graph search algorithms (A*, BFS) with zero friction.
  • The Cube Engine: The central mutating simulation class. It supports any physical dimension (NxNxN) and handles in-place physical rotations (apply_move), bulk sequence execution (apply_move_sequence), and rapid randomization (scramble).
  • Move & Action Space Mapping: Represents physical rotations with strict geometric parameters (Axis, Direction, Layer). Includes built-in ML utility functions like from_action_index to seamlessly map flat 1D integer outputs (e.g., from a neural network) directly to 3D physical actions.
  • Chronological History Tracking: The engine natively tracks every mutation applied to the cube (get_move_history), allowing algorithms to instantly extract the exact move sequence that led to a discovered solution state without manual bookkeeping.

Project Structure

  • /core: The standalone C++ library and mathematical engine.
  • /python: Pybind11 wrapper generating the .pyd module.
  • /tests: Pytest and GoogleTest suites verifying mathematical consistency and Python interop.

Installation & Build

PaperCube can be consumed purely as a Python library for algorithmic research, or compiled from source as a C++20 library.

Python (pip)

For Python users, PaperCube is available directly from PyPI. The installation includes pre-generated .pyi stubs, providing full IntelliSense and autocomplete support in modern IDEs.

pip install papercube

(Note: As a source distribution, pip requires a C++ compiler installed on your system to build the engine locally).

C++ (CMake)

PaperCube uses standard CMake. The build process automatically fetches Pybind11 and GoogleTest, requiring zero manual external dependencies.

Prerequisites:

  • A C++20 compatible compiler (MSVC, GCC, or Clang)
  • CMake 3.15+
# 1. Clone the repository
git clone [https://github.com/ayush00soni/PaperCube.git](https://github.com/ayush00soni/PaperCube.git)
cd PaperCube

# 2. Build with CMake
mkdir build && cd build
cmake ..
cmake --build . --config Release

Python Quickstart

You can import papercube directly into your Python scripts or Jupyter Notebooks to begin simulating state spaces.

import papercube

# Initialize a standard 3x3x3 cube
c = papercube.Cube(3)

# Verify the initial state is solved
print(f"Is solved? {c.state().is_solved()}")

# Apply a sequence of 20 random valid moves
c.scramble(20)

# Check the chronological history of mutations
history = c.get_move_history()
print(f"Total moves applied: {len(history)}")

# Reset the mechanics to a solved state
c.reset()

C++ Quickstart

You can easily link the core math engine (papercube_core) to your own C++ targets.

#include <papercube/cube.hpp>
#include <iostream>

int main() {
    papercube::Cube c(4); // 4x4x4 Cube
    
    // Apply a sequence using encoded action indices
    c.apply_move(4);
    c.apply_move(12);
    
    if (!c.state().is_solved()) {
        std::cout << "Cube successfully scrambled.\n";
    }
    
    c.reset();
    return 0;
}

Testing

PaperCube includes a rigorous, mathematically verified test suite across both environments.

# Run C++ GoogleTests
cd build
ctest --output-on-failure

# Run Python Pytests
cd ..
pytest tests/

Upcoming Features (Future Versions)

  • GUI Visualization Layer: A decoupled, secondary desktop application designed to read state data and visually render the N-dimensional cube. This will allow developers to animate and debug algorithmic solutions in real-time.
  • Standard Notation String Parser: Core API support for parsing standard Singmaster move notation (e.g., U R2 F' B D2) directly into executable papercube::Move sequences.
  • Direct Piece Array Accessors: Exposing zero-copy, read-only getters for the internal corners, edges, and centers arrays. This will allow advanced coordinate-based solvers (like Kociemba's two-phase algorithm) to directly query exact piece permutations and orientations, bypassing the need to decode the flattened 1D facelet state.

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

papercube-1.0.3.tar.gz (56.4 kB view details)

Uploaded Source

Built Distribution

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

papercube-1.0.3-cp313-cp313-win_amd64.whl (3.0 MB view details)

Uploaded CPython 3.13Windows x86-64

File details

Details for the file papercube-1.0.3.tar.gz.

File metadata

  • Download URL: papercube-1.0.3.tar.gz
  • Upload date:
  • Size: 56.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for papercube-1.0.3.tar.gz
Algorithm Hash digest
SHA256 e996a6afdd8a1ca736fe7014630827f9fb77981becea263ccef9d210cd0cc9a9
MD5 79e91a39fc46212401a6c2a7160f9320
BLAKE2b-256 912f6bf555e6c998dec0c6b28e16f175fb52d434115ed7020f171f6e45113d88

See more details on using hashes here.

File details

Details for the file papercube-1.0.3-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: papercube-1.0.3-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 3.0 MB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for papercube-1.0.3-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 c5c745001bfa2f37c03b04a877411a712135f0a1e94928c38bf5eddf783a88a1
MD5 12c2cd9348766e4fb48e9a14d51a7d2d
BLAKE2b-256 a8d12e1a6680d8553144f428520df531b3a0960fe9c14a8c40850f717171226b

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