twentyseven-0.0.0: Rubik's cube solver

Safe HaskellNone
LanguageHaskell2010

Rubik.Cube.Facelet

Contents

Description

Facelet representation

Facelets faces are unfolded and laid out like this:

      U
    L F R B
      D
  

Faces (or colors) are ordered U, L, F, R, B, D.

A Rubik's cube is a permutation of facelets numbered as follows:

           0  1  2
           3  4  5
           6  7  8

 9 10 11  18 19 20  27 28 29  36 37 38
12 13 14  21 22 23  30 31 32  39 40 41
15 16 17  24 25 26  33 34 35  42 43 44

          45 46 47
          48 49 50
          51 52 53

Synopsis

Facelet permutation

numFacelets :: Int Source

There are 54 == 6 * 9 facelets.

data Facelets Source

Cube as a permutation of facelets (replaced-by).

Every facelet is represented as an Int in [0 .. 54].

facelets :: Vector Int -> Maybe Facelets Source

This constructor checks that the input is a permutation of '[0 .. 53]'.

fromFacelets :: Facelets -> Vector Int Source

The underlying Vector of Int.

Colors

type Color = Int Source

The standard cube colors are the values between 0 and 5.

colorOf :: Int -> Color Source

The color of a facelet given its identifier.

colorChar :: Color -> Char Source

A color is mapped to a face, indicated by a Char:

map colorChar [0..5] == "ULFRBD"

Color list

data ColorFacelets Source

Cube as a list of facelet colors.

colorFacelets :: Vector Color -> Maybe ColorFacelets Source

This constructor checks that only standard colors (in [0 .. 5]) are used, that the argument has length 54 and that the centers are colored in order.

Note that there may still be more or less than 9 colors of a kind, although that cannot be the case in an actual cube.

colorFaceletsOf :: Facelets -> ColorFacelets Source

Remove permutation information.

If the argument cube can be obtained from the solved cube with the usual moves, then the original permutation can be recovered with colorFaceletsToCube.

List conversions

colorFacelets'' :: Eq a => [a] -> Maybe ColorFacelets Source

Convert a 6-color list of length 54 in any representation which implements Eq to ColorFacelets.

Pretty conversion

stringOfFacelets :: Facelets -> String Source

String listing the permutation of facelets numbered in base 9.

Base 9 is convenient here because the first digit directly corresponds to a face and the second to the facelet position in that face.

stringOfColorFacelets :: ColorFacelets -> String Source

String listing the facelet colors.

stringOfColorFacelets' :: Facelets -> String Source

Only show the colors of the facelets.

Facelets corresponding to each cubie

The first letter in the name of a cubie is the color of its reference facelet (illustrated at http://kociemba.org/math/cubielevel.htm).

Corner colors are given in clockwise order.

Corners are lexicographically ordered (U>L>F>R>B>D).

Edges are gathered by horizontal slices (U, D, UD).

Centers

centerFacelets :: [Int] Source

  centerFacelets
  = [ 4,  -- U
      13, -- L
      22, -- F
      31, -- R
      40, -- B
      49] -- D

Corners

cornerFacelets :: [[Int]] Source

cornerFacelets = [ulb, ufl, urf, ubr, dlf, dfr, drb, dbl]

ulb :: [Int] Source

Corner facelets

ufl :: [Int] Source

Corner facelets

urf :: [Int] Source

Corner facelets

ubr :: [Int] Source

Corner facelets

dlf :: [Int] Source

Corner facelets

dfr :: [Int] Source

Corner facelets

drb :: [Int] Source

Corner facelets

dbl :: [Int] Source

Corner facelets

Edges

edgeFacelets :: [[Int]] Source

edgeFacelets = [ul, uf, ur, ub, dl, df, dr, db, fl, fr, bl, br]

ul :: [Int] Source

Edge facelets

uf :: [Int] Source

Edge facelets

ur :: [Int] Source

Edge facelets

ub :: [Int] Source

Edge facelets

dl :: [Int] Source

Edge facelets

df :: [Int] Source

Edge facelets

dr :: [Int] Source

Edge facelets

db :: [Int] Source

Edge facelets

fl :: [Int] Source

Edge facelets

fr :: [Int] Source

Edge facelets

bl :: [Int] Source

Edge facelets

br :: [Int] Source

Edge facelets