Coder Social home page Coder Social logo

cube-solver's Introduction

cube-solver

This module contains a collection of Rubik's cube solvers implemented in JavaScript. It can solve a given cube using the fantastic Kociemba two-phase algorithm, generate random state scrambles, solve steps such as the cross or the Roux first block, and provide a variety of different scramble types.

Installation

Run yarn install cube-solver or similar, then require the cube-solver module. You can also manually add the bundle file to your webpage using this unpkg link, in which case the solver will be available globally as cubeSolver.

Examples

// Get a new random-state scramble.
const scramble = cubeSolver.scramble();
// Solve the first block.
cubeSolver.solve(scramble, 'fb') // => R L2 B' U' L2 D' F'
// Get a ZBLL scramble.
cubeSolver.scramble('zbll'); // => R B2 R' U' L U' L U' F2 R2 U' B2 U R2 D' F2 U'

Notes

The full 3x3 solver is pretty slow compared to other solvers such as the GWT compiled version of min2phase - it rather aims to be simple and extensible. Unless explicitly initialized, the Kociemba solver initializes when solving the first cube, which usually takes around 2 seconds. Generating and solving a random cube takes around 100ms on average, but for some cubes the number can be quite high. The EOLine, FB, and Cross solvers initialize pretty quickly, while the XCross solver also takes around 2 seconds. As a consequence, you probably want to use this library in conjunction with web workers.

Documentation

The solver exposes three main methods.

  • cubeSolver.scramble(type = '3x3') lets you generate scrambles for the entire cube or subsets of it --- see below for a list of available scramblers.
  • cubeSolver.solve(scramble, type = 'kociemba') lets you solve either the entire cube or a subset of it for a given scramble. See below for a list of available solvers.
  • cubeSolver.initialize(solver) lets you initialize solvers so that the first solve is quicker. See below for a list of available solvers. Note that to speed up ramdom-state scramblers, the Kociemba solver should be initialized.

In general, the solvers will put the feature being solved for on the bottom. For example, using normal scrambling orientation, solving for an XCross will yield a yellow cross with the front-left pair solved. To solve other positions, you can apply pre-moves to your scrambles. This example shows how to find a bottom-left yellow XCross:

const scramble = `U2 B2 D R' F R2 U2 L D R2 L2 F2 U R2 U' L2 D F2 R2`;
// Find an optimal solution for cross + the back left pair.
cubeSolver.solve(`y ${scramble}`); // => U L2 F' R' F' D L' D

Available scramble types

Type Description
3x3 A random-state 3x3 scrable.
2gll A 2-generator last layer scramble.
cmll A Roux CMLL scramble.
corners A corners-only scramble.
edges An edges-only scramble.
lse A Roux LSE scramble.
lsll Scramble for last slot + last layer.
pll A PLL scramble.
zbll A ZBLL scramble.
zzls Scramble for ZZ last slot + last layer.

Available solver types

Type Description
kociemba Solve the whole cube using the Kociemba algorithm.
cross Solve the CFOP cross.
eoline Solve the ZZ EOLine.
fb Solve the Roux first block, on the bottom left.
xcross Solve an extended CFOP cross.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.