GithubHelp home page GithubHelp logo

coder13 / alg.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cubing/alg.js

0.0 3.0 0.0 244 KB

A library for parsing and transforming puzzle algorithms ("algs").

Home Page: https://www.npmjs.org/package/alg

License: Other

Makefile 0.21% JavaScript 99.79%

alg.js's Introduction

alg.js

A library for parsing and transforming puzzle algorithms ("algs"). Spinout project from twisty.js.

This currently only parses SiGNw notation for cubes. It will handle more puzzles in the future.

Install

> npm install alg

Or include alg.js and alg_jison.js in an HTML page.

Simple Usage

> var alg = require("alg");
> alg.cube.invert("[R, U] R' F R2 U' R' U' R U R' F'")
  "F R U' R' U R U R2' F' R [U, R]"

Useful methods include:

  • simplify
  • invert
  • mirrorAcrossM
  • mirrorAcrossS
  • expand
  • countMoves

Parsing to JSON

> var alg = require("alg");
> alg.cube.fromString("R U R'")
[ { type: 'move',
    base: 'R',
    amount: 1,
    location:
     { first_line: 1,
       last_line: 1,
       first_column: 0,
       last_column: 1 } },
  { type: 'move',
    base: 'U',
    amount: 1,
    location:
     { first_line: 1,
       last_line: 1,
       first_column: 2,
       last_column: 3 } },
  { type: 'move',
    base: 'R',
    amount: -1,
    location:
     { first_line: 1,
       last_line: 1,
       first_column: 4,
       last_column: 6 } } ]

JSON algs contain the following types of nodes:

  • sequence
  • move
  • commutator
  • conjugate
  • group
  • pause
  • newline
  • comment_short
  • comment_long
  • timestamp

(TODO: provide a full JSON schema somewhere.)

Transformation API

> var alg = require("alg");
> doubleEachMove = alg.cube.makeAlgTraversal();
> doubleEachMove.move = function(move) {
    var newMove = alg.cube.cloneMove(move);
    newMove.amount *= 2;
    return newMove;
  }
> doubleEachMove("R U R' U R U2 R'")
  "R2 U2 R2' U2 R2 U4 R2'"

alg.js's People

Contributors

lgarron avatar

Watchers

James Cloos avatar Cailyn avatar  avatar

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.