twentyseven-0.0.0: Rubik's cube solver

Safe HaskellNone
LanguageHaskell2010

Rubik.Cube.Cubie

Contents

Description

Cubie representation.

A Rubik's cube is the cartesian product of a permutation of cubies and an action on their orientations.

Synopsis

Complete cube

class CubeAction a where Source

Group action of Cube on type a

 x `cubeAction` iden == x
(x `cubeAction` a) `cubeAction` b == x `cubeAction (a <> b)

It seems that with proper additional laws between FromCube and Group instances, it may be possible to automatically deduce a default CubeAction instance.

cubeAction a = (a <>) . fromCube

This module defines representations of right cosets (Hg where g :: Cube) of certain subgroups H of the Rubik group Cube, which acts on the right of the set of cosets.

Methods

cubeAction :: a -> Cube -> a Source

data Cube Source

A cube is given by the positions of its corners and edges.

Cubes are identified with the permutations that produce them starting from the solved cube.

The cube permutation composition (class Group Cube) is defined "in left to right order", so that the sequence of movements "x then y then z" is represented by x <> y <> z.

Constructors

Cube 

Fields

corner :: Corner
 
edge :: Edge
 

Solvability test

solvable :: Cube -> Bool Source

Tests whether a cube can be solved with the standard set of moves.

Corners

numCorners :: Int Source

numCorners = 8

data CornerPermu Source

Cubie permutation is in replaced-by representation.

(De)construction

cornerPermu :: Vector Int -> Maybe CornerPermu Source

Check that the argument is a permutation of size 8 and wrap it.

In a solvable Rubik's cube, its parity must be equal to that of the associated EdgePermu.

cornerOrien :: Vector Int -> Maybe CornerOrien Source

Check that the argument is a vector of senary (6) values of size 8 and wrap it.

In a solvable Rubik's cube, only ternary values are possible; i.e., all elements must be between 0 and 2. Their sum must also be a multiple of 3.

Orientation encoding

Corner orientations are permutations of 3 facelets.

They are mapped to integers in [0 .. 5] such that [0, 1, 2] are rotations (even permutations) and [3, 4, 5] are transpositions (although impossible in a Rubik's cube).

  • 0. identity
  • 1. counter-clockwise
  • 2. clockwise
  • 3. left facelet fixed
  • 4. right facelet fixed
  • 5. top (reference) facelet fixed

Edges

numEdges :: Int Source

numEdges = 12

data EdgePermu Source

Cubie permutation is in replaced-by representation.

Instances

Eq EdgePermu Source 
Show EdgePermu Source 
Monoid EdgePermu Source 
Group EdgePermu Source 
CubeAction EdgePermu Source 
FromCube EdgePermu Source 
RawEncodable EdgePermu Source
12! = 479001600

A bit too much to hold in memory.

Holds just right in a Haskell Int (maxInt >= 2^29 - 1).

(De)construction

edgePermu :: Vector Int -> Maybe EdgePermu Source

Check that the argument is a permutation of size 12 and wrap it.

In a solvable Rubik's cube, its parity must be equal to that of the associated CornerPermu.

edgeOrien :: Vector Int -> Maybe EdgeOrien Source

Check that the argument is a vector of binary values of size 12 and wrap it.

In a solvable Rubik's cube, their sum must be even.

Conversions

colorFaceletsToCube :: ColorFacelets -> Either [Int] (Maybe Cube) Source

Convert from facelet to cubie permutation.

Evaluates to a Left error if a combination of colors does not correspond to a regular cubie from the solved cube: the colors of the facelets on one cubie must be unique, and must not contain facelets of opposite faces. The error is the list of indices of facelets of such an invalid cubie.

Another possible error is that the resulting configuration is not a permutation of cubies (at least one cubie is absent, and one is duplicated). In that case, the result is Right Nothing.

UDSlice

numUDSliceEdges :: Int Source

numUDSliceEdges = 4

data UDSlice Source

Position of the 4 UDSlice edges up to permutation (carried-to). The vector is always sorted.

data UDSlicePermu2 Source

Position of the 4 UDSlice edges (replaced-by), assuming they are all in that slice already.

data UDEdgePermu2 Source

Position of the 8 other edges (replaced-by), assuming UDSlice edges are in that slice already.

(De)construction

uDSlice :: Vector Int -> Maybe UDSlice Source

Wrap an increasing list of 4 elements in [0 .. 11].

uDSlicePermu2 :: Vector Int -> Maybe UDSlicePermu2 Source

Wrap a permutation of size 4.

uDEdgePermu2 :: Vector Int -> Maybe UDEdgePermu2 Source

Wrap a permutation of size 8.

Symmetry

conjugateFlipUDSlice :: Cube -> FlipUDSlice -> FlipUDSlice Source

The conjugation is only compatible when the Cube symmetry leaves UDSlice edges stable, and either flips them all or none of them, and either flips all 8 non-UDSlice edges or none of them.

conjugateCornerOrien :: Cube -> CornerOrien -> CornerOrien Source

Expects UDSlice-stable symmetry.