Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
muodov committed Mar 18, 2018
2 parents 7fec105 + fca1e35 commit 2c3d01a
Show file tree
Hide file tree
Showing 12 changed files with 376 additions and 274 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
kociemba/ckociemba/bin/*
kociemba/ckociemba/cache/*
.vscode/**
Release/**
ckociembawrapper.c

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
12 changes: 7 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
language: python
python:
- "2.6"
- "2.7"
- "3.2"
- "3.3"
- "3.4"
- "3.5"
- "3.5-dev" # 3.5 development branch
- "nightly" # currently points to 3.6-dev
- "3.5-dev" # 3.5 development branch
- "3.6"
- "3.6-dev" # 3.6 development branch
- "3.7-dev" # 3.7 development branch
- "pypy"
# command to install dependencies
install: "python setup.py install"
install:
- pip install -U setuptools
- python setup.py install
# command to run tests
script: python setup.py test
29 changes: 23 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,29 @@
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 machine](https://blog.zok.pw/hacking/2015/08/18/fac-rubik-solver/), so be confident the algorithm is working.
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.

## Installation and usage
## Installation
This package is published on PyPI and can be installed with:

```$ pip install kociemba```

It was tested under Python 2.7 and 3.5.
It was tested under Python 2.7 and 3.3+.

On some 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`.
### 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.
Expand Down Expand Up @@ -44,7 +57,7 @@ The names of the facelet positions of the cube (letters stand for Up, Left, Fron
|*U7**U8**U9*|
|************|
************|************|************|************
*L1**L2**L3*|*F1**F2**F3*|*R1**R2**F3*|*B1**B2**B3*
*L1**L2**L3*|*F1**F2**F3*|*R1**R2**R3*|*B1**B2**B3*
************|************|************|************
*L4**L5**L6*|*F4**F5**F6*|*R4**R5**R6*|*B4**B5**B6*
************|************|************|************
Expand All @@ -69,7 +82,7 @@ So, for example, a definition of a solved cube would be `UUUUUUUUURRRRRRRRRFFFFF
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.
* 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**

Expand All @@ -84,3 +97,7 @@ When possible, `kociemba` will use C implementation under the hood. If something
To run the tests, clone the repository and run:

```$ python setup.py test```

## Thanks to

- @jarheadjoe for his contribution to Windows support
15 changes: 9 additions & 6 deletions kociemba/build_ckociemba.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
ffi.set_source(
"kociemba.ckociembawrapper",
"""
#include <stdio.h>
#include <stdlib.h>
#include <search.h>
#include "search.h"
char* solve(char *cubestring, char *patternstring, char *cache_dir)
{
char patternized[64];
char *sol;
if (patternstring) {
patternize(cubestring, patternstring, patternized);
cubestring = patternized;
}
char *sol = solution(
sol = solution(
cubestring,
24,
1000,
Expand All @@ -28,11 +28,14 @@
""",
include_dirs=['kociemba/ckociemba/include'],
sources=[
'kociemba/ckociemba/prunetable_helpers.c',
'kociemba/ckociemba/coordcube.c',
'kociemba/ckociemba/cubiecube.c',
'kociemba/ckociemba/facecube.c',
'kociemba/ckociemba/search.c'],
extra_compile_args=['-std=c99', '-O3', '-D_XOPEN_SOURCE=700'])
'kociemba/ckociemba/search.c'
],
extra_compile_args=['-std=c99', '-O3', '-D_XOPEN_SOURCE=700']
)

ffi.cdef("char* solve(char *cubestring, char *patternstring, char *cache_dir);")

Expand Down
3 changes: 1 addition & 2 deletions kociemba/ckociemba/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CKOCIEMBA_SRC = coordcube.c cubiecube.c facecube.c search.c
CKOCIEMBA_SRC = coordcube.c cubiecube.c facecube.c search.c prunetable_helpers.c
CKOCIEMBA_INCLUDE = include
CFLAGS = -std=c99 -O3
BINDIR = bin
Expand All @@ -7,4 +7,3 @@ BIN = kociemba
solve: solve.c $(CKOCIEMBA_SRC)
mkdir -p $(BINDIR)
gcc $(CFLAGS) $(CKOCIEMBA_SRC) -I$(CKOCIEMBA_INCLUDE) solve.c -o $(BINDIR)/$(BIN)

Loading

0 comments on commit 2c3d01a

Please sign in to comment.