GitHub - Giorgi-Kavtaradze/Rubik: 🧊 Rubik's Cube Simulator & Solver · GitHub
Skip to content
Giorgi-KavtaradzePublic

About

🧊 Rubik's Cube Simulator & Solver

Resources

Stars

2 stars

Watchers

0 watching

Forks

Latest commit

 

History

9 Commits

Folders and files

Repository files navigation

🧊 Rubik's Cube Simulator & Solver

Rust CI Crates.io Rust Version Bevy 0.15

Screenshot


Overview

A high-performance, cross-platform Rubik's Cube simulator and solver built in Rust. The application combines a mathematically rigorous cube state engine with a real-time 3D renderer, delivering smooth piece-by-piece rotation animations and an asynchronous Kociemba two-phase solver that never blocks the UI thread.

Whether you want to explore cube theory, visualize solutions step-by-step, or simply play with a virtual cube, this project provides a robust, production-grade foundation.


✨ Features

Core Engine

  • 54-Facelet State Representation — A deterministic, integer-based internal model that eliminates floating-point drift and hardware-dependent anomalies. Every state transition is a pure permutation.
  • Standard Move Notation — Full support for the 18 HTM (Half-Turn Metric) moves: U, D, F, B, L, R with clockwise, counter-clockwise, and 180° variants.
  • Scrambler — Generates valid random scramble sequences with configurable length, avoiding consecutive same-face moves.

3D Visualization

  • Orbital Camera — Fully controllable 360° camera with smooth zoom and pan, powered by Bevy's ECS architecture.
  • Smooth Animations — Per-cubelet rotation animations with configurable duration, using quaternion-based interpolation for artifact-free motion.
  • Sticker Rendering — Individual sticker quads with a physically accurate sRGB color palette matching official WCA standards.

Solver

  • Kociemba Two-Phase Algorithm — Integrated via the kewb crate, running on a dedicated thread with an 8 MB stack to prevent overflow on Windows.
  • Asynchronous Execution — Solving runs in a background thread with a channel-based result pipeline, keeping the UI fully responsive.
  • Cached Data Tables — The solver's pruning table is generated once and cached to the platform's standard cache directory (XDG_CACHE_HOME on Linux, ~/.cache on macOS, %LOCALAPPDATA% on Windows).

HUD & Analytics

  • Real-Time Status — Color-coded indicators for SOLVED, UNSOLVED, CALCULATING..., and SOLVING... states.
  • Solve Statistics — Tracks solve count, last solution length and duration, and running averages (steps, time, and throughput).

Cross-Platform

  • Compiles natively on Linux, macOS, and Windows with no platform-specific dependencies beyond the standard Rust toolchain.

🚀 Getting Started

Prerequisites

  • Rust 1.85+ (Edition 2024) — Install via rustup

Build & Run

# Clone the repository
git clone https://github.com/GiorgiKavtaradze-prog/Rubik.git
cd Rubik

# Run in release mode (recommended for optimal solver performance)
cargo run --release

# Or build a release binary
cargo build --release

Note: The first run will generate the Kociemba pruning table, which may take several minutes. The table is cached for subsequent runs.

Build Without Graphics (Headless / Testing)

The graphics feature is optional. You can build the core engine and solver without the Bevy rendering dependency:

cargo build --no-default-features
cargo test --no-default-features

🎮 Controls

Camera

Action Input
Orbit / Rotate Left Click + Drag
Zoom Scroll Wheel

Face Rotations (Manual)

Use the keyboard to rotate faces using standard Rubik's notation:

Key Move With Shift
U Up face — Clockwise Up face — Counter-Clockwise
D Down face — Clockwise Down face — Counter-Clockwise
F Front face — Clockwise Front face — Counter-Clockwise
B Back face — Clockwise Back face — Counter-Clockwise
R Right face — Clockwise Right face — Counter-Clockwise
L Left face — Clockwise Left face — Counter-Clockwise

Engine Triggers

Key Action
S Scramble — Applies a 20-move random scramble with animation
Space Solve — Triggers the Kociemba solver and plays the solution animation

🏗️ Architecture

src/
├── main.rs              # Bevy application entry point, ECS systems, and event loop
├── lib.rs               # Library crate root with feature-gated modules
├── cube/                # Core cube state engine
│   ├── cubie.rs         # 54-facelet Cube struct with permutation logic
│   ├── moves.rs         # Move and Face types with standard notation
│   ├── state.rs         # Facelets representation for rendering
│   └── scrambler.rs     # Random scramble sequence generator
├── render/              # 3D visualization layer (Bevy)
│   ├── cube3d.rs        # Cubelet and sticker mesh spawning
│   └── animation.rs     # Rotation animation state machine
├── solver/              # Solving algorithms
│   ├── kociemba_solver.rs  # Kewb-based two-phase solver with caching
│   ├── stats.rs         # Solve statistics tracking
│   └── idas.rs          # (Deprecated) IDA* solver for shallow scrambles
└── ui/                  # Heads-up display
    └── hud.rs           # Status, stats, and help text rendering

Key Design Decisions

  • Pure Permutation Model — The cube state is represented as a [u8; 54] array. All moves are deterministic permutations, ensuring reproducibility across platforms and runs.
  • ECS Architecture — The Bevy engine uses an Entity-Component-System pattern, with cubelets as entities and transforms/animations as components.
  • Thread-Isolated Solver — The Kociemba solver runs on a dedicated thread with an explicit 8 MB stack, communicating results back via a std::sync::mpsc channel polled each frame.
  • Feature Flags — The graphics feature gates all Bevy-dependent code, allowing headless testing of the core engine and solver.

🧪 Testing

# Run all tests (including integration tests)
cargo test

# Run tests without graphics dependencies
cargo test --no-default-features

# Run with output
cargo test -- --nocapture

The test suite includes:

  • Identity verification — Four sequential turns of any face return to the solved state.
  • Inverse move validation — Applying the inverse of a scramble sequence restores the cube.
  • Solver integration — The Kociemba solver produces valid solutions for random scrambles.

🛠️ Built With

Technology Purpose
Rust Systems programming language
Bevy 0.15 Data-driven game engine for 3D rendering
kewb Kociemba's Two-Phase Algorithm implementation
rand Cryptographically secure scramble generation
rcuber Cube representation utilities

📄 License

This project is licensed under the MIT License — see the LICENSE file for details.


🤝 Contributing

Contributions are welcome! Please feel free to submit issues or pull requests.

  1. Fork the repository
  2. Create a feature branch (git checkout -b feat/your-feature)
  3. Commit your changes (git commit -m 'Add your feature')
  4. Push to the branch (git push origin feat/your-feature)
  5. Open a pull request

Made with ❤️ and Rust.

About

🧊 Rubik's Cube Simulator & Solver

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages