Package Exports
- scramble-generator
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (scramble-generator) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
scramble-generator
Rubik's cube scramble generator
Usage
npm install scramble-generator
import { formatted, generate, parse } from 'scramble-generator';
formatted({ cubeSize: 3 }) // "R U' F2 D2 F2 L2 B2 R F' L' U' F' U2 R F U R D' L2 U2"
generate({ cubeSize: 3 }) // [ { face: 'B', longFace: 'BACK', inverted: false, double: true },
// { face: 'R', longFace: 'RIGHT', inverted: true, double: false }, ... ]
parse("B2 R'") // [ { face: 'B', longFace: 'BACK', inverted: false, double: true },
// { face: 'R', longFace: 'RIGHT', inverted: true, double: false } ]
API
scramble-generator
Meta
- author: Michael Rose
- license: https://github.com/msrose/scramble-generator/blob/master/LICENSE
Move
A turn of the cube is represented throughout as a Move object, which has all the properties necessary to describe how a given turn must be executed.
Type: object
Properties
face
string The short name of the face to turn e.g. 'R'longFace
string The long name of the face to turn e.g. 'RIGHT'inverted
boolean Indicates if the turn is to be made clockwise (false
) or counter-clockwise (true
)double
boolean Indicates if the turn is 180 degrees. Iftrue
,inverted
will always befalse
.
Faces
Map of constants representing names of cube faces. The keys are 'RIGHT', 'UP', 'LEFT', 'DOWN', 'BACK', and 'FRONT'.
Examples
import { Faces } from 'scramble-generator';
Faces.RIGHT; // 'RIGHT'
Faces.R; // 'R'
generate
Generates a random scramble for the given cube size.
Parameters
Examples
import { generate } from 'scramble-generator';
generate({ cubeSize: 3 });
// [ { face: 'U', longFace: 'UP', inverted: false, double: true },
// { face: 'R', longFace: 'RIGHT', inverted: true, double: false },
// { face: 'D', longFace: 'DOWN', inverted: false, double: true }, ... ]
Returns Array<Move> A list of moves representing the scramble for the cube.
format
Formats a given scramble as a string.
Parameters
Examples
import { format, Faces } from 'scramble-generator';
format([{
face: Faces.R,
inverted: true
}, {
face: Faces.U,
double: true
}, {
face: Faces.L
}])
// "R' U2 L"
Returns string String representation of the given scramble.
formatted
Generates a random formatted scramble.
Parameters
options
object? Same options passed togenerate
Examples
import { formatted } from 'scramble-generator';
formatted({ cubeSize: 3 }); // "F2 R2 F D2 L U2 L U2 F2 D2 R' F2 L' D' B2 R2 F2 R2 F2 R2"
Returns string The formatted scramble.
parse
Takes a given string and parses it into as scramble of Move objects.
Parameters
scrambleString
string The string to be parse as a scramble.
Examples
import { parse } from 'scramble-generator';
parse("R' U F D2");
// [ { face: 'R', longFace: 'RIGHT', inverted: true, double: false },
// { face: 'U', longFace: 'UP', inverted: false, double: false },
// { face: 'F', longFace: 'FRONT', inverted: false, double: false },
// { face: 'D', longFace: 'DOWN', inverted: false, double: true } ]
parse("R J Q D2 F U'"); // null
Returns (Array<Move> | null) An array of Move objects representing the given scramble, or null if the scramble isn't valid.