# 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
```sh
pip install magiccube
```
## Usage
```python
import magiccube
# 3x3x3 Cube
cube = magiccube.Cube(3,"YYYYYYYYYRRRRRRRRRGGGGGGGGGOOOOOOOOOBBBBBBBBBWWWWWWWWW")
print(cube)
```
![Cube](https://trincaopub.s3.amazonaws.com/imgs/magiccube/cube3x3.png)
```python
# Rotate the cube
cube.rotate("R' L2 U D' F B'2 R' L")
# Solve the 3x3x3 cube
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
```
## 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.|
|F2 F2' | 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 RIGH,UP,FRONT corner.
## Solver
The solver uses the [beginner method](https://ruwix.com/the-rubiks-cube/how-to-solve-the-rubiks-cube-beginners-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`
```sh
curl https://pyenv.run | bash
```
Setup the environment using `pyenv`
```sh
pyenv virtualenv 3.11 cube-3.11
pyenv local cube-3.11
pip install -r requirements.txt
direnv allow
```
Install commit hooks
```sh
pre-commit install
```
Raw data
{
"_id": null,
"home_page": null,
"name": "magiccube",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.5",
"maintainer_email": null,
"keywords": "rubik, cube, solver, Rubik Cube, NxNxN",
"author": null,
"author_email": "Gon\u00e7alo Trinc\u00e3o Cunha <goncalo.cunha@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/29/aa/008a6dc9884d855cf5f7e3e02466b0b44cb1e64fd4b5ce906d4ce03030f9/magiccube-0.3.0.tar.gz",
"platform": null,
"description": "# MagicCube: A NxNxN Rubik Cube implementation\n\nA fast implementation of the Rubik Cube based in Python 3.x.\n\nMakes it easy to create cubes of various sizes (2x2x2, 3x3x3, 4x4x4, 6x6x6, ...., 100x100x100).\n\nFast rotation speed when compared with other Python implementations, which makes it suitable for Rubik Cube simulations.\n\nIncludes:\n\n- Simple solver for the 3x3x3 cube.\n- Move optimizer which reduces the number of moves.\n\n## Installation\n\n```sh\npip install magiccube\n```\n\n## Usage\n\n```python\nimport magiccube\n\n# 3x3x3 Cube\ncube = magiccube.Cube(3,\"YYYYYYYYYRRRRRRRRRGGGGGGGGGOOOOOOOOOBBBBBBBBBWWWWWWWWW\")\nprint(cube)\n```\n\n![Cube](https://trincaopub.s3.amazonaws.com/imgs/magiccube/cube3x3.png)\n\n```python\n# Rotate the cube\ncube.rotate(\"R' L2 U D' F B'2 R' L\")\n\n# Solve the 3x3x3 cube\nsolver = BasicSolver(cube)\nsolver.solve()\n\n# Complex moves 6x6x6 Cube\ncube = magiccube.Cube(6)\ncube.rotate(\"Lw\") # L wide rotation\ncube.rotate(\"Lw'\") # L wide counter-rotation\ncube.rotate(\"Lw2\") # 2x L wide rotation\ncube.rotate(\"3L\") # 3rd line L rotation\ncube.rotate(\"3Lw\") # 3rd line L wide rotation\ncube.rotate(\"3Lw'2\") # 2x 3rd line L wide counter-rotation\n```\n\n## Examples\n\nSee examples folder.\n\n## Supported Moves and Notation\n\n### Basic moves\n\n|Move | |\n|-----|-------------------------------------------------------------|\n|L L' | Clockwise/Counterclockwise cube rotation of the LEFT face. |\n|R R' | Clockwise/Counterclockwise cube rotation of the RIGHT face. |\n|D D' | Clockwise/Counterclockwise cube rotation of the DOWN face. |\n|U U' | Clockwise/Counterclockwise cube rotation of the UP face. |\n|F F' | Clockwise/Counterclockwise cube rotation of the FRONT face. |\n|B B' | Clockwise/Counterclockwise cube rotation of the BACK face. |\n\n### Advanced Moves\n\n|Move | |\n|-----|-------------------------------------------------------------|\n|X X' | Cube rotation on X axis. X is the axis that points from LEFT to the RIGHT face.|\n|Y Y' | Cube rotation on Y axis. Y is the axis that points from DOWN to the UP face.|\n|Z Z' | Cube rotation on Z axis. Z is the axis that points from BACK to the FRONT face.|\n|M M' | Rotation of the center layer on the X axis.|\n|E E' | Rotation of the center layer on the Y axis.|\n|S S' | Rotation of the center layer on the Z axis.|\n|Fw Fw'| Wide rotation of 2 layers.|\n|3Fw 3Fw' | Wide rotation of 3 layers.|\n|3F 3F' | Rotation of the 3rd layer.|\n|F2 F2' | 2x rotation.|\n\n## Cube Coordinates\n\n- Cube coordinates are expressed as a tuple of x,y,z.\n- (0,0,0) is the piece on the LEFT,DOWN,BACK corner.\n- In a 3x3x3, (2,2,2) is the piece on the RIGH,UP,FRONT corner.\n\n## Solver\n\nThe solver uses the [beginner method](https://ruwix.com/the-rubiks-cube/how-to-solve-the-rubiks-cube-beginners-method/) to solve the cube\n\n## Move Optimizer\n\nThe move optimizer does the following optimizations:\n\n- Eliminates redundant moves (ex: L L L L)\n- Converts 3x moves to the inverse (ex: F F F -> F')\n- Eliminates cube rotations (ex: Y F -> R)\n\n## Development\n\nInstall `pyenv`\n\n```sh\ncurl https://pyenv.run | bash\n```\n\nSetup the environment using `pyenv`\n\n```sh\npyenv virtualenv 3.11 cube-3.11\npyenv local cube-3.11\npip install -r requirements.txt\ndirenv allow\n```\n\nInstall commit hooks\n\n```sh\npre-commit install\n```\n",
"bugtrack_url": null,
"license": "BSD-3-Clause",
"summary": "NxNxN Rubik Cube implementation",
"version": "0.3.0",
"project_urls": {
"Homepage": "https://github.com/trincaog/magiccube"
},
"split_keywords": [
"rubik",
" cube",
" solver",
" rubik cube",
" nxnxn"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f78d354a7357e03fb9277401989b7866b8f05ae407319e7bc450b958f9187308",
"md5": "128b882a6bac79ebde6b796396f5f48e",
"sha256": "a8da38cac53dff1667949c9a12485bebb9d62c01ae73db41eb7aba1bc1c8a00c"
},
"downloads": -1,
"filename": "magiccube-0.3.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "128b882a6bac79ebde6b796396f5f48e",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.5",
"size": 16931,
"upload_time": "2024-07-15T06:58:02",
"upload_time_iso_8601": "2024-07-15T06:58:02.631609Z",
"url": "https://files.pythonhosted.org/packages/f7/8d/354a7357e03fb9277401989b7866b8f05ae407319e7bc450b958f9187308/magiccube-0.3.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "29aa008a6dc9884d855cf5f7e3e02466b0b44cb1e64fd4b5ce906d4ce03030f9",
"md5": "c30a36950ee236dbd3acefb2f6af0747",
"sha256": "4fa47df1e99c19ac74597279a17de5a652083d4d68f0d5e52cf09202317e5d04"
},
"downloads": -1,
"filename": "magiccube-0.3.0.tar.gz",
"has_sig": false,
"md5_digest": "c30a36950ee236dbd3acefb2f6af0747",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.5",
"size": 19407,
"upload_time": "2024-07-15T06:58:03",
"upload_time_iso_8601": "2024-07-15T06:58:03.757154Z",
"url": "https://files.pythonhosted.org/packages/29/aa/008a6dc9884d855cf5f7e3e02466b0b44cb1e64fd4b5ce906d4ce03030f9/magiccube-0.3.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-07-15 06:58:03",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "trincaog",
"github_project": "magiccube",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "numpy",
"specs": []
},
{
"name": "pytest",
"specs": []
},
{
"name": "pylint",
"specs": []
},
{
"name": "autopep8",
"specs": []
},
{
"name": "pre-commit",
"specs": []
}
],
"lcname": "magiccube"
}