{"id":15628313,"url":"https://github.com/ldez/cubejs","last_synced_at":"2025-04-12T22:21:35.648Z","repository":{"id":11190098,"uuid":"13570052","full_name":"ldez/cubejs","owner":"ldez","description":"cube.js -- JavaScript library for modeling and solving the 3x3x3 Rubik's Cube","archived":false,"fork":false,"pushed_at":"2024-05-09T12:38:58.000Z","size":820,"stargazers_count":323,"open_issues_count":8,"forks_count":47,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-04-04T01:28:40.252Z","etag":null,"topics":["coffeescript","javascript","rubiks-cube","scrambler","solver"],"latest_commit_sha":null,"homepage":"http://ldez.github.io/cubejs/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ldez.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-10-14T18:52:32.000Z","updated_at":"2025-03-30T04:46:02.000Z","dependencies_parsed_at":"2024-06-18T18:34:19.836Z","dependency_job_id":"e35e65f4-6ab0-4440-b2a3-1775a18f2209","html_url":"https://github.com/ldez/cubejs","commit_stats":{"total_commits":143,"total_committers":14,"mean_commits":"10.214285714285714","dds":0.6153846153846154,"last_synced_commit":"8a38bfee6a0e36599934af693a774cf38713bad5"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ldez%2Fcubejs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ldez%2Fcubejs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ldez%2Fcubejs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ldez%2Fcubejs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ldez","download_url":"https://codeload.github.com/ldez/cubejs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248638602,"owners_count":21137688,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["coffeescript","javascript","rubiks-cube","scrambler","solver"],"created_at":"2024-10-03T10:21:52.999Z","updated_at":"2025-04-12T22:21:35.616Z","avatar_url":"https://github.com/ldez.png","language":"JavaScript","readme":"# cube.js\n\n[![Build Status](https://travis-ci.org/ldez/cubejs.svg?branch=master)](https://travis-ci.org/ldez/cubejs)\n[![npm version](https://badge.fury.io/js/cubejs.svg)](https://www.npmjs.com/package/cubejs)\n\n**cube.js** is a JavaScript library for modeling and solving the 3x3x3 Rubik's Cube.\n\nMost notably, it implements [Herbert Kociemba's two-phase algorithm](http://kociemba.org/cube.htm) for solving any state of the\ncube very fast in 22 moves or less.\n\n**cube.js** is written in [CoffeeScript](http://coffeescript.org/), and runs on [node.js](http://nodejs.org/) and modern browsers.\n\nA full-fledged random state scrambler demo is available [here](http://ldez.github.io/cubejs/).\n\n## Examples\n\n`cube.js` gives you basic cube manipulation:\n\n- Web:\n\n```javascript\n// Create a new solved cube instance\nconst cube = new Cube();\n\n// Apply an algorithm or randomize the cube state\ncube.move(\"U F R2 B' D2 L'\");\ncube.randomize();\n\n// Create a new random cube\nconst randomCube = Cube.random();\n```\n\n- Node:\n\n```javascript\nconst Cube = require('cubejs');\n\n// Create a new solved cube instance\nconst cube = new Cube();\n\n// Apply an algorithm or randomize the cube state\ncube.move(\"U F R2 B' D2 L'\");\ncube.randomize();\n\n// Create a new random cube\nconst randomCube = Cube.random();\n```\n\nFrom `solve.js` you can use the methods below, to solve the cube using [Herbert Kociemba's two-phase algorithm](http://kociemba.org/cube.htm).\n\n- Web:\n\n```javascript\n// This takes 4-5 seconds on a modern computer\nCube.initSolver();\n\n// These typically take from 0.01s to 0.4s, rarely up to 2s\ncube.solve();        // =\u003e \"D2 B' R' B L' B ...\"\nrandomCube.solve();  // =\u003e \"R B' R U' D' R' ...\"\n```\n\nTo offload the solving to a web worker, use `async.js` and `worker.js`:\n\n```javascript\nCube.asyncInit('lib/worker.js', function() {\n    // Initialized\n    Cube.asyncSolve(randomCube, function(algorithm) {\n        console.log(algorithm);\n    });\n});\n```\n\n- Node:\n\n```javascript\nconst Cube = require('cubejs');\n\n// This takes 4-5 seconds on a modern computer\nCube.initSolver();\n\n// These typically take from 0.01s to 0.4s, rarely up to 2s\ncube.solve();        // =\u003e \"D2 B' R' B L' B ...\"\nrandomCube.solve();  // =\u003e \"R B' R U' D' R' ...\"\n```\n\n\n## API Reference\n\nAll functionality is implemented in the `Cube` object.\nThere are a bunch of files, of which `cube.js` is always required.\n\n### `cube.js`\n\n`cube.js` gives you basic cube manipulation.\n\n#### Class methods\n\n##### `Cube([state])`\n\nThe constructor:\n- without arguments, constructs an identity cube (i.e. a solved cube).\n- with an argument, clones another cube or cube state.\n\n```javascript\nconst cube = new Cube();\nconst other = new Cube(cube);\nconst third = new Cube(cube.toJSON());\n```\n\n##### `Cube.fromString(str)`\n\nReturns a cube that represents the given facelet string.\nThe string consists of 54 characters, 9 per face:\n\n```javascript\n\"UUUUUUUUUR...F...D...L...B...\"\n```\n\n`U` means a facelet of the up face color, `R` means a facelet of the right face color, etc.\n\nThe following diagram demonstrates the order of the facelets:\n\n```\n             +------------+\n             | U1  U2  U3 |\n             |            |\n             | U4  U5  U6 |\n             |            |\n             | U7  U8  U9 |\n+------------+------------+------------+------------+\n| L1  L2  L3 | F1  F2  F3 | R1  R2  R3 | B1  B2  B3 |\n|            |            |            |            |\n| L4  L5  L6 | F4  F5  F6 | R4  R5  R6 | B4  B5  B6 |\n|            |            |            |            |\n| L7  L8  L9 | F7  F8  F9 | R7  R8  R9 | B7  B8  B9 |\n+------------+------------+------------+------------+\n             | D1  D2  D3 |\n             |            |\n             | D4  D5  D6 |\n             |            |\n             | D7  D8  D9 |\n             +------------+\n```\n\n##### `Cube.random()`\n\nReturn a new, randomized cube.\n\n```javascript\nconst cube = Cube.random();\n```\n\n##### `Cube.inverse(algoritm)`\n\nGiven an algorithm (a string, array of moves, or a single move), returns its inverse.\n\n```javascript\nCube.inverse(\"F B' R\");    // =\u003e \"R' B F'\"\nCube.inverse([1, 8, 12]);  // =\u003e [14, 6, 1]\nCube.inverse(8);           // =\u003e 6\n```\n\nSee below for numeric moves.\n\n#### Instance methods\n\n##### `init(state)`\n\nResets the cube state to match another cube.\n\n```javascript\nconst random = Cube.random();\nconst cube = new Cube();\ncube.init(random);\n```\n\n##### `identity()`\n\nResets the cube to the identity cube.\n\n```javascript\ncube.identity();\ncube.isSolved();  // =\u003e true\n```\n\n##### `toJSON()`\n\nReturns the cube state as an object.\n\n```javascript\ncube.toJSON();  // =\u003e {cp: [...], co: [...], ep: [...], eo: [...]}\n```\n\n##### `asString()`\n\nReturns the cube's state as a facelet string. See `Cube.fromString()`.\n\n##### `clone()`\n\nReturns a fresh clone of the cube.\n\n##### `randomize()`\n\nRandomizes the cube in place.\n\n##### `isSolved()`\n\nReturns `true` if the cube is solved (i.e. the identity cube), and `false` otherwise.\n\n##### `move(algorithm)`\n\nApplies an algorithm (a string, array of moves, or a single move) to the cube.\n\n```javascript\nconst cube = new Cube();\ncube.isSolved();  // =\u003e true\ncube.move(\"U R F'\");\ncube.isSolved();  // =\u003e false\n```\n\nSee below for numeric moves.\n\n#### Numeric moves\n\nInternally, cube.js treats moves as numbers.\n\n\n| Move | Number |\n|------|--------|\n| U    | 0      |\n| U2   | 1      |\n| U'   | 2      |\n| R    | 3      |\n| R2   | 4      |\n| R'   | 5      |\n| F    | 6      |\n| F2   | 7      |\n| F'   | 8      |\n| D    | 9      |\n| D2   | 10     |\n| D'   | 11     |\n| L    | 12     |\n| L2   | 13     |\n| L'   | 14     |\n| B    | 15     |\n| B2   | 16     |\n| B'   | 17     |\n\n### `solve.js`\n\n`solve.js` implements [Herbert Kociemba's two-phase algorithm](http://kociemba.org/cube.htm)\nfor solving the cube quickly in nearly optimal number of moves.\nThe algorithm is a port of his simple Java implementation without symmetry reductions.\n\nFor the algorithm to work, a computationally intensive precalculation step is required.\nPrecalculation results in a set of lookup tables that guide the heuristic tree search.\nPrecalculation takes 4-5 seconds on a typical modern computer, but migh take longer on older machines.\n\nAfter precalculation is done, solving a cube with at most 22 moves typically takes 0.01-0.4 seconds, but may take up to 1.5-2 seconds.\nAgain, these figures apply for a modern computer, and might be bigger on older machines.\n\nThe maximum search depth (numer of moves) can be configured.\nThe deeper search is allowed, the quicker the solving is.\nThere's usually no reason to change the default of 22 moves.\n\n#### Class methods\n\n##### `Cube.initSolver()`\n\nPerform the precalculation step described above. This must be called before calling `solve()`.\n\n##### `Cube.scramble()`\n\nGenerate a random scramble by taking a random cube state, solving it, and returning the inverse of the solving algorithm.\nBy applying this algorithm to a cube, you end up to the random state.\n\n#### Instance methods\n\n##### `solve([maxDepth])`\n\nReturn an algorithm that solves the cube as a string. `maxDepth` is\nthe maximum number of moves in the solution, and defaults to 22.\n\n\n## License\n\n**cube.js** is licensed under the [MIT License](http://opensource.org/licenses/MIT).\n\n## History\n\n**cube.js** was created by [Petri Lehtinen](http://www.digip.org/about/) aka [akheron](https://github.com/akheron).\nThanks to him.\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fldez%2Fcubejs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fldez%2Fcubejs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fldez%2Fcubejs/lists"}