CUBE STATE ENGINE

Bryan Lundberg

It's a core state manager that should be able to integrate with custom 3D cube models, making it easy to track and update the cube's state after every move, providing context information, such as when it's solved.

Installation

  npm install cube-state-engine
    

Docs

  class CubeEngine {
    constructor(initialScramble?: string): CubeEngine,
    isSolved(): boolean,
    getMoves(asString?: boolean): string | string[],
    state(): {
      UPPER: string[][];
      LEFT: string[][];
      FRONT: string[][];
      RIGHT: string[][];
      BACK: string[][];
      DOWN: string[][];
    },
    reset(): void,
    applyMoves(sequence: string, options?: { record?: boolean }): void,
    rotateU(clockwise?: boolean): void,
    rotateD(clockwise?: boolean): void,
    rotateL(clockwise?: boolean): void,
    rotateR(clockwise?: boolean): void,
    rotateF(clockwise?: boolean): void,
    rotateB(clockwise?: boolean): void,
    rotateX(clockwise?: boolean): void,
    rotateY(clockwise?: boolean): void,
    rotateZ(clockwise?: boolean): void,
    rotateDw(clockwise?: boolean): void,
    rotateUw(clockwise?: boolean): void,
    rotateRw(clockwise?: boolean): void,
    rotateLw(clockwise?: boolean): void,
    rotateM(clockwise?: boolean): void,
  }

Sample usage

This example showcases a 3D visualization of a Rubik's Cube using the Cubing.js library. You can easily swap it with any other visualization method if preferred. The controls are configured to respond to keyboard input, and a random interval movement has been implemented to demonstrate the library in action.

  const CE = window.CubeEngine;

  const movesMap = {
    f: { move: () => CE.rotateU(false) },
    j: { move: () => CE.rotateU(true) },
    g: { move: () => CE.rotateF(false) },
    h: { move: () => CE.rotateF(true) },
    o: { move: () => CE.rotateB(false) },
    p: { move: () => CE.rotateB(true) },
    i: { move: () => CE.rotateR(true) },
    k: { move: () => CE.rotateR(false) },
    d: { move: () => CE.rotateL(true) },
    e: { move: () => CE.rotateL(false) },
    t: { move: () => CE.rotateX(true) },
    y: { move: () => CE.rotateX(true) },
    b: { move: () => CE.rotateX(false) },
    n: { move: () => CE.rotateX(false) },
    ñ: { move: () => CE.rotateY(true) },
    a: { move: () => CE.rotateY(false) },
    s: { move: () => CE.rotateD(true) },
    l: { move: () => CE.rotateD(false) },
  };

  setInterval(() => {
    const keys = Object.keys(movesMap);
    const randomKey = keys[Math.floor(Math.random() * keys.length)];
    executeMove(randomKey);
  }, 250);
      

3D

Memory

OOO
OOO
OOO
BGG
BGG
BGG
BBG
BBG
BBG
YWW
YWW
YWW
WYY
WYY
WYY
isSolved?: false
Moves: 2
Historial: L L