[![Build Status](https://travis-ci.org/muodov/kociemba.svg?branch=master)](https://travis-ci.org/muodov/kociemba)
# kociemba
This Python package contains two equivalent implementations (in C and Python) of Herbert Kociemba's two-phase algorithm for solving Rubik's Cube.
Original Java implementation can be found here: http://kociemba.org/download.htm.
These ports are pretty straightforward (not to say dumb) and most probably can be optimized. But they have been extensively tested in our Rubik's cube solving machines ([FAC System Solver](https://blog.zok.pw/hacking/2015/08/18/fac-rubik-solver/) and [Meccano Rubik's Shrine](http://blog.zok.pw/hacking/2016/08/12/meccano-rubiks-shrine/)), so be confident the algorithm is working.
**NB** please note that two-phase algorithm does not guarantee that the produced solution is the shortest possible. Instead, it gives you a "good enough" solution in a very short time. You can implement additional checks on top of this library, for example, to not produce any moves if the cube is already solved.
## Installation
This package is published on PyPI and can be installed with:
```$ pip install kociemba```
It was tested under Python 2.7 and 3.3+.
### Unix-based systems
You might need to install libffi system library beforehand. For example, on Debian-based distributions (e.g. Raspbian) you would run `sudo apt-get install libffi-dev`.
### Windows
Library should work on Windows, however it is not automatically tested at this moment: Travis CI [doesn't have windows support](https://github.com/travis-ci/travis-ci/issues/2104).
Normal `pip install kociemba` (or `pip3 install kociemba` for Python 3.3+) should work, but you will need to install free build tools from Microsoft first. Check the following links:
- for Python 2.7: https://www.microsoft.com/en-us/download/details.aspx?id=44266
- for Python 3: https://www.visualstudio.com/downloads/#build-tools-for-visual-studio-2017
## Usage
The package exposes just one function ```solve()```, which accepts a cube definition string and returns a solution string in standard notation (see below).
Optional second argument allows solving to a specific pattern.
```python
>>> import kociemba
>>> kociemba.solve('DRLUUBFBRBLURRLRUBLRDDFDLFUFUFFDBRDUBRUFLLFDDBFLUBLRBD')
u"D2 R' D' F2 B D R2 D2 R' F2 D' F2 U' B2 L2 U2 D R2 U"
>>> kociemba.solve('FLBUULFFLFDURRDBUBUUDDFFBRDDBLRDRFLLRLRULFUDRRBDBBBUFL', 'BBURUDBFUFFFRRFUUFLULUFUDLRRDBBDBDBLUDDFLLRRBRLLLBRDDF')
u"R' D2 R' U2 R F2 D B2 U' R F' U R2 D L2 D' B2 R2 B2 U' B2"
```
## Standalone tool
When installing with pip, `kociemba` will also register a command line tool with the same name. So you can also use it like this:
```$ kociemba <cubestring>```
## Cube string notation
The names of the facelet positions of the cube (letters stand for Up, Left, Front, Right, Back, and Down):
```
|************|
|*U1**U2**U3*|
|************|
|*U4**U5**U6*|
|************|
|*U7**U8**U9*|
|************|
************|************|************|************
*L1**L2**L3*|*F1**F2**F3*|*R1**R2**R3*|*B1**B2**B3*
************|************|************|************
*L4**L5**L6*|*F4**F5**F6*|*R4**R5**R6*|*B4**B5**B6*
************|************|************|************
*L7**L8**L9*|*F7**F8**F9*|*R7**R8**R9*|*B7**B8**B9*
************|************|************|************
|************|
|*D1**D2**D3*|
|************|
|*D4**D5**D6*|
|************|
|*D7**D8**D9*|
|************|
```
A cube definition string "UBL..." means that in position U1 we have the U-color, in position U2 we have the
B-color, in position U3 we have the L color etc. according to the order `U1`, `U2`, `U3`, `U4`, `U5`, `U6`, `U7`, `U8`, `U9`, `R1`, `R2`,
`R3`, `R4`, `R5`, `R6`, `R7`, `R8`, `R9`, `F1`, `F2`, `F3`, `F4`, `F5`, `F6`, `F7`, `F8`, `F9`, `D1`, `D2`, `D3`, `D4`, `D5`, `D6`, `D7`, `D8`, `D9`, `L1`, `L2`, `L3`, `L4`,
`L5`, `L6`, `L7`, `L8`, `L9`, `B1`, `B2`, `B3`, `B4`, `B5`, `B6`, `B7`, `B8`, `B9`.
So, for example, a definition of a solved cube would be `UUUUUUUUURRRRRRRRRFFFFFFFFFDDDDDDDDDLLLLLLLLLBBBBBBBBB`
Solution string consists of space-separated parts, each of them represents a single move:
* A single letter by itself means to turn that face clockwise 90 degrees.
* A letter followed by an apostrophe means to turn that face counterclockwise 90 degrees.
* A letter with the number 2 after it means to turn that face 180 degrees.
e.g. **`R U R’ U R U2 R’ U`**
## C version
C sources reside in the `ckociemba` folder. Running `make` inside this directory will compile a standalone binary. It accepts a cube representation as a command line argument, and writes the solution to the standard output. You can, of course, use `ckociemba` sources directly in your projects.
## Performance
When possible, `kociemba` will use C implementation under the hood. If something goes wrong (C version cannot be imported) it will automatically fall back to pure-Python implementation. However, it will be much slower.
## Testing
To run the tests, clone the repository and run:
```$ python setup.py test```
## Thanks to
- @jarheadjoe for his contribution to Windows support
没有合适的资源?快使用搜索试试~ 我知道了~
kociemba:用于解决Rubik立方体的Kociemba算法的纯Python和纯C端口
共61个文件
py:15个
pkl:12个
h:9个
需积分: 48 6 下载量 32 浏览量
2021-05-09
08:52:35
上传
评论
收藏 6.81MB ZIP 举报
温馨提示
Kociemba 该Python软件包包含用于解决Rubik立方体的Herbert Kociemba的两阶段算法的两个等效实现(用C和Python)。 原始Java实现可在以下位置找到: : 。 这些端口非常简单(更不用说哑巴了),并且很可能可以进行优化。 但是它们已经在我们的Rubik立方体解决方案机器( 和 )中进行了广泛的测试,因此可以确信该算法是否有效。 注意,请注意,两阶段算法不能保证所产生的解决方案是最短的。 相反,它可以在很短的时间内为您提供“足够好”的解决方案。 您可以在此库的顶部实施其他检查,例如,如果多维数据集已经解决,则不产生任何移动。 安装 该软件包在PyPI上发布,可以安装在: $ pip install kociemba 它已在Python 2.7和3.3+下进行了测试。 基于Unix的系统 您可能需要预先安装libffi系统库。 例如,在基于De
资源详情
资源评论
资源推荐
收起资源包目录
kociemba-master.zip (61个子文件)
kociemba-master
.travis.yml 274B
kociemba
cprunetables
URFtoDLF_Move 709KB
Slice_Flip_Prun 495KB
URtoUL_Move 46KB
UBtoDF_Move 46KB
Slice_Twist_Prun 529KB
MergeURtoULandUBtoDF 221KB
twistMove 77KB
flipMove 72KB
Slice_URtoDF_Parity_Prun 473KB
Slice_URFtoDLF_Parity_Prun 473KB
URtoDF_Move 709KB
FRtoBR_Move 418KB
ckociemba
facecube.c 4KB
solve.c 628B
include
edge.h 231B
cubiecube.h 2KB
search.h 3KB
corner.h 248B
color.h 144B
prunetable_helpers.h 627B
coordcube.h 4KB
facecube.h 1KB
facelet.h 2KB
coordcube.c 14KB
prunetable_helpers.c 2KB
Makefile 295B
cubiecube.c 20KB
search.c 11KB
command_line.py 402B
build_ckociemba.py 1KB
__init__.py 2KB
pykociemba
facelet.py 3KB
tools.py 2KB
coordcube.py 18KB
search.py 13KB
edge.py 553B
facecube.py 4KB
__init__.py 0B
prunetables
URFtoDLF_Move.pkl 2.76MB
Slice_Twist_Prun.pkl 3.07MB
FRtoBR_Move.pkl 1.54MB
UBtoDF_Move.pkl 153KB
twistMove.pkl 268KB
URtoDF_Move.pkl 2.96MB
Slice_URtoDF_Parity_Prun.pkl 2.76MB
flipMove.pkl 249KB
Slice_URFtoDLF_Parity_Prun.pkl 2.76MB
MergeURtoULandUBtoDF.pkl 602KB
URtoUL_Move.pkl 153KB
Slice_Flip_Prun.pkl 2.88MB
corner.py 496B
color.py 377B
cubiecube.py 19KB
tests
test_solve.py 16KB
javares.txt 1.07MB
LICENSE 18KB
setup.cfg 23B
setup.py 1KB
.gitignore 800B
README.md 5KB
共 61 条
- 1
ShiMax
- 粉丝: 51
- 资源: 4424
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0