Skip to content

Sparsh12321/Rubik-s-Cube-Solver-OpenGL-

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 

Repository files navigation

🧊 Rubik's Cube Solver - OpenGL

C++ License Platform

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.


✨ Features

  • 🎮 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

📸 Demo

IMG-20250715-WA0009 IMG-20250715-WA0007 IMG-20250715-WA0006 IMG-20250715-WA0008


🎮 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)

🧠 Algorithm - BFS Explained

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.


🛠️ Tech Stack

  • Language: C++
  • Graphics API: OpenGL
  • Math: GLM (optional), custom matrix logic
  • Platform: Windows / Linux

🚀 Getting Started

🔧 Requirements

  • C++ Compiler (e.g., g++, clang++)
  • OpenGL
  • GLUT or FreeGLUT
  • CMake (optional)

🔨 Build & Run

# 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

About

Rubik's Cube Solver in OpenGL

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages