Skip to content

suhasparuchuri/RubiksCubeSolver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rubik's Cube Solver

What this project does

  • 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).

Build and run (macOS, Homebrew)

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_solver

If 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 / Output

  • Input: No external input required. main.cpp shuffles the cube randomly and then solves it using IDA* + Corner DB.
    • Shuffle depth is set in main.cpp via randomShuffleCube(13).
    • Corner DB file path is relative: Databases/cornerDepth5V1.txt.
  • 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 ...

Regenerate Corner Pattern Database (optional)

main.cpp contains commented code to generate the corner DB using CornerDBMaker. Steps:

  1. Ensure string fileName = "Databases/cornerDepth5V1.txt"; in main.cpp.
  2. Uncomment the "Code to create Corner Database" lines:
    // CornerDBMaker dbMaker(fileName, 0x99);
    // dbMaker.bfsAndStore();
  3. Build and run once to generate the file. Then re-comment those lines to run the solver without regenerating.

Notes

  • Requires GCC because the code uses <bits/stdc++.h>.
  • Adjust randomShuffleCube(depth) in main.cpp to change scramble depth.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published