A GDScript port of the min2phase algorithm for solving Rubik's cubes in Godot. This plugin provides optimal solutions using the two-phase algorithm.
- Download or clone this plugin
- Copy the
addons/min2phasefolder to your Godot project'saddons/directory - Enable the plugin in Project Settings → Plugins
- The
Min2PhaseInstanceautoload will be automatically available in your project
extends Node
func _ready():
# Generate a random scrambled cube
var scrambled_cube = Min2PhaseInstance.random_cube()
print("Scrambled: ", scrambled_cube)
# Solve the cube
var solution = Min2PhaseInstance.solve(scrambled_cube, 21)
print("Solution: ", solution)
# Generate random moves
var moves = Min2PhaseInstance.random_moves(20)
print("Random moves: ", moves)
# Apply moves to a cube
var cube_after_moves = Min2PhaseInstance.from_moves(moves)
print("Result: ", cube_after_moves)A high-performance scrambles solver is available here
The project includes a command-line tool scrambles_solver.gd for batch processing scramble files. This tool can solve multiple scrambles from a text file and output the solutions.
# Using the Makefile (recommended)
make solve scrambles=your_scrambles.txt
# Or directly with Godot
godot --headless --script ./scrambles_solver.gd your_scrambles.txtThe scrambles file should contain one scramble per line in standard notation (e.g., R U R' U' F2 D L2). Empty lines are ignored.
You can download official WCA scrambles from:
- Cube20 Distance-20 Positions - Known distance-20 positions in half-turn metric
- WCA Scrambles - Official competition scrambles
# Create a scrambles file
echo "R U R' U' F2 D L2" > my_scrambles.txt
echo "F R U R' U' F'" >> my_scrambles.txt
# Solve them
make solve scrambles=my_scrambles.txtThe cube is represented as a 54-character string following this layout:
+--------+
|U1 U2 U3|
|U4 U5 U6|
|U7 U8 U9|
+--------+--------+--------+--------+
|L1 L2 L3|F1 F2 F3|R1 R2 R3|B1 B2 B3|
|L4 L5 L6|F4 F5 F6|R4 R5 R6|B4 B5 B6|
|L7 L8 L9|F7 F8 F9|R7 R8 R9|B7 B8 B9|
+--------+--------+--------+--------+
|D1 D2 D3|
|D4 D5 D6|
|D7 D8 D9|
+--------+
The string format is: U1U2...U9R1R2...R9F1...F9D1...D9L1...L9B1...B9
Solved cube: UUUUUUUUURRRRRRRRRFFFFFFFFFDDDDDDDDDLLLLLLLLLBBBBBBBBB
Moves follow standard Rubik's cube notation:
- U, R, F, D, L, B: 90° clockwise turns
- U', R', F', D', L', B': 90° counterclockwise turns
- U2, R2, F2, D2, L2, B2: 180° turns
Examples:
R U R' U'- Right, Up, Right counter-clockwise, Up counter-clockwiseF2 R U' D2- Front 180°, Right, Up counter-clockwise, Down 180°
When solving fails, the function returns "Error X" where X is:
- 1: Invalid facelet string format
- 2: Invalid edge configuration
- 3: Edge orientation parity error
- 4: Invalid corner configuration
- 5: Corner orientation parity error
- 6: Permutation parity error between corners and edges
- 8: No solution found within move limit
- The solver typically finds solutions in 0.01-3.0 seconds for most cubes
- Some very rare hard cases can take up to 30 minutes
- Solutions are usually 15-25 moves in length
- The algorithm is deterministic - same input always gives same output
- For real-time applications, consider solving on a background thread
This plugin implements a simplified version of the two-phase algorithm:
- Phase 1: Reduce the cube to a subgroup where only certain moves are needed
- Phase 2: Solve the cube within that restricted subgroup
This plugin is released under the MIT License.