emilgoldsmith/elm-speedcubing/9.0.1

NOTE: the latest version is 14.1.0

AUF

Types and helpers to deal with Adjust U Face (AUF), which are the moves needed either to adjust the U face to the right angle for executing your algorithms for several algorithm sets such as OLL and PLL, or the last move needed to solve the cube for example after PLL. See https://www.speedsolving.com/wiki/index.php/AUF for more information

Definition and Constructors

type AUF
= None
| Clockwise
| Halfway
| CounterClockwise

The 4 different AUFs. U, U', U2, and nothing. Use these value constructors together with @all when you need to construct in different ways.

all : Nonempty AUF

A nonempty list containing all the possible aufs. Could for example be used to generate a random auf or generate all the possible versions of an algorithm

import List.Nonempty


-- They are all there!
List.Nonempty.length all --> 4


-- Generate a random one
List.Nonempty.sample all


-- Get all versions of a Y perm
all
    |> List.Nonempty.map (Tuple.pair PLL.Y)
    |> List.Nonempty.map (\(pll, postAuf) ->
        List.Nonempty.map
            (\preAuf -> (preAuf, pll, postAuf))
            all
    )

Helpers

Get the algorithm that corresponds to the AUF

import Algorithm


toAlgorithm Halfway
-->  Algorithm.fromTurnList
-->    [ Algorithm.Turn
-->        Algorithm.U
-->        Algorithm.Halfway
-->        Algorithm.Clockwise
-->    ]

Get the algorithm that corresponds to the AUF, but be able to specify which turnable to use to do the AUF. This is especially relevant for usecases such as an algorithm does an x or z rotation (or wide move) in the algorithm so the AUF is actually executed on a non-U face

import Algorithm


toAlgorithmWithCustomTurnable Algorithm.B Halfway
-->  Algorithm.fromTurnList
-->    [ Algorithm.Turn
-->        Algorithm.B
-->        Algorithm.Halfway
-->        Algorithm.Clockwise
-->    ]
toString : AUF -> String

Get an algorithm string representation of the AUF

toString Halfway --> "U2"
= InvalidAUFAlgorithm String
| AlgorithmParsingError FromStringError

Explains an issue that occurred while parsing an AUF

InvalidAUFAlgorithm: The algorithm was parsed correctly but was not either an empty move or a turn of the U face

AlgorithmParsingProblem: The string was not a valid algorithm string and the contained Algorithm.FromStringError has the problem with the string

Describes the error as a string, and is not recommended to be displayed to end-users, but rather to be used in error mesages logged for developer's eyes etc.

case fromString aufString of
    Ok _ ->
        doSomethingOnSuccess


    Err error ->
        logError (debugFromStringError error)
fromString : String -> Result FromStringError AUF

Attempts to parse an algorithmic representation of an AUF

fromString "U'" --> Ok CounterClockwise


fromString "" --> Ok None


fromString "U B"
--> Err (InvalidAUFAlgorithm "U B")

Add a pre and postAUF to an algorithm outputting the resulting algorithm. This also supports algorithms that change orientation. So for example this would do the AUF on R instead of on U for the postAUF

import Algorithm


addToAlgorithm
    ( Halfway, Clockwise )
    (Algorithm.fromTurnList [ Algorithm.Turn Algorithm.Z Algorithm.OneQuarter Algorithm.Clockwise ])


--> Algorithm.fromTurnList
-->     [ Algorithm.Turn Algorithm.U Algorithm.Halfway Algorithm.Clockwise
-->     , Algorithm.Turn Algorithm.Z Algorithm.OneQuarter Algorithm.Clockwise
-->     , Algorithm.Turn Algorithm.R Algorithm.OneQuarter Algorithm.Clockwise
-->     ]