MagicCube

1.2.0 · active · verified Fri Apr 17

MagicCube is a Python library providing an NxNxN Rubik's Cube implementation. It allows for cube manipulation, scrambling, and solving (including Kociemba's algorithm). The current stable version is 1.2.0, with ongoing development reflected in beta releases, though stable releases are less frequent.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to instantiate a cube, scramble it, retrieve its state in Kociemba format, solve it using the Kociemba solver, and apply the solution.

from magiccube import Cube
from magiccube.cube import Move
from magiccube.solver import KociembaSolver

# Create a 3x3x3 cube
c = Cube(3)

# Scramble the cube
c.scramble(count=25)
print('Scrambled cube:')
print(c)

# Get facelet colors in Kociemba format
kociemba_colors = c.get_kociemba_facelet_colors()
print(f'Kociemba facelet colors: {kociemba_colors}')

# Solve the cube using Kociemba's algorithm
solver = KociembaSolver(c)
solution = solver.solve()
print(f'Solution: {solution}')

# Apply the solution to verify
c.rotate(solution)
print('Solved cube:')
print(c)
assert c.is_solved()

view raw JSON →