Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hichemtab-tech/rubikscube-threejs
Rubik's cube solver implemented in JavaScript. The solver operates on a 3x3 Rubik's cube and employs an algorithm based on base solver and transformations to solve the cube.
https://github.com/hichemtab-tech/rubikscube-threejs
game game-development javascript rubik-cube rubiks-cube rubiks-cube-simulator rubiks-cube-solver threejs
Last synced: about 2 months ago
JSON representation
Rubik's cube solver implemented in JavaScript. The solver operates on a 3x3 Rubik's cube and employs an algorithm based on base solver and transformations to solve the cube.
- Host: GitHub
- URL: https://github.com/hichemtab-tech/rubikscube-threejs
- Owner: HichemTab-tech
- License: mit
- Created: 2024-01-31T14:20:22.000Z (11 months ago)
- Default Branch: master
- Last Pushed: 2024-06-02T00:01:05.000Z (7 months ago)
- Last Synced: 2024-06-03T00:41:58.458Z (7 months ago)
- Topics: game, game-development, javascript, rubik-cube, rubiks-cube, rubiks-cube-simulator, rubiks-cube-solver, threejs
- Language: JavaScript
- Homepage: https://hichemtab-tech.github.io/RubiksCube-threejs/
- Size: 306 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Rubik's Cube Solver
This project is a Rubik's cube solver implemented in JavaScript. The solver operates on a 3x3 Rubik's cube and employs an algorithm based on base solver and transformations to solve the cube.
## Demo
The Rubik's Cube Solver is available as a web application. You can access the demo [here](https://hichemtab-tech.github.io/RubiksCube-threejs/).
## Algorithm
The algorithm is based on the [CFOP method](https://ruwix.com/the-rubiks-cube/how-to-solve-the-rubiks-cube-beginners-method/). Which is programmed in this project under these steps:
### Step 1
Identify the positioning of the cubes, which are categorized into **edges** and **diagonals**. Each cube has an associated color. The **solver** identifies the colors and their location to determine the initial state of the Rubik's Cube.### Step 2
The **solver** then calculates the **movement plan** to reach the solved state. This is performed by following a pre-defined `road` that describes how the cube's faces should be moved.
This process involves rotating the cube faces in a specific way using the `#move` function. This function takes the face ID and a boolean value to determine whether the rotation should be **clockwise** or **counterclockwise**.### Step 3
The `#getIndexesRoad` function is used to understand the transformation between the old face ID and the new one. It calculates the sequence of moves to transport a cube piece from its old location (old face ID) to its new location (new face ID).### Step 4
The `#getIndexBySide` function is used to understand the sides of each cube. It determines the relative position on the face of a cube using the cube indices.### Step 5
If the cube is on the edge, the `#getCubes` function takes care of moving it to its correct position, respecting the global color scheme of the Rubik's Cube.### End Step
After going through these algorithmic steps, the Rubik's Cube should be in its solved state. Calculations based on the cube's state ensure that the solver continues to execute until the cube is solved.
This algorithm essentially mimics the way a human would solve a Rubik's Cube, by understanding the positioning, planning the movements, and then executing those movements until the puzzle is solved._**Disclaimer**: This is a high-level summarization of the algorithm used in this project, for more detailed understanding I recommend going through the source code._