Skip to main content

NxNxN Rubik Cube implementation

Project description

MagicCube: A NxNxN Rubik Cube implementation

A fast implementation of the Rubik Cube based in Python 3.x.

Makes it easy to create cubes of various sizes (2x2x2, 3x3x3, 4x4x4, 6x6x6, ...., 100x100x100).

Fast rotation speed when compared with other Python implementations, which makes it suitable for Rubik Cube simulations.

Includes:

  • Simple solver for the 3x3x3 cube.
  • Move optimizer which reduces the number of moves.

Installation

pip install magiccube

Usage

import magiccube

# 3x3x3 Cube
cube = magiccube.Cube(3,"YYYYYYYYYRRRRRRRRRGGGGGGGGGOOOOOOOOOBBBBBBBBBWWWWWWWWW")
print(cube)

Cube

# Rotate the cube
cube.rotate("R' L2 U D' F B'2 R' L")

# Solve the 3x3x3 cube
from magiccube import BasicSolver
solver = BasicSolver(cube)
solver.solve()

# Complex moves 6x6x6 Cube
cube = magiccube.Cube(6)
cube.rotate("Lw") # L wide rotation
cube.rotate("Lw'") # L wide counter-rotation
cube.rotate("Lw2") # 2x L wide rotation
cube.rotate("3L") # 3rd line L rotation
cube.rotate("3Lw") # 3rd line L wide rotation
cube.rotate("3Lw'2") # 2x 3rd line L wide counter-rotation

# Get cube state
print("State:", cube.get())
# Get cube state in Kociemba order
print("State (Kociemba):", cube.get_kociemba_facelet_colors())

Documentation and Examples

Supported Moves and Notation

Uses SIGN notation, including advanced extensions.

Basic moves

Move
L L' Clockwise/Counterclockwise cube rotation of the LEFT face.
R R' Clockwise/Counterclockwise cube rotation of the RIGHT face.
D D' Clockwise/Counterclockwise cube rotation of the DOWN face.
U U' Clockwise/Counterclockwise cube rotation of the UP face.
F F' Clockwise/Counterclockwise cube rotation of the FRONT face.
B B' Clockwise/Counterclockwise cube rotation of the BACK face.

Advanced Moves

Move
X X' Cube rotation on X axis. X is the axis that points from LEFT to the RIGHT face.
Y Y' Cube rotation on Y axis. Y is the axis that points from DOWN to the UP face.
Z Z' Cube rotation on Z axis. Z is the axis that points from BACK to the FRONT face.
M M' Rotation of the center layer on the X axis.
E E' Rotation of the center layer on the Y axis.
S S' Rotation of the center layer on the Z axis.
Fw Fw' Wide rotation of 2 layers.
3Fw 3Fw' Wide rotation of 3 layers.
3F 3F' Rotation of the 3rd layer.
F2 F'2 2x rotation.

Cube Coordinates

  • Cube coordinates are expressed as a tuple of x,y,z.
  • (0,0,0) is the piece on the LEFT,DOWN,BACK corner.
  • In a 3x3x3, (2,2,2) is the piece on the RIGHT,UP,FRONT corner.

Solver

The solver uses the beginner method to solve the cube

Move Optimizer

The move optimizer does the following optimizations:

  • Eliminates redundant moves (ex: L L L L)
  • Converts 3x moves to the inverse (ex: F F F -> F')
  • Eliminates cube rotations (ex: Y F -> R)

Development

Install pyenv

curl https://pyenv.run | bash

Setup the environment using pyenv

pyenv install 3.11
pyenv virtualenv 3.11 cube
pyenv local cube
pip install -r requirements.txt
direnv allow

Install commit hooks

pre-commit install

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

magiccube-1.2.0.tar.gz (21.5 kB view details)

Uploaded Source

Built Distribution

magiccube-1.2.0-py3-none-any.whl (18.5 kB view details)

Uploaded Python 3

File details

Details for the file magiccube-1.2.0.tar.gz.

File metadata

  • Download URL: magiccube-1.2.0.tar.gz
  • Upload date:
  • Size: 21.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for magiccube-1.2.0.tar.gz
Algorithm Hash digest
SHA256 9761a71b4e7edcd370866e6907c5b8e0a5510150dc41c3d99c07644b1d6b5eb9
MD5 1012ab0f3fa78025561425b8ee567a01
BLAKE2b-256 b04e3e467076dd9b087de57d738edbe410e15259589d6bfd16e20bdf1f0a2444

See more details on using hashes here.

Provenance

The following attestation bundles were made for magiccube-1.2.0.tar.gz:

Publisher: release.yml on trincaog/magiccube

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file magiccube-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: magiccube-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 18.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for magiccube-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f6b114ae7ac413053be375afa43b9b022d93709af9c72806ad7b4ebdc90e3bc5
MD5 7f64aa430dad2272a8b57020f0133f2a
BLAKE2b-256 f8e109b31d2fcc0a6bce0a9531f5b9abf5c6b87594b3885157971b792de4da0e

See more details on using hashes here.

Provenance

The following attestation bundles were made for magiccube-1.2.0-py3-none-any.whl:

Publisher: release.yml on trincaog/magiccube

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page