A C++17 Rubik's Cube solver built around object-oriented cube modeling, interchangeable state representations, and informed search. The project implements DFS, BFS, IDDFS, and IDA* across the same cube interface, and uses a corner pattern database heuristic to guide IDA* search.
- Three interchangeable cube representations:
- 3D array
- 1D array
- bitboard
- A shared
RubiksCubeabstraction with common move, shuffle, print, and corner-inspection helpers. - Search implementations for DFS, BFS, IDDFS, and IDA*.
- Hashable cube states so the representations can be used directly with
unordered_mapandunordered_set. - A corner pattern database stored in a compact nibble array for fast heuristic lookup.
- Binary persistence for the heuristic table so the database can be generated once and reused.
The cube is modeled as a reusable domain object rather than a single concrete structure. Each representation exposes the same move semantics and solved-state logic, which makes it possible to compare algorithm behavior and state-storage trade-offs without changing the solver logic itself.
The current demo path in src/main.cpp:
- loads the corner database from disk if it exists,
- generates it with BFS if the file is missing,
- scrambles a cube,
- runs IDA* with the pattern database heuristic,
- prints the scramble and the solved state.
The repository contains three concrete cube models under Model/.
RubiksCube3dArray stores the cube as vector<vector<vector<char>>> and is straightforward to inspect and debug.
RubiksCube1dArray stores all 54 stickers in a flat vector<char> for a denser layout.
RubiksCubeBitboard packs each face into a compact 64-bit representation, which keeps the state small and makes the comparison and hash logic lightweight.
All three implementations provide the same face-turn methods and override equality and hashing support, which allows them to be used in standard hashed containers during search.
The solver folder includes these implementations:
BFSSolver.hDFSSolver.hIDDFSSolver.hIDAStarSolver.h
DFS, BFS, and IDDFS are present as alternate search strategies for comparison. The active solver path uses IDA*, which keeps the memory footprint lower than BFS while still using heuristic guidance to reduce the search space.
The heuristic is based on corner-state information only.
CornerPatternDatabasemaps a cube state to a database index using corner permutation rank plus corner orientation.CornerDBMakerbuilds the database with BFS from the solved state and stores the discovered depths.NibbleArraystores two 4-bit values per byte, so the heuristic table is packed densely on disk and in memory.
The current database size is derived from corner permutation and orientation:
Stored as 4-bit entries, that is about 44,089,920 bytes, or roughly 42 MB.
- The solver code uses templates so the same algorithm can run on any cube representation that exposes the shared interface and hash/equality support.
- The cube move set is the standard 18-turn face metric: quarter turns, inverse turns, and double turns for all six faces.
- The repository keeps older DFS/BFS/IDDFS experiments in commented code inside
main.cpp, which makes the file a useful experiment harness for comparing search strategies. - The project uses
unordered_mapandunordered_setinternally for visited-state tracking and parent reconstruction. - The pattern database is persisted as a binary file, so it does not need to be regenerated on every run once created.
Model/- cube abstraction and the three concrete cube backendsSolver/- DFS, BFS, IDDFS, and IDA* implementationsPatternDatabases/- pattern database storage, indexing, and generationDatabase/- saved heuristic artifactsbuild/- local CMake build output
Requirements:
- CMake 3.20 or newer
- A C++17-capable compiler
Build from the repository root:
cmake -S . -B build
cmake --build buildThe executable target is named cube and is written to the build directory.
Run the executable from the build directory.
./cubeOn Windows PowerShell:
.\build\cube.exeThe current demo in main.cpp uses a hardcoded path for the corner database file. If you are running the project from a different checkout location, update that path to a repository-relative path such as Database/cornerDepth5V1.txt.
If the database file is missing, the program generates it before solving.
The Database/ directory currently contains:
cornerDepth5V1.txt- the corner pattern database used by the demo
main.cppis set up as a demo and benchmarking entry point rather than a final CLI.- The cube code uses
<bits/stdc++.h>, which keeps the project compact but ties it to toolchains that provide that header. - No license file is currently present in the repository.