emilgoldsmith / elm-speedcubing / Cube.Advanced

Definition


type Cube

See Cube

Constructors

solved : Cube

See Cube.solved

Modifiers

applyAlgorithm : Algorithm -> Cube -> Cube

See Cube.applyAlgorithm

Displayers


type alias CubeTheme =
{ up : Color
, down : Color
, right : Color
, left : Color
, front : Color
, back : Color
, plastic : Color
, annotations : Color 
}

The color scheme of the cube, and also color of the "plastic" and the face annotations (U, F, B etc. on the respective sides) text color.

Note that we use the color type from avh4/elm-color

defaultTheme : CubeTheme

For ease of use here is a pretty standard color scheme for a cube


type DisplayAngle

See Cube.DisplayAngle

ufrDisplayAngle : DisplayAngle

See Cube.ufrDisplayAngle

ublDisplayAngle : DisplayAngle

See Cube.ublDisplayAngle

dblDisplayAngle : DisplayAngle

See Cube.dblDisplayAngle

view : List (Html.Attribute msg) -> { pixelSize : Basics.Int, displayAngle : DisplayAngle, annotateFaces : Basics.Bool, theme : CubeTheme } -> Cube -> Html msg

See Cube.view

debugViewAllowingVisualTesting : List (Html.Attribute msg) -> { pixelSize : Basics.Int, displayAngle : DisplayAngle, annotateFaces : Basics.Bool, theme : CubeTheme } -> Cube -> Html msg

It's exactly the same as Cube.view, except it allows for programmatic screenshotting of the application, and the cost of that is lowered performance. This is due to some WebGL internals which the cube rendering is implemented with

Rendering


type alias Rendering =
{ ufr : CubieRendering
, ufl : CubieRendering
, ubl : CubieRendering
, ubr : CubieRendering
, dfr : CubieRendering
, dfl : CubieRendering
, dbl : CubieRendering
, dbr : CubieRendering
, uf : CubieRendering
, df : CubieRendering
, db : CubieRendering
, ub : CubieRendering
, ur : CubieRendering
, ul : CubieRendering
, dl : CubieRendering
, dr : CubieRendering
, fl : CubieRendering
, fr : CubieRendering
, br : CubieRendering
, bl : CubieRendering
, u : CubieRendering
, d : CubieRendering
, f : CubieRendering
, b : CubieRendering
, l : CubieRendering
, r : CubieRendering 
}

This representation of how the cube looks is meant for advanced custom use if you for example want to display the cube differently than this package does, or you need to introspect specific state of the cube for your application.

It is expected that most use cases should be able to fulfill their goals without the use of this, and if you find a use case that you think should be covered by the package itself feel free to submit a Github issue.

Otherwise as mentioned use these rendering methods and types to accomplish all the custom goals you want to!


type alias CubieRendering =
{ u : CubeColor
, d : CubeColor
, f : CubeColor
, b : CubeColor
, l : CubeColor
, r : CubeColor 
}

The rendering of one specific cubie (a cubie is one of the pieces of the Rubik's Cube). Note that we describe all sides of all cubies in this model, even the ones that aren't facing outwards.


type CubeColor
    = UpColor
    | DownColor
    | FrontColor
    | BackColor
    | LeftColor
    | RightColor
    | PlasticColor

The color of a face of a cubie. The name of the color corresponds to the face of the cube that it belongs to in the initial orientation. So in standard scrambling orientation of the 3x3 cube UpColor is white and RightColor is red. PlasticColor means it is a part of the cubie not facing outwards

render : Cube -> Rendering

Get a Rendering of a cube

Rendering Helpers


type Face
    = UpOrDown UOrD
    | FrontOrBack FOrB
    | LeftOrRight LOrR

Describes all the possible faces of a cubie (a piece on the cube)


type UOrD
    = U
    | D

A helper type that allows us to make it impossible to represent impossible locations on the cube. By splitting the faces into opposites like we've done with these 3 types we can describe that a corner location is exactly described by one of each of three opposing faces, and not any two faces, and similarly for edges


type LOrR
    = L
    | R

Same as UOrD


type FOrB
    = F
    | B

Same as UOrD

uFace : Face

A helper constructor for the U face as it's much neater to read than UpOrDown U

dFace : Face

A helper constructor for the D face as it's much neater to read than UpOrDown D

rFace : Face

A helper constructor for the R face as it's much neater to read than LeftOrRight R

lFace : Face

A helper constructor for the L face as it's much neater to read than LeftOrRight L

fFace : Face

A helper constructor for the F face as it's much neater to read than FrontOrBack F

bFace : Face

A helper constructor for the B face as it's much neater to read than FrontOrBack B

faceToColor : Face -> CubeColor

Get the color corresponding to the given face

colorToFaceItBelongsTo : CubeColor -> Maybe Face

Get the color corresponding to the given face

setColor : Face -> CubeColor -> CubieRendering -> CubieRendering

Set the given color on the given face of the given cubie rendering

faces : List.Nonempty.Nonempty Face

All possible faces

import List.Nonempty

List.Nonempty.length faces --> 6


type alias CornerLocation =
( UOrD
, FOrB
, LOrR 
)

Describes all the possible locations of a corner on a cube

getCorner : CornerLocation -> Cube -> OrientedCorner

Get the corner at the given location of the given cube

setCorner : CornerLocation -> OrientedCorner -> Cube -> Cube

Set the given corner at the given corner location on the given cube

cornerLocations : List.Nonempty.Nonempty CornerLocation

All possible corner locations

import List.Nonempty

List.Nonempty.length cornerLocations --> 8


type EdgeLocation
    = M (( UOrD, FOrB ))
    | S (( UOrD, LOrR ))
    | E (( FOrB, LOrR ))

Describes all the possible locations of an edge on a cube

getEdge : EdgeLocation -> Cube -> OrientedEdge

Get the edge at the given location on the given cube

setEdge : EdgeLocation -> OrientedEdge -> Cube -> Cube

Set the given edge at the given location of the given cube

edgeLocations : List.Nonempty.Nonempty EdgeLocation

All possible edge locations

import List.Nonempty

List.Nonempty.length edgeLocations --> 12


type CenterLocation

Describes all the possible locations of a center on a cube

getCenter : CenterLocation -> Cube -> Center

Get the center at the given location on the given cube

setCenter : CenterLocation -> Center -> Cube -> Cube

Set the given center at the given location on the given cube

centerLocations : List.Nonempty.Nonempty CenterLocation

All possible center locations

import List.Nonempty

List.Nonempty.length centerLocations --> 6

Algorithm Helpers

algorithmResultsAreEquivalent : Algorithm -> Algorithm -> Basics.Bool

See Cube.algorithmResultsAreEquivalent

algorithmResultsAreEquivalentIndependentOfFinalRotation : Algorithm -> Algorithm -> Basics.Bool

See Cube.algorithmResultsAreEquivalentIndependentOfFinalRotation

makeAlgorithmMaintainOrientation : Algorithm -> Algorithm

See Cube.makeAlgorithmMaintainOrientation

AUF Helpers

addAUFsToAlgorithm : ( AUF, AUF ) -> Algorithm -> Algorithm

See Cube.addAUFsToAlgorithm

detectAUFs : { toDetectFor : Algorithm, toMatchTo : Algorithm } -> Maybe ( AUF, AUF )

See Cube.detectAUFs

General Helpers

canBeSolvedBySingleUTurn : Cube -> Basics.Bool

Checks whether a cube is only a single U turn away from being solved or not. This is used internally, which is why it sits here under Advanced as it's a pretty particular use case, but can be useful for some AUF logic, hopefully most if not all of your needs should be satisfied by the AUF module though

import Algorithm

Algorithm.fromString "U"
    |> Result.map (\alg -> canBeSolvedBySingleUTurn (applyAlgorithm alg solved))
--> Ok True

Algorithm.fromString "F"
    |> Result.map (\alg -> canBeSolvedBySingleUTurn (applyAlgorithm alg solved))
--> Ok False