A 3D interactive Rubik’s Cube visualizer and solver built using OpenGL and C++, capable of solving any scrambled cube using the Breadth-First Search (BFS) algorithm. This project combines the logic of cube solving with real-time rendering and animation.
- 🎮 Interactive 3D Rubik’s Cube using OpenGL
- 🤖 Automatic solver using Breadth-First Search (BFS)
- 🔀 Random scrambler with valid move sequences
- 🎞️ Smooth cube rotation and layer-turn animations
- 🧠 Solves from any valid cube state
- 🪟 Simple keyboard/mouse controls
| Key | Action |
|---|---|
U, u |
Rotate Up face (clockwise/counterclockwise) |
D, d |
Rotate Down face |
L, l |
Rotate Left face |
R, r |
Rotate Right face |
F, f |
Rotate Front face |
B, b |
Rotate Back face |
S |
Auto-Solve the cube using BFS |
Arrow Keys |
Rotate the 3D cube view |
Q/E |
Zoom in/out (if implemented) |
This project uses Breadth-First Search (BFS) to solve the Rubik's Cube:
- Treats the cube as a state-space tree, where each node represents a cube state.
- Each edge corresponds to a valid move (e.g., U, R', F2).
- Performs a level-order traversal starting from the scrambled state.
- Stores visited states using a hash map or cube string representation to avoid revisiting.
- The goal is the solved state, and the first match guarantees the shortest move sequence.
Though BFS is not optimal for speed or memory in large-depth searches, it's sufficient for short scrambles and guarantees the shortest path in terms of moves.
- Language: C++
- Graphics API: OpenGL
- Math: GLM (optional), custom matrix logic
- Platform: Windows / Linux
- C++ Compiler (e.g., g++, clang++)
- OpenGL
- GLUT or FreeGLUT
- CMake (optional)
# Clone the repository
git clone https://github.com/Sparsh12321/Rubik-s-Cube-Solver-OpenGL.git
cd Rubik-s-Cube-Solver-OpenGL
# Compile (example using g++)
g++ main.cpp -o cube_solver -lGL -lGLU -lglut
# Run the executable
./cube_solver


