Skip to content

MeepMoop/py222

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

61 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Py222

Py222 is a 2x2x2 Rubik's Cube representation written in Python. It has support for applying individual moves to the puzzle, as well as space-separated algorithm strings specified in WCA notation.

A cube's state is represented as a 24-element numpy array with indices corresponding to the following stickers, and values corresponding to the following face colors:

sticker indices:
       β”Œβ”€β”€β”¬β”€β”€β”
       β”‚ 0β”‚ 1β”‚
       β”œβ”€β”€β”Όβ”€β”€β”€
       β”‚ 2β”‚ 3β”‚
 β”Œβ”€β”€β”¬β”€β”€β”Όβ”€β”€β”Όβ”€β”€β”Όβ”€β”€β”¬β”€β”€β”¬β”€β”€β”¬β”€β”€β”
 β”‚16β”‚17β”‚ 8β”‚ 9β”‚ 4β”‚ 5β”‚20β”‚21β”‚
 β”œβ”€β”€β”Όβ”€β”€β”Όβ”€β”€β”Όβ”€β”€β”Όβ”€β”€β”Όβ”€β”€β”Όβ”€β”€β”Όβ”€β”€β”€
 β”‚18β”‚19β”‚10β”‚11β”‚ 6β”‚ 7β”‚22β”‚23β”‚
 β””β”€β”€β”΄β”€β”€β”Όβ”€β”€β”Όβ”€β”€β”Όβ”€β”€β”΄β”€β”€β”΄β”€β”€β”΄β”€β”€β”˜
       β”‚12β”‚13β”‚
       β”œβ”€β”€β”Όβ”€β”€β”€
       β”‚14β”‚15β”‚
       β””β”€β”€β”΄β”€β”€β”˜

face colors:
    β”Œβ”€β”€β”
    β”‚ 0β”‚
 β”Œβ”€β”€β”Όβ”€β”€β”Όβ”€β”€β”¬β”€β”€β”
 β”‚ 4β”‚ 2β”‚ 1β”‚ 5β”‚
 β””β”€β”€β”Όβ”€β”€β”Όβ”€β”€β”΄β”€β”€β”˜
    β”‚ 3β”‚
    β””β”€β”€β”˜

The move definitions are written for a sticker representation, but there are functions to normalize the state's stickers relative to a fixed DLB corner, and convert it into a fixed-corner piece orientation and permutation (OP) representation. There are also various functions that can hash the fixed-corner OP representation state into unique integer indices.

Also included is a sample IDA* solver (solver.py).

Dependencies

  • numpy

Usage

  import py222

  # get solved state
  s = py222.initState()
  py222.printCube(s)
      β”Œβ”€β”€β”¬β”€β”€β”
      β”‚ 0β”‚ 0β”‚
      β”œβ”€β”€β”Όβ”€β”€β”€
      β”‚ 0β”‚ 0β”‚
β”Œβ”€β”€β”¬β”€β”€β”Όβ”€β”€β”Όβ”€β”€β”Όβ”€β”€β”¬β”€β”€β”¬β”€β”€β”¬β”€β”€β”
β”‚ 4β”‚ 4β”‚ 2β”‚ 2β”‚ 1β”‚ 1β”‚ 5β”‚ 5β”‚
β”œβ”€β”€β”Όβ”€β”€β”Όβ”€β”€β”Όβ”€β”€β”Όβ”€β”€β”Όβ”€β”€β”Όβ”€β”€β”Όβ”€β”€β”€
β”‚ 4β”‚ 4β”‚ 2β”‚ 2β”‚ 1β”‚ 1β”‚ 5β”‚ 5β”‚
β””β”€β”€β”΄β”€β”€β”Όβ”€β”€β”Όβ”€β”€β”Όβ”€β”€β”΄β”€β”€β”΄β”€β”€β”΄β”€β”€β”˜
      β”‚ 3β”‚ 3β”‚
      β”œβ”€β”€β”Όβ”€β”€β”€
      β”‚ 3β”‚ 3β”‚
      β””β”€β”€β”΄β”€β”€β”˜
  # do some moves
  s = py222.doAlgStr(s, "x y R U' R' U' F2 U' R U R' U F2")
  py222.printCube(s)
      β”Œβ”€β”€β”¬β”€β”€β”
      β”‚ 2β”‚ 2β”‚
      β”œβ”€β”€β”Όβ”€β”€β”€
      β”‚ 2β”‚ 2β”‚
β”Œβ”€β”€β”¬β”€β”€β”Όβ”€β”€β”Όβ”€β”€β”Όβ”€β”€β”¬β”€β”€β”¬β”€β”€β”¬β”€β”€β”
β”‚ 0β”‚ 3β”‚ 1β”‚ 4β”‚ 3β”‚ 0β”‚ 4β”‚ 1β”‚
β”œβ”€β”€β”Όβ”€β”€β”Όβ”€β”€β”Όβ”€β”€β”Όβ”€β”€β”Όβ”€β”€β”Όβ”€β”€β”Όβ”€β”€β”€
β”‚ 3β”‚ 3β”‚ 1β”‚ 1β”‚ 0β”‚ 0β”‚ 4β”‚ 4β”‚
β””β”€β”€β”΄β”€β”€β”Όβ”€β”€β”Όβ”€β”€β”Όβ”€β”€β”΄β”€β”€β”΄β”€β”€β”΄β”€β”€β”˜
      β”‚ 5β”‚ 5β”‚
      β”œβ”€β”€β”Όβ”€β”€β”€
      β”‚ 5β”‚ 5β”‚
      β””β”€β”€β”΄β”€β”€β”˜
  # normalize stickers relative to DLB
  s = py222.normFC(s)
  py222.printCube(s)

      β”Œβ”€β”€β”¬β”€β”€β”
      β”‚ 0β”‚ 0β”‚
      β”œβ”€β”€β”Όβ”€β”€β”€
      β”‚ 0β”‚ 0β”‚
β”Œβ”€β”€β”¬β”€β”€β”Όβ”€β”€β”Όβ”€β”€β”Όβ”€β”€β”¬β”€β”€β”¬β”€β”€β”¬β”€β”€β”
β”‚ 1β”‚ 4β”‚ 2β”‚ 5β”‚ 4β”‚ 1β”‚ 5β”‚ 2β”‚
β”œβ”€β”€β”Όβ”€β”€β”Όβ”€β”€β”Όβ”€β”€β”Όβ”€β”€β”Όβ”€β”€β”Όβ”€β”€β”Όβ”€β”€β”€
β”‚ 4β”‚ 4β”‚ 2β”‚ 2β”‚ 1β”‚ 1β”‚ 5β”‚ 5β”‚
β””β”€β”€β”΄β”€β”€β”Όβ”€β”€β”Όβ”€β”€β”Όβ”€β”€β”΄β”€β”€β”΄β”€β”€β”΄β”€β”€β”˜
      β”‚ 3β”‚ 3β”‚
      β”œβ”€β”€β”Όβ”€β”€β”€
      β”‚ 3β”‚ 3β”‚
      β””β”€β”€β”΄β”€β”€β”˜

Solver Usage

import py222
import solver

# get solved state
s = py222.initState()

# apply some scramble
s = py222.doAlgStr(s, "R U2 R2 F2 R' F2 R F R")

# solve cube
solver.solveCube(s)
      β”Œβ”€β”€β”¬β”€β”€β”
      β”‚ 2β”‚ 3β”‚
      β”œβ”€β”€β”Όβ”€β”€β”€
      β”‚ 1β”‚ 0β”‚
β”Œβ”€β”€β”¬β”€β”€β”Όβ”€β”€β”Όβ”€β”€β”Όβ”€β”€β”¬β”€β”€β”¬β”€β”€β”¬β”€β”€β”
β”‚ 1β”‚ 3β”‚ 5β”‚ 4β”‚ 2β”‚ 2β”‚ 4β”‚ 3β”‚
β”œβ”€β”€β”Όβ”€β”€β”Όβ”€β”€β”Όβ”€β”€β”Όβ”€β”€β”Όβ”€β”€β”Όβ”€β”€β”Όβ”€β”€β”€
β”‚ 4β”‚ 2β”‚ 0β”‚ 0β”‚ 4β”‚ 1β”‚ 0β”‚ 5β”‚
β””β”€β”€β”΄β”€β”€β”Όβ”€β”€β”Όβ”€β”€β”Όβ”€β”€β”΄β”€β”€β”΄β”€β”€β”΄β”€β”€β”˜
      β”‚ 1β”‚ 5β”‚
      β”œβ”€β”€β”Όβ”€β”€β”€
      β”‚ 3β”‚ 5β”‚
      β””β”€β”€β”΄β”€β”€β”˜
normalizing stickers...
generating pruning tables...
searching...
depth 1
depth 2
depth 3
depth 4
depth 5
depth 6
depth 7
depth 8
F R2 F' R U2 R2 F' R 
F R2 F' R' F R2 U2 R' 

About

Python 2x2 Rubik's Cube representation & solver

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages