- Models a 3×3 Rubik’s Cube (3D array, 1D array, bitboard).
- Solves using DFS, BFS, IDDFS, and IDA*.
- Uses a Corner Pattern Database heuristic for IDA* (
Databases/cornerDepth5V1.txt).
brew install cmake gcc
cd /Users/you/path/to/rubiks-cube-solver-main
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=$(ls /opt/homebrew/bin/gcc-*) -DCMAKE_CXX_COMPILER=$(ls /opt/homebrew/bin/g++-*)
cmake --build build -j
./build/rubiks_cube_solverIf you already have Homebrew GCC (e.g., g++-15):
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=/opt/homebrew/bin/gcc-15 -DCMAKE_CXX_COMPILER=/opt/homebrew/bin/g++-15
cmake --build build -j && ./build/rubiks_cube_solver- Input: No external input required.
main.cppshuffles the cube randomly and then solves it using IDA* + Corner DB.- Shuffle depth is set in
main.cppviarandomShuffleCube(13). - Corner DB file path is relative:
Databases/cornerDepth5V1.txt.
- Shuffle depth is set in
- Output: The program prints
- Initial shuffled cube (planar format),
- The move sequence to solve,
- The final solved cube state.
Example run output (truncated):
Rubik's Cube:
... shuffled state ...
B R' L' ...
Rubik's Cube:
... solved state ...
main.cpp contains commented code to generate the corner DB using CornerDBMaker.
Steps:
- Ensure
string fileName = "Databases/cornerDepth5V1.txt";inmain.cpp. - Uncomment the "Code to create Corner Database" lines:
// CornerDBMaker dbMaker(fileName, 0x99); // dbMaker.bfsAndStore();
- Build and run once to generate the file. Then re-comment those lines to run the solver without regenerating.
- Requires GCC because the code uses
<bits/stdc++.h>. - Adjust
randomShuffleCube(depth)inmain.cppto change scramble depth.