JSPM

scramble-generator

0.2.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 4
  • Score
    100M100P100Q25912F
  • License MIT

Generate scrambles for Rubik's cubes

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 npm

npm install scramble-generator

0.2.0 has breaking changes. If you're using < v0.2.0, see the upgrading section.

API

generateScramble

Generates a random scramble for the given cube size.

Parameters

  • $0 any (optional, default {})
    • $0.cubeSize (optional, default 3)
    • $0.length (optional, default (cubeSize-2)*20||8)
    • $0.formatted (optional, default true)

Examples

import generateScramble from 'scramble-generator';
generateScramble();
// R' U F D' L ...

generateScramble({ cubeSize: 3, formatted: false });
// [ { face: 'U', inverted: false, double: true },
// { face: 'R', inverted: true, double: false },
// { face: 'D', inverted: false, double: true }, ... ]

Returns (string | Array<Move>)

Faces

Map of Faces.

Type: {}

Examples

import { Faces } from 'scramble-generator';
Faces.R; // 'R'
Faces.U; // 'U'

Face

The face of the cube to turn is represented by a single-character string

Type: $Keys<any>

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: {face: Face, inverted: boolean, double: boolean, layerCount: number}

Properties

formatScramble

Formats a given scramble as a string.

Parameters

  • scramble Array<Move> List of Move objects representing a scramble to be formatted.

Examples

import { formatScramble, 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.

Upgrading

From v0.1.x

v0.2.0 has breaking changes. To upgrade from an earlier version:

// Before:
import { formatted, generate, format, parse } from 'scramble-generator';

formatted(); // R U' D ...
const scramble = generate(); // [{ face: 'R', longFace: 'RIGHT', inverted: true, double: false }, ...]
format(scramble) // R' ...
parse("R' U L") // [{ face: 'R', longFace: 'RIGHT', inverted: true, double: false }, ...]

// After
import generateScramble, { formatScramble } from 'scramble-generator';
import parseScramble from 'scramble-parser';

generateScramble(); // R U' D ...
const scramble = generateScramble({ formatted: false }); // [{ face: 'R', inverted: true, double: false }, ...] (NB: `longFace` has been removed)
formatScramble(scramble); // R' ...
parseScramble("R' U L"); // [{ face: 'R', inverted: true, double: false }, ...] (NB: `longFace` has been removed)

These breaking changes are necessary to facilitate moving towards v1.0.0, after which the package will adhere strictly to semver. There might be some more breaking changes