diff --git a/dist/enums.d.ts b/dist/enums.d.ts new file mode 100644 index 0000000..161ea5d --- /dev/null +++ b/dist/enums.d.ts @@ -0,0 +1,19 @@ +export declare enum CubePlane { + X = "x", + Y = "y", + Z = "z" +} +export declare enum Side { + L = "L", + R = "R", + U = "U", + D = "D", + F = "F", + B = "B" +} +export declare enum Modifier { + Double = "2", + CounterClockwise = "'", + Clockwise = "" +} +//# sourceMappingURL=enums.d.ts.map \ No newline at end of file diff --git a/dist/enums.d.ts.map b/dist/enums.d.ts.map new file mode 100644 index 0000000..f96a10b --- /dev/null +++ b/dist/enums.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"enums.d.ts","sourceRoot":"","sources":["../src/enums.ts"],"names":[],"mappings":"AAAA,oBAAY,SAAS;IACnB,CAAC,MAAM;IACP,CAAC,MAAM;IACP,CAAC,MAAM;CACR;AAED,oBAAY,IAAI;IACd,CAAC,MAAM;IACP,CAAC,MAAM;IACP,CAAC,MAAM;IACP,CAAC,MAAM;IACP,CAAC,MAAM;IACP,CAAC,MAAM;CACR;AAED,oBAAY,QAAQ;IAClB,MAAM,MAAM;IACZ,gBAAgB,MAAO;IACvB,SAAS,KAAK;CACf"} \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts new file mode 100644 index 0000000..f0e67a9 --- /dev/null +++ b/dist/index.d.ts @@ -0,0 +1,6 @@ +export declare const cube: (size?: number, numTurns?: number) => String; +export declare const megaminx: () => String; +export declare const pyraminx: (numTurns?: number) => String; +export declare const skewb: (numTurns?: number) => String; +export declare const square1: (numTurns?: number) => any; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/index.d.ts.map b/dist/index.d.ts.map new file mode 100644 index 0000000..3d5f5c4 --- /dev/null +++ b/dist/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AA2BA,eAAO,MAAM,IAAI,8CAEhB,CAAA;AAED,eAAO,MAAM,QAAQ,cAEpB,CAAA;AAED,eAAO,MAAM,QAAQ,cAAe,MAAM,WAEzC,CAAA;AAED,eAAO,MAAM,KAAK,cAAe,MAAM,WAEtC,CAAA;AAED,eAAO,MAAM,OAAO,cAAe,MAAM,QAIxC,CAAA"} \ No newline at end of file diff --git a/dist/index.html b/dist/index.html deleted file mode 100644 index e7b00ad..0000000 --- a/dist/index.html +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/dist/index.js b/dist/index.js index 4fe4901..2644c16 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,2 +1,2 @@ -!function(r,o){"object"==typeof exports&&"object"==typeof module?module.exports=o():"function"==typeof define&&define.amd?define([],o):"object"==typeof exports?exports["sr-scrambler"]=o():r["sr-scrambler"]=o()}(self,(function(){return(()=>{"use strict";var r,o,t,n={d:(r,o)=>{for(var t in o)n.o(o,t)&&!n.o(r,t)&&Object.defineProperty(r,t,{enumerable:!0,get:o[t]})},o:(r,o)=>Object.prototype.hasOwnProperty.call(r,o),r:r=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(r,"__esModule",{value:!0})}},e={};function i(r){return!Array.isArray(r)||r.length<1?null:r[Math.floor(Math.random()*r.length)]}n.r(e),n.d(e,{cube:()=>s,megaminx:()=>p,pyraminx:()=>h,skewb:()=>d,square1:()=>v}),function(r){r.X="x",r.Y="y",r.Z="z"}(r||(r={})),function(r){r.L="L",r.R="R",r.U="U",r.D="D",r.F="F",r.B="B"}(o||(o={})),function(r){r.Double="2",r.CounterClockwise="'",r.Clockwise=""}(t||(t={}));var u=function(r,o,t){if(t||2===arguments.length)for(var n,e=0,i=o.length;e2?"".concat(r.depth):"",t=r.depth>1?"w":"";return"".concat(o).concat(r.face).concat(t).concat(r.modifier)}(r)})).join(" ")},s=function(n,e){return void 0===n&&(n=3),void 0===e&&(e=21),l(function(n,e){var i;return void 0===n&&(n=3),void 0===e&&(e=21),f([o.L,o.R,o.U,o.D,o.F,o.B],((i={})[o.L]=r.X,i[o.R]=r.X,i[o.U]=r.Y,i[o.D]=r.Y,i[o.F]=r.Z,i[o.B]=r.Z,i),[t.Double,t.CounterClockwise,t.Clockwise],Math.floor(n/2),e)}(n,e))},p=function(){return l(function(r,o){void 0===r&&(r=10),void 0===o&&(o=6);for(var t=[],n=0;n0){var t;r-=t=o.pop(),o.unshift(t)}},e=function(r){for(;0!=r;)if(r<0){if((o=t.shift())>-r)throw Error("breaking");r+=o,t.push(o)}else if(r>0){var o;if((o=t.pop())>r)throw Error("breaking2");r-=o,t.unshift(o)}},f=function(){for(var r=0,n=0,e=0,i=o.length;i>0&&e<6;i--)e+=o[i-1],r++;for(e=0,i=0;i6)return!1;return!0},a=function(r,o){if(o<0){for(;o<0;){if((t=r.shift())>Math.abs(o))return!1;o+=t,r.push(t)}return c(r)}if(o>0){for(;o>0;){var t;if(o<(t=r.pop()))return!1;o-=t,r.unshift(t)}return c(r)}return!0},l=function(){for(var r=[],n=[],e=-6;e<=6;e++)a(u([],o,!0),e)&&r.push(e),a(u([],t,!0),e)&&n.push(e);return{possibleTop:r,possibleBottom:n}},s=[],p=0;p{"use strict";var e,t,o,r={d:(e,t)=>{for(var o in t)r.o(t,o)&&!r.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},l={};function n(e){return!Array.isArray(e)||e.length<1?null:e[Math.floor(Math.random()*e.length)]}r.r(l),r.d(l,{cube:()=>p,megaminx:()=>a,pyraminx:()=>c,skewb:()=>h,square1:()=>d}),function(e){e.X="x",e.Y="y",e.Z="z"}(e||(e={})),function(e){e.L="L",e.R="R",e.U="U",e.D="D",e.F="F",e.B="B"}(t||(t={})),function(e){e.Double="2",e.CounterClockwise="'",e.Clockwise=""}(o||(o={}));const i=(e,t,o,r,l)=>{let i,f,s=[];for(var u=0;ue.map((e=>Array.isArray(e)?u(e)+"\n":(e=>{const t=e.depth>2?`${e.depth}`:"",o=e.depth>1?"w":"";return`${t}${e.face}${o}${e.modifier}`})(e))).join(" "),p=(r=3,l=21)=>u(((r=3,l=21)=>i([t.L,t.R,t.U,t.D,t.F,t.B],{[t.L]:e.X,[t.R]:e.X,[t.U]:e.Y,[t.D]:e.Y,[t.F]:e.Z,[t.B]:e.Z},[o.Double,o.CounterClockwise,o.Clockwise],Math.floor(r/2),l))(r,l)),a=()=>u(((e=10,t=6)=>{let o=[];for(let r=0;ru(((e=10)=>{let r=i([t.L,t.R,t.U,t.B],{[t.L]:"L",[t.R]:"R",[t.U]:"U",[t.B]:"B"},[o.CounterClockwise,o.Clockwise],1,e);var l;return(l=["l","r","u","b"],l.map((e=>({value:e,sort:Math.random()}))).sort(((e,t)=>e.sort-t.sort)).map((({value:e})=>e))).forEach((e=>{let t=n([o.Clockwise,o.CounterClockwise,null]);null!=t&&r.push({face:e,modifier:t,depth:1})})),r})(e)),h=e=>u(((e=9)=>i([t.L,t.R,t.U,t.B],{[t.L]:"L",[t.R]:"R",[t.U]:"U",[t.B]:"B"},[o.CounterClockwise,o.Clockwise],1,e))(e)),d=e=>((e=12)=>{let t=[2,1,2,1,2,1,2,1],o=[1,2,1,2,1,2,1,2];const r=e=>{for(;0!=e;)if(e<0){let o=t.shift();e+=o,t.push(o)}else if(e>0){let o=t.pop();e-=o,t.unshift(o)}},l=e=>{for(;0!=e;)if(e<0){let t=o.shift();if(t>-e)throw Error("breaking");e+=t,o.push(t)}else if(e>0){let t=o.pop();if(t>e)throw Error("breaking2");e-=t,o.unshift(t)}},i=()=>{let e=0,r=0,l=0;for(let o=t.length;o>0&&l<6;o--)l+=t[o-1],e++;l=0;for(let e=0;e{let t=0;for(let o=0;o6)return!1;return!0},s=(e,t)=>{if(t<0){for(;t<0;){let o=e.shift();if(o>Math.abs(t))return!1;t+=o,e.push(o)}return f(e)}if(t>0){for(;t>0;){let o=e.pop();if(t{let e=[],r=[];for(let l=-6;l<=6;l++)s([...t],l)&&e.push(l),s([...o],l)&&r.push(l);return{possibleTop:e,possibleBottom:r}};let p=[];for(let t=0;t` (${e.top}, ${e.bottom}) /`)).join("");return l})()})); //# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/index.js.map b/dist/index.js.map index 4cb0663..cec3757 100644 --- a/dist/index.js.map +++ b/dist/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,IACQ,mBAAXG,QAAyBA,OAAOC,IAC9CD,OAAO,GAAIH,GACe,iBAAZC,QACdA,QAAQ,gBAAkBD,IAE1BD,EAAK,gBAAkBC,IARzB,CASGK,MAAM,WACT,M,mBCTA,ICDWC,EAMAC,EASAC,EDdPC,EAAsB,CEA1BA,EAAwB,CAACR,EAASS,KACjC,IAAI,IAAIC,KAAOD,EACXD,EAAoBG,EAAEF,EAAYC,KAASF,EAAoBG,EAAEX,EAASU,IAC5EE,OAAOC,eAAeb,EAASU,EAAK,CAAEI,YAAY,EAAMC,IAAKN,EAAWC,MCJ3EF,EAAwB,CAACQ,EAAKC,IAAUL,OAAOM,UAAUC,eAAeC,KAAKJ,EAAKC,GCClFT,EAAyBR,IACH,oBAAXqB,QAA0BA,OAAOC,aAC1CV,OAAOC,eAAeb,EAASqB,OAAOC,YAAa,CAAEC,MAAO,WAE7DX,OAAOC,eAAeb,EAAS,aAAc,CAAEuB,OAAO,M,KCLhD,SAASC,EAAcC,GAC1B,OAAKC,MAAMC,QAAQF,IAAUA,EAAMG,OAAS,EACjC,KAEJH,EAAMI,KAAKC,MAAMD,KAAKE,SAAWN,EAAMG,S,mFJHlD,SAAWvB,GACPA,EAAa,EAAI,IACjBA,EAAa,EAAI,IACjBA,EAAa,EAA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Q,UAC7EjC,KAAK,K","sources":["webpack://sr-scrambler/webpack/universalModuleDefinition","webpack://sr-scrambler/webpack/bootstrap","webpack://sr-scrambler/./src/enums.ts","webpack://sr-scrambler/webpack/runtime/define property getters","webpack://sr-scrambler/webpack/runtime/hasOwnProperty shorthand","webpack://sr-scrambler/webpack/runtime/make namespace object","webpack://sr-scrambler/./src/util.ts","webpack://sr-scrambler/./src/scrambler/scrambler.ts","webpack://sr-scrambler/./src/index.ts"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"sr-scrambler\"] = factory();\n\telse\n\t\troot[\"sr-scrambler\"] = factory();\n})(self, function() {\nreturn ","// The require scope\nvar __webpack_require__ = {};\n\n","export var CubePlane;\n(function (CubePlane) {\n CubePlane[\"X\"] = \"x\";\n CubePlane[\"Y\"] = \"y\";\n CubePlane[\"Z\"] = \"z\";\n})(CubePlane || (CubePlane = {}));\nexport var Side;\n(function (Side) {\n Side[\"L\"] = \"L\";\n Side[\"R\"] = \"R\";\n Side[\"U\"] = \"U\";\n Side[\"D\"] = \"D\";\n Side[\"F\"] = \"F\";\n Side[\"B\"] = \"B\";\n})(Side || (Side = {}));\nexport var Modifier;\n(function (Modifier) {\n Modifier[\"Double\"] = \"2\";\n Modifier[\"CounterClockwise\"] = \"'\";\n Modifier[\"Clockwise\"] = \"\";\n})(Modifier || (Modifier = {}));\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","export function randomElement(array) {\n if (!Array.isArray(array) || array.length < 1) {\n return null;\n }\n return array[Math.floor(Math.random() * array.length)];\n}\nexport function shuffle(array) {\n return array.map(function (value) { return ({ value: value, sort: Math.random() }); })\n .sort(function (a, b) { return a.sort - b.sort; })\n .map(function (_a) {\n var value = _a.value;\n return value;\n });\n}\n","var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\n if (ar || !(i in from)) {\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\n ar[i] = from[i];\n }\n }\n return to.concat(ar || Array.prototype.slice.call(from));\n};\nimport { CubePlane, Modifier, Side } from \"../enums\";\nimport { randomElement, shuffle } from \"../util\";\nvar generateScramble = function (faces, planeMapping, modifiers, maxDepth, numTurns) {\n var turns = [];\n var previousTurn;\n var newTurn;\n for (var i = 0; i < numTurns; i++) {\n do {\n newTurn = randomElement(faces);\n } while (planeMapping[previousTurn] === planeMapping[newTurn]);\n turns.push({\n face: newTurn,\n depth: Math.floor(Math.random() * maxDepth) + 1,\n modifier: randomElement(modifiers)\n });\n previousTurn = newTurn;\n }\n return turns;\n};\nexport var generateCubeScramble = function (size, numTurns) {\n var _a;\n if (size === void 0) { size = 3; }\n if (numTurns === void 0) { numTurns = 21; }\n return generateScramble([Side.L, Side.R, Side.U, Side.D, Side.F, Side.B], (_a = {},\n _a[Side.L] = CubePlane.X,\n _a[Side.R] = CubePlane.X,\n _a[Side.U] = CubePlane.Y,\n _a[Side.D] = CubePlane.Y,\n _a[Side.F] = CubePlane.Z,\n _a[Side.B] = CubePlane.Z,\n _a), [\n Modifier.Double,\n Modifier.CounterClockwise,\n Modifier.Clockwise\n ], Math.floor(size / 2), numTurns);\n};\nvar pochmanFaces = ['D', 'R'];\nvar pochmanModifiers = ['++', '--'];\n/**\n * generates a pochman scramble for the megaminx\n */\nexport var generateMegaminxScramble = function (sequenceLength, numSequences) {\n if (sequenceLength === void 0) { sequenceLength = 10; }\n if (numSequences === void 0) { numSequences = 6; }\n var turns = [];\n for (var i = 0; i < numSequences; i++) {\n turns[i] = [];\n for (var j = 0; j < sequenceLength; j++) {\n turns[i].push({\n face: pochmanFaces[j % pochmanFaces.length],\n modifier: randomElement(pochmanModifiers),\n depth: 1\n });\n }\n turns[i].push({\n face: 'U',\n modifier: randomElement(['', '\\'']),\n depth: 1\n });\n }\n return turns;\n};\nexport var generateSkewbScramble = function (numTurns) {\n var _a;\n if (numTurns === void 0) { numTurns = 9; }\n return generateScramble([Side.L, Side.R, Side.U, Side.B], (_a = {},\n _a[Side.L] = 'L',\n _a[Side.R] = 'R',\n _a[Side.U] = 'U',\n _a[Side.B] = 'B',\n _a), [\n Modifier.CounterClockwise,\n Modifier.Clockwise\n ], 1, numTurns);\n};\nexport var generatePyraminxScramble = function (numTurns) {\n var _a;\n if (numTurns === void 0) { numTurns = 10; }\n var turns = generateScramble([Side.L, Side.R, Side.U, Side.B], (_a = {},\n _a[Side.L] = 'L',\n _a[Side.R] = 'R',\n _a[Side.U] = 'U',\n _a[Side.B] = 'B',\n _a), [\n Modifier.CounterClockwise,\n Modifier.Clockwise\n ], 1, numTurns);\n shuffle(['l', 'r', 'u', 'b'])\n .forEach(function (point) {\n var modifier = randomElement([Modifier.Clockwise, Modifier.CounterClockwise, null]);\n if (modifier != null) {\n turns.push({\n face: point,\n modifier: modifier,\n depth: 1\n });\n }\n });\n return turns;\n};\nexport var generateSquare1Scramble = function (numTurns) {\n if (numTurns === void 0) { numTurns = 12; }\n var tops = [2, 1, 2, 1, 2, 1, 2, 1];\n var bottom = [1, 2, 1, 2, 1, 2, 1, 2];\n var turnTop = function (turns) {\n while (turns != 0) {\n if (turns < 0) {\n var piece = tops.shift();\n turns += piece;\n tops.push(piece);\n }\n else if (turns > 0) {\n var piece = tops.pop();\n turns -= piece;\n tops.unshift(piece);\n }\n }\n };\n var turnBottom = function (turns) {\n while (turns != 0) {\n if (turns < 0) {\n var piece = bottom.shift();\n if (piece > (-turns)) {\n throw Error(\"breaking\");\n }\n turns += piece;\n bottom.push(piece);\n }\n else if (turns > 0) {\n var piece = bottom.pop();\n if (piece > turns) {\n throw Error(\"breaking2\");\n }\n turns -= piece;\n bottom.unshift(piece);\n }\n }\n };\n var slice = function () {\n var topNum = 0;\n var bottomNum = 0;\n var value = 0;\n for (var i = tops.length; i > 0 && value < 6; i--) {\n value += tops[i - 1];\n topNum++;\n }\n value = 0;\n for (var i = 0; i < bottom.length && value < 6; i++) {\n value += bottom[i];\n bottomNum++;\n }\n var topSlice = tops.splice(tops.length - topNum, tops.length);\n var bottomSlice = bottom.splice(0, bottomNum);\n tops = tops.concat(bottomSlice);\n bottom = topSlice.concat(bottom);\n };\n var isLayerAligned = function (layer) {\n var value = 0;\n for (var i = 0; i < layer.length && value < 6; i++) {\n value += layer[i];\n if (value > 6) {\n return false;\n }\n }\n return true;\n };\n var isMovePossible = function (layer, turns) {\n if (turns < 0) {\n // Take off front, put on end\n while (turns < 0) {\n var piece = layer.shift();\n if (piece > Math.abs(turns)) {\n return false;\n }\n turns += piece;\n layer.push(piece);\n }\n return isLayerAligned(layer);\n }\n else if (turns > 0) {\n // Take off end, put on front\n while (turns > 0) {\n var piece = layer.pop();\n if (turns < piece) {\n return false;\n }\n turns -= piece;\n layer.unshift(piece);\n }\n return isLayerAligned(layer);\n }\n else {\n // Turns = 0, should be possible\n return true;\n }\n };\n var possibleMoves = function () {\n var possibleTop = [];\n var possibleBottom = [];\n for (var i = -6; i <= 6; i++) {\n if (isMovePossible(__spreadArray([], tops, true), i)) {\n possibleTop.push(i);\n }\n if (isMovePossible(__spreadArray([], bottom, true), i)) {\n possibleBottom.push(i);\n }\n }\n return {\n possibleTop: possibleTop,\n possibleBottom: possibleBottom\n };\n };\n var turns = [];\n for (var i = 0; i < numTurns; i++) {\n var moves = possibleMoves();\n var topMove = 0;\n var bottomMove = 0;\n do {\n topMove = randomElement(moves.possibleTop);\n bottomMove = randomElement(moves.possibleBottom);\n } while (topMove === 0 && bottomMove === 0);\n turns.push({\n top: topMove,\n bottom: bottomMove\n });\n turnTop(topMove);\n turnBottom(bottomMove);\n slice();\n }\n return turns;\n};\n","import { generateSquare1Scramble, generateCubeScramble, generateMegaminxScramble, generatePyraminxScramble, generateSkewbScramble } from \"./scrambler/scrambler\";\nvar turnToString = function (turn) {\n var depthLayer = turn.depth > 2 ? \"\".concat(turn.depth) : '';\n var sliceIndicator = turn.depth > 1 ? 'w' : '';\n return \"\".concat(depthLayer).concat(turn.face).concat(sliceIndicator).concat(turn.modifier);\n};\nvar scrambleToString = function (turns) {\n return turns\n .map(function (turn) {\n if (Array.isArray(turn)) {\n return scrambleToString(turn) + '\\n';\n }\n else {\n return turnToString(turn);\n }\n })\n .join(' ');\n};\nexport var cube = function (size, numTurns) {\n if (size === void 0) { size = 3; }\n if (numTurns === void 0) { numTurns = 21; }\n return scrambleToString(generateCubeScramble(size, numTurns));\n};\nexport var megaminx = function () {\n return scrambleToString(generateMegaminxScramble());\n};\nexport var pyraminx = function (numTurns) {\n return scrambleToString(generatePyraminxScramble(numTurns));\n};\nexport var skewb = function (numTurns) {\n return scrambleToString(generateSkewbScramble(numTurns));\n};\nexport var square1 = function (numTurns) {\n return generateSquare1Scramble(numTurns)\n .map(function (turn) { return \" (\".concat(turn.top, \", \").concat(turn.bottom, \") /\"); })\n .join('');\n};\n"],"names":["root","factory","exports","module","define","amd","self","CubePlane","Side","Modifier","__webpack_require__","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","randomElement","array","Array","isArray","length","Math","floor","random","__spreadArray","to","from","pack","arguments","ar","i","l","slice","concat","generateScramble","faces","planeMapping","modifiers","maxDepth","numTurns","previousTurn","newTurn","turns","push","face","depth","modifier","pochmanFaces","pochmanModifiers","scrambleToString","map","turn","depthLayer","sliceIndicator","turnToString","join","cube","size","_a","L","R","U","D","F","B","X","Y","Z","Double","CounterClockwise","Clockwise","generateCubeScramble","megaminx","sequenceLength","numSequences","j","generateMegaminxScramble","pyraminx","sort","a","b","forEach","point","generatePyraminxScramble","skewb","generateSkewbScramble","square1","tops","bottom","turnTop","piece","shift","pop","unshift","turnBottom","Error","topNum","bottomNum","topSlice","splice","bottomSlice","isLayerAligned","layer","isMovePossible","abs","possibleMoves","possibleTop","possibleBottom","moves","topMove","bottomMove","top","generateSquare1Scramble"],"sourceRoot":""} \ No newline at end of file +{"version":3,"file":"index.js","mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,IACQ,mBAAXG,QAAyBA,OAAOC,IAC9CD,OAAO,GAAIH,GACe,iBAAZC,QACdA,QAAQ,gBAAkBD,IAE1BD,EAAK,gBAAkBC,IARzB,CASGK,MAAM,WACT,M,mBCTA,ICDWC,EAMAC,EASAC,EDdPC,EAAsB,CEA1BA,EAAwB,CAACR,EAASS,KACjC,IAAI,IAAIC,KAAOD,EACXD,EAAoBG,EAAEF,EAAYC,KAASF,EAAoBG,EAAEX,EAASU,IAC5EE,OAAOC,eAAeb,EAASU,EAAK,CAAEI,YAAY,EAAMC,IAAKN,EAAWC,MCJ3EF,EAAwB,CAACQ,EAAKC,IAAUL,OAAOM,UAAUC,eAAeC,KAAKJ,EAAKC,GCClFT,EAAyBR,IACH,oBAAXqB,QAA0BA,OAAOC,aAC1CV,OAAOC,eAAeb,EAASqB,OAAOC,YAAa,CAAEC,MAAO,WAE7DX,OAAOC,eAAeb,EAAS,aAAc,CAAEuB,OAAO,M,KCLhD,SAASC,EAAcC,GAC1B,OAAKC,MAAMC,QAAQF,IAAUA,EAAMG,OAAS,EACjC,KAEJH,EAAMI,KAAKC,MAAMD,KAAKE,SAAWN,EAAMG,S,mFJHlD,SAAWvB,GACPA,EAAa,E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IjB,GAAS7C,IAC5BkE,EAAejE,KAAKD,GAG5B,MAAO,CACHiE,YAAAA,EACAC,eAAAA,IAGR,IAAInE,EAAQ,GACZ,IAAK,IAAIC,EAAI,EAAGA,EAAIJ,EAAUI,IAAK,CAC/B,IAAImE,EAAQH,IACRI,EAAU,EACVC,EAAa,EACjB,GACID,EAAUrF,EAAcoF,EAAMF,aAC9BI,EAAatF,EAAcoF,EAAMD,sBAChB,IAAZE,GAAgC,IAAfC,GAC1BtE,EAAME,KAAK,CACPqE,IAAKF,EACLvB,OAAQwB,IAEZvB,EAAQsB,GACRjB,EAAWkB,GACXhB,IAEJ,OAAOtD,GC5LAwE,CAAwB3E,GAC1BY,KAAKC,GAAS,KAAKA,EAAK6D,QAAQ7D,EAAKoC,cACrChC,KAAK,I","sources":["webpack://sr-scrambler/webpack/universalModuleDefinition","webpack://sr-scrambler/webpack/bootstrap","webpack://sr-scrambler/./src/enums.ts","webpack://sr-scrambler/webpack/runtime/define property getters","webpack://sr-scrambler/webpack/runtime/hasOwnProperty shorthand","webpack://sr-scrambler/webpack/runtime/make namespace object","webpack://sr-scrambler/./src/util.ts","webpack://sr-scrambler/./src/scrambler/scrambler.ts","webpack://sr-scrambler/./src/index.ts"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"sr-scrambler\"] = factory();\n\telse\n\t\troot[\"sr-scrambler\"] = factory();\n})(self, function() {\nreturn ","// The require scope\nvar __webpack_require__ = {};\n\n","export var CubePlane;\n(function (CubePlane) {\n CubePlane[\"X\"] = \"x\";\n CubePlane[\"Y\"] = \"y\";\n CubePlane[\"Z\"] = \"z\";\n})(CubePlane || (CubePlane = {}));\nexport var Side;\n(function (Side) {\n Side[\"L\"] = \"L\";\n Side[\"R\"] = \"R\";\n Side[\"U\"] = \"U\";\n Side[\"D\"] = \"D\";\n Side[\"F\"] = \"F\";\n Side[\"B\"] = \"B\";\n})(Side || (Side = {}));\nexport var Modifier;\n(function (Modifier) {\n Modifier[\"Double\"] = \"2\";\n Modifier[\"CounterClockwise\"] = \"'\";\n Modifier[\"Clockwise\"] = \"\";\n})(Modifier || (Modifier = {}));\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","export function randomElement(array) {\n if (!Array.isArray(array) || array.length < 1) {\n return null;\n }\n return array[Math.floor(Math.random() * array.length)];\n}\nexport function shuffle(array) {\n return array.map(value => ({ value, sort: Math.random() }))\n .sort((a, b) => a.sort - b.sort)\n .map(({ value }) => value);\n}\n","import { CubePlane, Modifier, Side } from \"../enums\";\nimport { randomElement, shuffle } from \"../util\";\nconst generateScramble = (faces, planeMapping, modifiers, maxDepth, numTurns) => {\n let turns = [];\n let previousTurn;\n let newTurn;\n for (var i = 0; i < numTurns; i++) {\n do {\n newTurn = randomElement(faces);\n } while (planeMapping[previousTurn] === planeMapping[newTurn]);\n turns.push({\n face: newTurn,\n depth: Math.floor(Math.random() * maxDepth) + 1,\n modifier: randomElement(modifiers)\n });\n previousTurn = newTurn;\n }\n return turns;\n};\nexport const generateCubeScramble = (size = 3, numTurns = 21) => {\n return generateScramble([Side.L, Side.R, Side.U, Side.D, Side.F, Side.B], {\n [Side.L]: CubePlane.X,\n [Side.R]: CubePlane.X,\n [Side.U]: CubePlane.Y,\n [Side.D]: CubePlane.Y,\n [Side.F]: CubePlane.Z,\n [Side.B]: CubePlane.Z\n }, [\n Modifier.Double,\n Modifier.CounterClockwise,\n Modifier.Clockwise\n ], Math.floor(size / 2), numTurns);\n};\nconst pochmanFaces = ['D', 'R'];\nconst pochmanModifiers = ['++', '--'];\n/**\n * generates a pochman scramble for the megaminx\n */\nexport const generateMegaminxScramble = (sequenceLength = 10, numSequences = 6) => {\n let turns = [];\n for (let i = 0; i < numSequences; i++) {\n turns[i] = [];\n for (let j = 0; j < sequenceLength; j++) {\n turns[i].push({\n face: pochmanFaces[j % pochmanFaces.length],\n modifier: randomElement(pochmanModifiers),\n depth: 1\n });\n }\n turns[i].push({\n face: 'U',\n modifier: randomElement(['', '\\'']),\n depth: 1\n });\n }\n return turns;\n};\nexport const generateSkewbScramble = (numTurns = 9) => {\n return generateScramble([Side.L, Side.R, Side.U, Side.B], {\n [Side.L]: 'L',\n [Side.R]: 'R',\n [Side.U]: 'U',\n [Side.B]: 'B'\n }, [\n Modifier.CounterClockwise,\n Modifier.Clockwise\n ], 1, numTurns);\n};\nexport const generatePyraminxScramble = (numTurns = 10) => {\n let turns = generateScramble([Side.L, Side.R, Side.U, Side.B], {\n [Side.L]: 'L',\n [Side.R]: 'R',\n [Side.U]: 'U',\n [Side.B]: 'B'\n }, [\n Modifier.CounterClockwise,\n Modifier.Clockwise\n ], 1, numTurns);\n shuffle(['l', 'r', 'u', 'b'])\n .forEach(point => {\n let modifier = randomElement([Modifier.Clockwise, Modifier.CounterClockwise, null]);\n if (modifier != null) {\n turns.push({\n face: point,\n modifier: modifier,\n depth: 1\n });\n }\n });\n return turns;\n};\nexport const generateSquare1Scramble = (numTurns = 12) => {\n let tops = [2, 1, 2, 1, 2, 1, 2, 1];\n let bottom = [1, 2, 1, 2, 1, 2, 1, 2];\n const turnTop = (turns) => {\n while (turns != 0) {\n if (turns < 0) {\n let piece = tops.shift();\n turns += piece;\n tops.push(piece);\n }\n else if (turns > 0) {\n let piece = tops.pop();\n turns -= piece;\n tops.unshift(piece);\n }\n }\n };\n const turnBottom = (turns) => {\n while (turns != 0) {\n if (turns < 0) {\n let piece = bottom.shift();\n if (piece > (-turns)) {\n throw Error(\"breaking\");\n }\n turns += piece;\n bottom.push(piece);\n }\n else if (turns > 0) {\n let piece = bottom.pop();\n if (piece > turns) {\n throw Error(\"breaking2\");\n }\n turns -= piece;\n bottom.unshift(piece);\n }\n }\n };\n const slice = () => {\n let topNum = 0;\n let bottomNum = 0;\n let value = 0;\n for (let i = tops.length; i > 0 && value < 6; i--) {\n value += tops[i - 1];\n topNum++;\n }\n value = 0;\n for (let i = 0; i < bottom.length && value < 6; i++) {\n value += bottom[i];\n bottomNum++;\n }\n const topSlice = tops.splice(tops.length - topNum, tops.length);\n const bottomSlice = bottom.splice(0, bottomNum);\n tops = tops.concat(bottomSlice);\n bottom = topSlice.concat(bottom);\n };\n const isLayerAligned = (layer) => {\n let value = 0;\n for (let i = 0; i < layer.length && value < 6; i++) {\n value += layer[i];\n if (value > 6) {\n return false;\n }\n }\n return true;\n };\n const isMovePossible = (layer, turns) => {\n if (turns < 0) {\n // Take off front, put on end\n while (turns < 0) {\n let piece = layer.shift();\n if (piece > Math.abs(turns)) {\n return false;\n }\n turns += piece;\n layer.push(piece);\n }\n return isLayerAligned(layer);\n }\n else if (turns > 0) {\n // Take off end, put on front\n while (turns > 0) {\n let piece = layer.pop();\n if (turns < piece) {\n return false;\n }\n turns -= piece;\n layer.unshift(piece);\n }\n return isLayerAligned(layer);\n }\n else {\n // Turns = 0, should be possible\n return true;\n }\n };\n const possibleMoves = () => {\n let possibleTop = [];\n let possibleBottom = [];\n for (let i = -6; i <= 6; i++) {\n if (isMovePossible([...tops], i)) {\n possibleTop.push(i);\n }\n if (isMovePossible([...bottom], i)) {\n possibleBottom.push(i);\n }\n }\n return {\n possibleTop,\n possibleBottom\n };\n };\n let turns = [];\n for (let i = 0; i < numTurns; i++) {\n let moves = possibleMoves();\n let topMove = 0;\n let bottomMove = 0;\n do {\n topMove = randomElement(moves.possibleTop);\n bottomMove = randomElement(moves.possibleBottom);\n } while (topMove === 0 && bottomMove === 0);\n turns.push({\n top: topMove,\n bottom: bottomMove\n });\n turnTop(topMove);\n turnBottom(bottomMove);\n slice();\n }\n return turns;\n};\n","import { generateSquare1Scramble, generateCubeScramble, generateMegaminxScramble, generatePyraminxScramble, generateSkewbScramble } from \"./scrambler/scrambler\";\nconst turnToString = (turn) => {\n const depthLayer = turn.depth > 2 ? `${turn.depth}` : '';\n const sliceIndicator = turn.depth > 1 ? 'w' : '';\n return `${depthLayer}${turn.face}${sliceIndicator}${turn.modifier}`;\n};\nconst scrambleToString = (turns) => {\n return turns\n .map(turn => {\n if (Array.isArray(turn)) {\n return scrambleToString(turn) + '\\n';\n }\n else {\n return turnToString(turn);\n }\n })\n .join(' ');\n};\nexport const cube = (size = 3, numTurns = 21) => {\n return scrambleToString(generateCubeScramble(size, numTurns));\n};\nexport const megaminx = () => {\n return scrambleToString(generateMegaminxScramble());\n};\nexport const pyraminx = (numTurns) => {\n return scrambleToString(generatePyraminxScramble(numTurns));\n};\nexport const skewb = (numTurns) => {\n return scrambleToString(generateSkewbScramble(numTurns));\n};\nexport const square1 = (numTurns) => {\n return generateSquare1Scramble(numTurns)\n .map((turn) => ` (${turn.top}, ${turn.bottom}) /`)\n .join('');\n};\n"],"names":["root","factory","exports","module","define","amd","self","CubePlane","Side","Modifier","__webpack_require__","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","randomElement","array","Array","isArray","length","Math","floor","random","generateScramble","faces","planeMapping","modifiers","maxDepth","numTurns","previousTurn","newTurn","turns","i","push","face","depth","modifier","pochmanFaces","pochmanModifiers","scrambleToString","map","turn","depthLayer","sliceIndicator","turnToString","join","cube","size","L","R","U","D","F","B","X","Y","Z","Double","CounterClockwise","Clockwise","generateCubeScramble","megaminx","sequenceLength","numSequences","j","generateMegaminxScramble","pyraminx","sort","a","b","forEach","point","generatePyraminxScramble","skewb","generateSkewbScramble","square1","tops","bottom","turnTop","piece","shift","pop","unshift","turnBottom","Error","slice","topNum","bottomNum","topSlice","splice","bottomSlice","concat","isLayerAligned","layer","isMovePossible","abs","possibleMoves","possibleTop","possibleBottom","moves","topMove","bottomMove","top","generateSquare1Scramble"],"sourceRoot":""} \ No newline at end of file diff --git a/dist/scrambler/scrambler.d.ts b/dist/scrambler/scrambler.d.ts new file mode 100644 index 0000000..13afd42 --- /dev/null +++ b/dist/scrambler/scrambler.d.ts @@ -0,0 +1,33 @@ +/** + * planes of rotation + * for examples a cube rototes on x,y,z axis + * we don't want to generate two turns in a + * row on the same axis + */ +export declare type RotationPlane = string; +/** + * possible faces to rotate on the puzzle + * (ex, 3x3 has UFLRB) + */ +export declare type Face = string; +/** + * clockwise, counterclockwise... + */ +export declare type Modifer = string; +export declare type PlaneMapping = { + [face: string]: RotationPlane; +}; +export declare type Turn = { + face: Face; + depth: number; + modifier: Modifer; +}; +export declare const generateCubeScramble: (size?: number, numTurns?: number) => Turn[]; +/** + * generates a pochman scramble for the megaminx + */ +export declare const generateMegaminxScramble: (sequenceLength?: number, numSequences?: number) => Turn[][]; +export declare const generateSkewbScramble: (numTurns?: number) => Turn[]; +export declare const generatePyraminxScramble: (numTurns?: number) => Turn[]; +export declare const generateSquare1Scramble: (numTurns?: number) => any; +//# sourceMappingURL=scrambler.d.ts.map \ No newline at end of file diff --git a/dist/scrambler/scrambler.d.ts.map b/dist/scrambler/scrambler.d.ts.map new file mode 100644 index 0000000..b7faf4d --- /dev/null +++ b/dist/scrambler/scrambler.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"scrambler.d.ts","sourceRoot":"","sources":["../../src/scrambler/scrambler.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,oBAAY,aAAa,GAAG,MAAM,CAAC;AAEnC;;;GAGG;AACH,oBAAY,IAAI,GAAG,MAAM,CAAC;AAE1B;;GAEG;AACH,oBAAY,OAAO,GAAG,MAAM,CAAC;AAE7B,oBAAY,YAAY,GAAG;IAAE,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,CAAA;CAAE,CAAC;AAE7D,oBAAY,IAAI,GAAG;IACjB,IAAI,EAAE,IAAI,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,OAAO,CAAC;CACnB,CAAA;AA6BD,eAAO,MAAM,oBAAoB,UAAU,MAAM,aAAgB,MAAM,WAiBtE,CAAA;AAKD;;GAEG;AACH,eAAO,MAAM,wBAAwB,oBAAoB,MAAM,iBAAqB,MAAM,KAAO,IAAI,EAAE,EAoBtG,CAAA;AAED,eAAO,MAAM,qBAAqB,cAAc,MAAM,WAcrD,CAAA;AAED,eAAO,MAAM,wBAAwB,cAAc,MAAM,WA6BxD,CAAA;AAED,eAAO,MAAM,uBAAuB,cAAc,MAAM,QAsJvD,CAAA"} \ No newline at end of file diff --git a/dist/util.d.ts b/dist/util.d.ts new file mode 100644 index 0000000..309869a --- /dev/null +++ b/dist/util.d.ts @@ -0,0 +1,3 @@ +export declare function randomElement(array: T[]): T; +export declare function shuffle(array: T[]): T[]; +//# sourceMappingURL=util.d.ts.map \ No newline at end of file diff --git a/dist/util.d.ts.map b/dist/util.d.ts.map new file mode 100644 index 0000000..6c5df3b --- /dev/null +++ b/dist/util.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,wBAAgB,aAAa,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC,CAK9C;AAED,wBAAgB,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,CAI1C"} \ No newline at end of file diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 44c0b99..0000000 --- a/index.d.ts +++ /dev/null @@ -1,37 +0,0 @@ -declare namespace SRScrambler { - export function generateScramble(size: number, numTurns: number): Turn[]; - export function generateHtmlScramble(size: number, numTurns: number): string; - export function convertScrambleToHtml(turns: Turn[]): string; - - export class Turn { - cubeSize: number; - face: Side; - depth: number; - modifier: Modifier; - - toHtml(): string - } - - export enum CubePlane { - X = 'x', - Y = 'y', - Z = 'z' - } - - export enum Side { - L = 'L', - R = 'R', - U = 'U', - D = 'D', - F = 'F', - B = 'B' - } - - export enum Modifier { - Double = '2', - CounterClockwise = '\'', - Clockwise = '' - } -} - -export = SRScrambler \ No newline at end of file diff --git a/package.json b/package.json index 45fd5d4..fde0ece 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,9 @@ { "name": "sr-scrambler", - "version": "2.0.0", + "version": "2.0.1", "description": "utilitiy to generate scrambles for twisty puzzles (rubiks cube, megaminx, pyraminx, skewb, square1)", "main": "dist/index.js", + "types": "dist/index.d.ts", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "build": "webpack --mode production --config webpack.config.js", diff --git a/tsconfig.json b/tsconfig.json index 56b891c..4a790cb 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,9 +1,21 @@ { "compilerOptions": { "outDir": "./dist/", - "noImplicitAny": true, + "noImplicitAny": false, "module": "es6", - "target": "es5", + "target": "es6", "allowJs": true, - } -} + "moduleResolution": "node", + "isolatedModules": true, + "esModuleInterop": true, + "declaration": true, + "declarationMap": true + }, + "include": [ + "./src" + ], + "exclude": [ + "./tests", + "./node_modules" + ] +} \ No newline at end of file