{"id":13832291,"url":"https://github.com/daniel-j/node-two-phase-algorithm","last_synced_at":"2025-10-27T10:05:40.962Z","repository":{"id":7345314,"uuid":"8668887","full_name":"daniel-j/node-two-phase-algorithm","owner":"daniel-j","description":"A port of Herbert Kociemba's Two-Phase-Algorithm for solving Rubik's cube.","archived":false,"fork":false,"pushed_at":"2013-03-12T13:28:26.000Z","size":2704,"stargazers_count":17,"open_issues_count":1,"forks_count":5,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-26T19:03:57.819Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/daniel-j.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-03-09T11:30:04.000Z","updated_at":"2024-01-24T01:51:10.000Z","dependencies_parsed_at":"2022-08-29T16:53:29.315Z","dependency_job_id":null,"html_url":"https://github.com/daniel-j/node-two-phase-algorithm","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daniel-j%2Fnode-two-phase-algorithm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daniel-j%2Fnode-two-phase-algorithm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daniel-j%2Fnode-two-phase-algorithm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daniel-j%2Fnode-two-phase-algorithm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/daniel-j","download_url":"https://codeload.github.com/daniel-j/node-two-phase-algorithm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248650557,"owners_count":21139670,"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":[],"created_at":"2024-08-04T10:01:58.626Z","updated_at":"2025-10-27T10:05:35.915Z","avatar_url":"https://github.com/daniel-j.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"\nnode-two-phase-algorithm\n============\n\n### An algorithm to solve Rubik's cube.\n\nThe Two-Phase-Algorithm was created by Herbert Kociemba, read more: http://kociemba.org/cube.htm\n\nThis is a Node.js module ported from his Java package.\n\nThis module uses child_process.fork() to keep the main process from freezing.\n\nInstallation\n------------\nGo to your node_modules folder and execute:\n`git clone git://github.com/daniel-j/node-two-phase-algorithm.git twophase`\n\nExample\n-------\nHere is an example to solve a random-generated cube:\n\n``` javascript\n#!/usr/bin/env node\nvar twophase = require('twophase');\n\nconsole.log(\"Initiating algorithm...\");\ntwophase.initialize(function () {\n\tconsole.log(\"Ready\");\n\n\t// This just tests the solve, solution is F\n\ttwophase.solve(\"UUUUUURRRDRRDRRDRRFFFFFFFFFLLLDDDDDDLLULLULLUBBBBBBBBB\", 30, 60, false, function (err, solution) {\n\t\tif (err) console.error(err);\n\n\t\ttwophase.randomCube(function (err, randomCube) {\n\t\t\tif (err) console.error(err);\n\t\t\tvar cube = randomCube;\n\t\t\t//cube = \"DUDLUDLFDRBRFRBLUUBUBLFRLDFFFUDDBRDRBFUBLUULDFRLRBLBRF\";\n\t\t\tconsole.log(cube);\n\n\t\t\ttwophase.solve(cube, 30, 60, false, function (err, solution) {\n\t\t\t\tif (err) console.error(err);\n\t\t\t\tconsole.log(\"Solution:\", solution);\n\t\t\t\ttwophase.close();\n\t\t\t});\n\t\t});\n\t\t\n\t});\n});\n```\nExample output:\n```\nInitiating algorithm...\nGenerating/loading tables...\nLoading twistMove...\nLoading flipMove...\nLoading FRtoBR_Move...\nLoading URFtoDLF_Move...\nLoading URtoDF_Move...\nLoading URtoUL_Move...\nLoading UBtoDF_Move...\nLoading MergeURtoULandUBtoDF...\nLoading Slice_URFtoDLF_Parity_Prun...\nLoading Slice_URtoDF_Parity_Prun...\nLoading Slice_Twist_Prun...\nLoading Slice_Flip_Prun...\nAll tables generated/loaded\nReady\nULRRULBBDBFBRRFUULULLRFURRFDBRBDBRLDFFLDLDDDFUULUBFFDB\nSolution: F' U F D' F' R B' L B2 D F' U F2 R2 D B2 R2 L2 U'\n```\n\nAPI\n---\n### twophase.initialize(callback)\nThis loads the algorithm and the tables (if the tables don't exist on disk, it generates them).\nThis can take some time, depending on your hardware.\n\n### twophase.solve(facelets, maxDepth, timeOut, useSeparator, callback)\nThis will attempt to calculate a solution of a cube. The facelets are the faces of the cube you're trying to solve. A solved cube looks like this: `UUUUUUUUURRRRRRRRRFFFFFFFFFDDDDDDDDDLLLLLLLLLBBBBBBBBB`\n\nmaxDepth is the maximum moves that the algorithm will go before it gives up.\n\ntimeOut is the maximum time in seconds that the algorithm has to solve the cube in. If exceeded, it gives up.\n\n### twophase.randomCube(callback)\nThis lets you generate random cubes as facelets data.\n\n### twophase.verify(cube, callback)\nThis verifies if the cube is solvable.\ncallback contains the parameters (err, code)\n\n### twophase.close()\nThis closes the fork/child process. Use it when you are finished with the module.\nYou can call initialize after close, as if you restarted the program.\nThis will regenerate/reload all the tables again, as with the first initialize call.\n\n\nCredits\n-------\nThanks to Herbert Kociemba for creating the original Two-Phase-Algorithm in Java. Also thanks to Hans Andersson for creating the LEGO Mindstorms cube solver Tilted Twister (http://tiltedtwister.com/), which got me started porting the Java-package in the first place.\nAnd credits go to Dr. Axel Rauschmayer for creating the enums node.js module, which I needed to port the enums from Java: http://www.2ality.com/2011/10/enums.html\nI had to modify it a bit, adding some methods and indices.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaniel-j%2Fnode-two-phase-algorithm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdaniel-j%2Fnode-two-phase-algorithm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaniel-j%2Fnode-two-phase-algorithm/lists"}