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.
npm install cube-state-engine
class CubeEngine { isSolved():boolean, getMoves(asString: boolean): string, state(): { UPPER: string[][]; LEFT: string[][]; FRONT: string[][]; RIGHT: string[][]; BACK: string[][]; DOWN: string[][]; } rotateU(clockwise: boolean): void, rotateF(clockwise: boolean): void, rotateD(clockwise: boolean): void, rotateX(clockwise: boolean): void, rotateY(clockwise: boolean): void, rotateL(clockwise: boolean): void, rotateR(clockwise: boolean): void, }
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) }, 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);