cube-python
High-performance Rubik's Cube solver Python bindings powered by C/C++ FFI.
Installation
pip install cube-python
Quickstart
iimport pycube
from pycube import SolveError
# Default solved cube string representation
print(f"Target State: {pycube.CUBE_ID}")
# Validate state solvability
scrambled = pycube.facecube("U F U' L2 R L' D2 B")
if pycube.solvable(scrambled):
try:
# Find solution sequence
solution = pycube.solve(scrambled, step=30, best=True)
print(f"Solution: {solution}")
# Apply solution to verify end state
end_state = pycube.facecube(solution, scrambled)
assert end_state == pycube.CUBE_ID
except SolveError as e:
print(f"Failed to solve cube: {e}")
📖 API Reference
import pycube
from pycube import SolveError, CUBE_ID
Functions
| Function | Description |
|---|---|
solve(src, tgt=CUBE_ID, step=30, best=False) |
Solves the cube state string src. Returns solution string or raises SolveError. |
facecube(maneuver, cube=CUBE_ID) |
Applies move sequence (e.g., "U F U' L2") to a cube state and returns the new state. |
solvable(cube) |
Returns True if the 54-character state string is physically solvable. |
permutation(ms, fmt=2) |
Returns a permutation representation for a move sequence or state. |
Constants & Exceptions
| Name | Type | Description |
|---|---|---|
CUBE_ID |
str |
Constant representing the standard solved state ("UUUUUUUUURRRRRRRRRFFFFFFFFFDDDDDDDDDLLLLLLLLLBBBBBBBBB"). |
SolveError |
Exception |
Raised when the state is invalid, unsolvable, or exceeds search step limits. |
📄 License
MIT © coshz
Release files for cube-python 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| cube_python-0.4.0.tar.gz | 21.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| cube_python-0.4.0-cp312-cp312-macosx_10_15_x86_64.whl | CPython 3.12 | CPython 3.12 | macOS 10.15+ x86-64 | Details |
Total release size: 111.0 kB
Release files / cube_python-0.4.0.tar.gz
| Download URL | cube_python-0.4.0.tar.gz |
|---|---|
| Size | 21.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9b815e3408f73053ccf52ad0be0bdcd450e4b91bb26accb31aea24778ae31f93
|
|
BLAKE2b-256 checksum How to use checksums |
cb12b40be85b91a6affc522657c60377defde3216a203e7599820b22f184eba3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.1
|
Release files / cube_python-0.4.0-cp312-cp312-macosx_10_15_x86_64.whl
| Download URL | cube_python-0.4.0-cp312-cp312-macosx_10_15_x86_64.whl |
|---|---|
| Size | 89.8 kB |
| Tags | CPython 3.12 macOS 10.15+ x86-64 |
|
SHA-256 checksum How to use checksums |
649ef8e6c831cb93b4c4a50c7330245efcd80aaa0497d9e00395428146118475
|
|
BLAKE2b-256 checksum How to use checksums |
369d51430dc0cad04c256f3d079059f40f9463b2319b2b689a0dfa9b1b331e58
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.1
|