« Go Back to Phase 1

Before we conclude this phase, we should create a common (although currently BUGGY!!!!) scrambler.

The bugginess will not be very obvious to a non-cuber, though, so I will explain a later post when I refactor.

let Scramble cubeState (movesAllowed : CubeTransformation list) n =
    let rnd = new System.Random()

    let mutable scrambledCube = cubeState
    let mutable movesPerformed = []

    for i = 1 to n do
        let nextMove = movesAllowed.[rnd.Next(movesAllowed.Length)]
        scrambledCube <- scrambledCube |> Execute nextMove.Transformation
        movesPerformed <- nextMove.Label :: movesPerformed

    (scrambledCube, System.String.Join(" ", movesPerformed))

Relevant Tests:

[<Fact>]
let ``Scrambles should result in a scrambled cube...`` () =
    Scramble solvedCube Movesets.MoveSets.All 25 |> should not' (equal solvedCube)

[<Fact>]
let ``Scrambles should not have repeated moves.`` () =
    1 |> should equal 2 
    (*
        not sure how to write this test.
        basically want to prevent things like [L L] or [L L2] or [L R' L2]
    *)