Skip to main content

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' L U D' F B' R' L")

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

# 6x6x6 Cube
cube = magiccube.Cube(6)
cube.rotate("Rw' Lw 3Uw'")

Examples

See examples folder.

Supported Moves and Notation

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.

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 RIGH,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)

Metadata

Release files for magiccube 0.0.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for magiccube 0.0.8
File Size Uploaded
magiccube-0.0.8.tar.gz 13.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for magiccube 0.0.8
File Interpreter ABI Platform
magiccube-0.0.8-py3-none-any.whl Python 3 none any Details

Total release size: 24.0 kB

Release files / magiccube-0.0.8.tar.gz

Download URL magiccube-0.0.8.tar.gz
Size 13.2 kB
Tags Source
SHA-256 checksum
How to use checksums
59830c3522d7924806eafad3ee2909a636901b2058878f81b74032b896288b3f
BLAKE2b-256 checksum
How to use checksums
416a86b59e4b51534bca5f24396a0ae7be19a3b804bd325dc34942eb6b3894b2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.12

Release files / magiccube-0.0.8-py3-none-any.whl

Download URL magiccube-0.0.8-py3-none-any.whl
Size 10.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1abab73973525fb5df2c3334b87c5a058062e6f096022b61f2291a046c34f010
BLAKE2b-256 checksum
How to use checksums
b64f0804833b47cf1a5a54f7e74b06c089029a57a9f901351ca5784f61701e64
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.12

Release history Release notifications | RSS feed

1.2.0

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.3.0

2 release files

0.0.10

2 release files

0.0.9

2 release files

This release

0.0.8 This release

2 release files

0.0.7

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page