Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

License

NotificationsYou must be signed in to change notification settings

trincaog/magiccube

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

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

Cube

# Rotate the cubecube.rotate("R' L2 U D' F B'2 R' L")# Solve the 3x3x3 cubefrommagiccubeimportBasicSolversolver=BasicSolver(cube)solver.solve()# Complex moves 6x6x6 Cubecube=magiccube.Cube(6)cube.rotate("Lw")# L wide rotationcube.rotate("Lw'")# L wide counter-rotationcube.rotate("Lw2")# 2x L wide rotationcube.rotate("3L")# 3rd line L rotationcube.rotate("3Lw")# 3rd line L wide rotationcube.rotate("3Lw'2")# 2x 3rd line L wide counter-rotation# Get cube stateprint("State:",cube.get())# Get cube state in Kociemba orderprint("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'22x 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 thebeginner 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

Setup the environment using UV

InstallUV

pip install uv

Setup the environment

uv python install 3.11uv python pin 3.11uv syncdirenv allowpre-commit install

Setup the environment using pyenv

Installpyenv

curl https://pyenv.run| bash

Setup the environment

pyenv install 3.11pyenv virtualenv 3.11 cubepyenvlocal cubepip install -r requirements.txtdirenv allowpre-commit install

[8]ページ先頭

©2009-2025 Movatter.jp