From 2691bf77eb2d5848a8bee2dd5e2432877935a509 Mon Sep 17 00:00:00 2001 From: Alexandre Date: Tue, 7 Jul 2020 16:08:23 -0300 Subject: [PATCH] Update dist and lib --- dist/classes/Result.js | 14 +++++++++ dist/classes/Result.js.map | 1 + dist/classes/Solution.js | 11 +++++++ dist/classes/Solution.js.map | 1 + dist/functions/AStar.js | 39 +++++++++++++++++++++++ dist/functions/AStar.js.map | 1 + dist/functions/node.js | 13 +------- dist/functions/node.js.map | 2 +- dist/functions/solution.js | 17 ++++++++++ dist/functions/solution.js.map | 1 + dist/functions/state.js | 27 +++++++++------- dist/functions/state.js.map | 2 +- dist/index.js | 48 ++++++++++------------------- dist/index.js.map | 2 +- lib/a-star-puzzle-solver.umd.js | 2 +- lib/a-star-puzzle-solver.umd.min.js | 2 +- 16 files changed, 124 insertions(+), 59 deletions(-) create mode 100644 dist/classes/Result.js create mode 100644 dist/classes/Result.js.map create mode 100644 dist/classes/Solution.js create mode 100644 dist/classes/Solution.js.map create mode 100644 dist/functions/AStar.js create mode 100644 dist/functions/AStar.js.map create mode 100644 dist/functions/solution.js create mode 100644 dist/functions/solution.js.map diff --git a/dist/classes/Result.js b/dist/classes/Result.js new file mode 100644 index 0000000..26ddc3f --- /dev/null +++ b/dist/classes/Result.js @@ -0,0 +1,14 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var Result = /** @class */ (function () { + function Result(pathCost, iterations, expandedNodes, finalNode, solution) { + this.pathCost = pathCost; + this.iterations = iterations; + this.expandedNodes = expandedNodes; + this.finalNode = finalNode; + this.solution = solution; + } + return Result; +}()); +exports.default = Result; +//# sourceMappingURL=Result.js.map \ No newline at end of file diff --git a/dist/classes/Result.js.map b/dist/classes/Result.js.map new file mode 100644 index 0000000..2722fb1 --- /dev/null +++ b/dist/classes/Result.js.map @@ -0,0 +1 @@ +{"version":3,"file":"Result.js","sourceRoot":"","sources":["../../src/classes/Result.ts"],"names":[],"mappings":";;AAGA;IAOI,gBAAY,QAAgB,EAAE,UAAkB,EAAE,aAAqB,EAAE,SAAmB,EAAE,QAAyB;QACnH,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC7B,CAAC;IACL,aAAC;AAAD,CAAC,AAdD,IAcC"} \ No newline at end of file diff --git a/dist/classes/Solution.js b/dist/classes/Solution.js new file mode 100644 index 0000000..d07f6c4 --- /dev/null +++ b/dist/classes/Solution.js @@ -0,0 +1,11 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var SolutionItem = /** @class */ (function () { + function SolutionItem(s, op) { + this.state = s; + this.operation = op; + } + return SolutionItem; +}()); +exports.default = SolutionItem; +//# sourceMappingURL=Solution.js.map \ No newline at end of file diff --git a/dist/classes/Solution.js.map b/dist/classes/Solution.js.map new file mode 100644 index 0000000..0e5bc42 --- /dev/null +++ b/dist/classes/Solution.js.map @@ -0,0 +1 @@ +{"version":3,"file":"Solution.js","sourceRoot":"","sources":["../../src/classes/Solution.ts"],"names":[],"mappings":";;AAGA;IAII,sBAAY,CAAc,EAAE,EAAc;QACtC,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC;QACf,IAAI,CAAC,SAAS,GAAG,EAAE,CAAC;IACxB,CAAC;IACL,mBAAC;AAAD,CAAC,AARD,IAQC"} \ No newline at end of file diff --git a/dist/functions/AStar.js b/dist/functions/AStar.js new file mode 100644 index 0000000..cd011db --- /dev/null +++ b/dist/functions/AStar.js @@ -0,0 +1,39 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.run = void 0; +var state_1 = require("./state"); +var node_1 = require("./node"); +var Result_1 = __importDefault(require("../classes/Result")); +function runAStarLoop(goalState, frontier, expandedStates) { + var actualNode = frontier.shift(); + var iterations = 0; + if (actualNode) { + while (!state_1.areEqual(actualNode.state, goalState)) { + var children = node_1.generateNodeList(actualNode, goalState); + for (var _i = 0, children_1 = children; _i < children_1.length; _i++) { + var c = children_1[_i]; + if (!state_1.includes(c.state, expandedStates)) { //Only add to frontier states not openned yet + if (state_1.isSolvable(c.state)) { //Only add to frontier solvable states + frontier.push(c); + } + expandedStates.push(actualNode.state); + } + } + frontier.sort(function (a, b) { return (a.evaluationFunctionValue.f < b.evaluationFunctionValue.f) ? -1 : ((a.evaluationFunctionValue.f === b.evaluationFunctionValue.f) ? ((a.evaluationFunctionValue.h < b.evaluationFunctionValue.h) ? -1 : 1) : 1); }); // Order frontier according to heuristic value of nodes + var aux = frontier.shift(); + iterations += 1; + if (aux) { + actualNode = aux; + } + else { + throw new Error('Empty frontier'); + } + } + return new Result_1.default(actualNode.evaluationFunctionValue.g, iterations, expandedStates.length, actualNode); + } +} +exports.run = runAStarLoop; +//# sourceMappingURL=AStar.js.map \ No newline at end of file diff --git a/dist/functions/AStar.js.map b/dist/functions/AStar.js.map new file mode 100644 index 0000000..81caf48 --- /dev/null +++ b/dist/functions/AStar.js.map @@ -0,0 +1 @@ +{"version":3,"file":"AStar.js","sourceRoot":"","sources":["../../src/functions/AStar.ts"],"names":[],"mappings":";;;;;;AAEA,iCAAyD;AACzD,+BAA0C;AAC1C,6DAAuC;AAGvC,SAAS,YAAY,CAAC,SAAgB,EAAE,QAAoB,EAAE,cAAuB;IACjF,IAAI,UAAU,GAAG,QAAQ,CAAC,KAAK,EAAE,CAAC;IAClC,IAAI,UAAU,GAAG,CAAC,CAAC;IACnB,IAAG,UAAU,EAAC;QACV,OAAM,CAAC,gBAAQ,CAAC,UAAU,CAAC,KAAK,EAAE,SAAS,CAAC,EAAC;YACzC,IAAM,QAAQ,GAAG,uBAAgB,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;YAC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UAAU,CAAC,CAAC;KAC1G;AACL,CAAC;AAEwB,2BAAG"} \ No newline at end of file diff --git a/dist/functions/node.js b/dist/functions/node.js index c743440..3484512 100644 --- a/dist/functions/node.js +++ b/dist/functions/node.js @@ -3,13 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.readNode = exports.generateNode = exports.generateNodeList = void 0; +exports.generateNode = exports.generateNodeList = void 0; var operations_1 = require("./../utils/operations"); var Node_1 = require("../classes/Node"); var heuristic_1 = require("./heuristic"); var operations_2 = require("./operations"); var HeuristicValue_1 = __importDefault(require("../classes/HeuristicValue")); -var state_1 = require("./state"); function generateNodeList(node, goalState) { var childrenNodes = []; var childUp = generateAndTest(operations_1.operations.up, node, goalState, node.evaluationFunctionValue.g); @@ -51,14 +50,4 @@ function generateNode(state, op, goalState, gValue, previousNode) { return new Node_1.NodeInfo(heuristicValue, op, state, previousNode); } exports.generateNode = generateNode; -function readNode(node) { - state_1.readState(node.state); - if (node.previousNode) { - return readNode(node.previousNode); - } - else { - return node; - } -} -exports.readNode = readNode; //# sourceMappingURL=node.js.map \ No newline at end of file diff --git a/dist/functions/node.js.map b/dist/functions/node.js.map index 896f849..b8d5a8d 100644 --- a/dist/functions/node.js.map +++ b/dist/functions/node.js.map @@ -1 +1 @@ -{"version":3,"file":"node.js","sourceRoot":"","sources":["../../src/functions/node.ts"],"names":[],"mappings":";;;;;;AAAA,oDAAmD;AACnD,wCAA0C;AAE1C,yCAAyC;AACzC,2CAA8C;AAC9C,6EAAuD;AACvD,iCAAoC;AAEpC,SAAS,gBAAgB,CAAC,IAAc,EAAE,SAAgB;IACtD,IAAI,aAAa,GAAe,EAAE,CAAC;IACnC,IAAM,OAAO,GAAG,eAAe,CAAC,uBAAU,CAAC,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,CAAC,uBAAuB,CAAC,CAAC,CAAC,CAAC;IACh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AAG,cAAc,CAAC,CAAC,GAAG,YAAY,CAAC,uBAAuB,CAAC,CAAC,EAAC;YACzD,IAAG,YAAY,CAAC,uBAAuB,CAAC,CAAC,GAAG,cAAc,CAAC,CAAC,EAAE;gBAC1D,cAAc,CAAC,CAAC,GAAG,YAAY,CAAC,uBAAuB,CAAC,CAAC,CAAC,CAAC,4BAA4B;aAC1F;SACJ;KACJ;IACD,OAAO,IAAI,eAAQ,CAAC,cAAc,EAAE,EAAE,EAAE,KAAK,EAAE,YAAY,CAAC,CAAC;AACjE,CAAC;AAE0B,oCAAY"} \ No newline at end of file diff --git a/dist/functions/solution.js b/dist/functions/solution.js new file mode 100644 index 0000000..6221f22 --- /dev/null +++ b/dist/functions/solution.js @@ -0,0 +1,17 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.getSolutionFromNode = void 0; +var state_1 = require("./state"); +var Solution_1 = __importDefault(require("../classes/Solution")); +function getSolutionFromNode(node, list) { + if (node.previousNode) { + list.unshift(new Solution_1.default(state_1.convertStateInArray(node.state), node.operation)); + return getSolutionFromNode(node.previousNode, list); + } + return list; +} +exports.getSolutionFromNode = getSolutionFromNode; +//# sourceMappingURL=solution.js.map \ No newline at end of file diff --git a/dist/functions/solution.js.map b/dist/functions/solution.js.map new file mode 100644 index 0000000..2151eeb --- /dev/null +++ b/dist/functions/solution.js.map @@ -0,0 +1 @@ +{"version":3,"file":"solution.js","sourceRoot":"","sources":["../../src/functions/solution.ts"],"names":[],"mappings":";;;;;;AACA,iCAA8C;AAC9C,iEAA+C;AAG/C,SAAS,mBAAmB,CAAC,IAAc,EAAE,IAAoB;IAC7D,IAAG,IAAI,CAAC,YAAY,EAAC;QACjB,IAAI,CAAC,OAAO,CAAC,IAAI,kBAAY,CAAC,2BAAmB,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;QAChF,OAAO,mBAAmB,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;KACvD;IACD,OAAO,IAAI,CAAC;AAChB,CAAC;AAEQ,kDAAmB"} \ No newline at end of file diff --git a/dist/functions/state.js b/dist/functions/state.js index bf0b9fd..e528e19 100644 --- a/dist/functions/state.js +++ b/dist/functions/state.js @@ -1,6 +1,6 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -exports.isSolvable = exports.readState = exports.includes = exports.areEqual = void 0; +exports.convertStateInArray = exports.convertArrayInState = exports.isSolvable = exports.includes = exports.areEqual = void 0; // Using this function because literal comparison between 2 types (state1 == state2) always return false // TODO: melhorar formato de verificação function areEqual(state1, state2) { @@ -32,6 +32,7 @@ function isSolvable(state) { exports.isSolvable = isSolvable; function quantityOfInversions(state) { var stateList = convertStateInArray(state); + stateList = stateList.filter(function (val) { return val !== 0; }); // Do not consider 0 when counting inversions var inversions = 0; for (var i in stateList) { for (var j = Number(i) + 1; j < stateList.length; j++) { @@ -47,20 +48,24 @@ function convertStateInArray(state) { var stateList = []; for (var l in state) { for (var c in state[l]) { - if (state[l][c] !== 0) { // Do not consider 0 when counting inversions - stateList.push(state[l][c]); - } + stateList.push(state[l][c]); } } return stateList; } -function readState(state) { - console.log('---------'); - for (var _i = 0, state_1 = state; _i < state_1.length; _i++) { - var l = state_1[_i]; - console.log(l); +exports.convertStateInArray = convertStateInArray; +//TODO: Melhorar a forma de fazer isso +function convertArrayInState(stateList) { + var state = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]; + for (var l in state) { + for (var c in state[l]) { + var item = stateList.shift(); + if (item) { + state[l][c] = item; + } + } } - console.log('---------'); + return state; } -exports.readState = readState; +exports.convertArrayInState = convertArrayInState; //# sourceMappingURL=state.js.map \ No newline at end of file diff --git a/dist/functions/state.js.map b/dist/functions/state.js.map index 07e3b27..094e54f 100644 --- a/dist/functions/state.js.map +++ b/dist/functions/state.js.map @@ -1 +1 @@ -{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AAG,SAAS,CAAC,CAAC,CAAC,EAAC;gBAC3B,UAAU,EAAE,CAAC;aAChB;SACJ;KACJ;IACD,OAAO,UAAU,CAAC;AACtB,CAAC;AAED,sCAAsC;AACtC,SAAS,mBAAmB,CAAC,KAAY;IACrC,IAAI,SAAS,GAAgB,EAAE,CAAC;IAChC,KAAI,IAAI,CAAC,IAAI,KAAK,EAAC;QACf,KAAK,IAAI,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,EAAC;YACnB,IAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,EAAC,EAAC,6CAA6C;gBAC/D,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;aAC/B;SACJ;KACJ;IACD,OAAO,SAAS,CAAC;AACrB,CAAC;AAED,SAAS,SAAS,CAAC,KAAY;IAC3B,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IACzB,KAAa,UAAK,EAAL,eAAK,EAAL,mBAAK,EAAL,IAAK,EAAC;QAAf,IAAI,CAAC,cAAA;QACL,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;KAClB;IACD,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;AAC7B,CAAC;AAE4B,8BAAS"} \ No newline at end of file +{"version":3,"file":"state.js","sourceRoot":"","sources":["../../src/functions/state.ts"],"names":[],"mappings":";;;AAGA,wGAAwG;AACxG,wCAAwC;AACxC,SAAS,QAAQ,CAAC,MAAa,EAAE,MAAa;IAC1C,IAAM,KAAK,GAAG,IAAI,CAAC;IACnB,KAAK,IAAI,CAAC,IAAI,MAAM,EAAC;QACjB,KAAK,IAAI,CAAC,IAAI,MAAM,EAAC;YACjB,IAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAC;gBAC/B,OAAO,KAA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K,CAAC,CAAC,CAAC,EAAC;YACnB,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;SAC/B;KACJ;IACD,OAAO,SAAS,CAAC;AACrB,CAAC;AAgB6D,kDAAmB;AAdjF,sCAAsC;AACtC,SAAS,mBAAmB,CAAC,SAAsB;IAC/C,IAAI,KAAK,GAAU,CAAC,CAAC,CAAC,EAAC,CAAC,EAAC,CAAC,CAAC,EAAC,CAAC,CAAC,EAAC,CAAC,EAAC,CAAC,CAAC,EAAC,CAAC,CAAC,EAAC,CAAC,EAAC,CAAC,CAAC,CAAC,CAAC;IAC7C,KAAI,IAAI,CAAC,IAAI,KAAK,EAAC;QACf,KAAK,IAAI,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,EAAC;YACnB,IAAM,IAAI,GAAG,SAAS,CAAC,KAAK,EAAE,CAAC;YAC/B,IAAG,IAAI,EAAC;gBACJ,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;aACtB;SACJ;KACJ;IACD,OAAO,KAAK,CAAC;AACjB,CAAC;AAEwC,kDAAmB"} \ No newline at end of file diff --git a/dist/index.js b/dist/index.js index 1eb2c88..c76cd8f 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,47 +1,33 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -exports.solvePuzzle = void 0; +exports.isSolvable = exports.convertStateInArray = exports.convertArrayInState = exports.solvePuzzle = void 0; var operations_1 = require("./utils/operations"); var node_1 = require("./functions/node"); var state_1 = require("./functions/state"); -function AStar(initialState, finalState) { +Object.defineProperty(exports, "isSolvable", { enumerable: true, get: function () { return state_1.isSolvable; } }); +Object.defineProperty(exports, "convertArrayInState", { enumerable: true, get: function () { return state_1.convertArrayInState; } }); +Object.defineProperty(exports, "convertStateInArray", { enumerable: true, get: function () { return state_1.convertStateInArray; } }); +var AStar_1 = require("./functions/AStar"); +var solution_1 = require("./functions/solution"); +function index(state, finalState) { + var initialState = state_1.convertArrayInState(state); var goalState = finalState ? finalState : [[1, 2, 3], [4, 5, 6], [7, 8, 0]]; if (state_1.isSolvable(initialState)) { var firstNode = node_1.generateNode(initialState, operations_1.operations.none, goalState, 0); var frontier = [firstNode]; var expandedStates = []; - var finalNode = runAStarLoop(goalState, frontier, expandedStates); - return finalNode; + var result = AStar_1.run(goalState, frontier, expandedStates); + if (result) { + result.solution = solution_1.getSolutionFromNode(result.finalNode, []); + return result; + } + else { + throw new Error('Unexpected error while processing search'); + } } else { throw new Error('Initial state is not solvable'); } } -exports.solvePuzzle = AStar; -function runAStarLoop(goalState, frontier, expandedStates) { - var actualNode = frontier.shift(); - if (actualNode) { - while (!state_1.areEqual(actualNode.state, goalState)) { - var children = node_1.generateNodeList(actualNode, goalState); - for (var _i = 0, children_1 = children; _i < children_1.length; _i++) { - var c = children_1[_i]; - if (!state_1.includes(c.state, expandedStates)) { //Only add to frontier states not openned yet - if (state_1.isSolvable(c.state)) { //Only add to frontier solvable states - frontier.push(c); - } - expandedStates.push(actualNode.state); - } - } - frontier.sort(function (a, b) { return (a.evaluationFunctionValue.f < b.evaluationFunctionValue.f) ? -1 : ((a.evaluationFunctionValue.f === b.evaluationFunctionValue.f) ? ((a.evaluationFunctionValue.h < b.evaluationFunctionValue.h) ? -1 : 1) : 1); }); // Order frontier according to heuristic value of nodes - var aux = frontier.shift(); - if (aux) { - actualNode = aux; - } - else { - throw new Error('Empty frontier'); - } - } - return actualNode; - } -} +exports.solvePuzzle = index; //# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/index.js.map b/dist/index.js.map index 068bc93..1e782c4 100644 --- a/dist/index.js.map +++ b/dist/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,iDAAgD;AAGhD,yCAA4E;AAC5E,2CAAmE;AAGnE,SAAS,KAAK,CAAC,YAAmB,EAAE,UAAkB;IAClD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C,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAC,CAAC,EAAC,CAAC,CAAC,EAAC,CAAC,CAAC,EAAC,CAAC,EAAC,CAAC,CAAC,EAAC,CAAC,CAAC,EAAE,CAAC,EAAC,CAAC,CAAC,CAAC,CAAC;IAC9E,IAAG,kBAAU,CAAC,YAAY,CAAC,EAAC;QACxB,IAAM,SAAS,GAAG,mBAAY,CAAC,YAAY,EAAE,uBAAU,CAAC,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC;QAC5E,IAAI,QAAQ,GAAa,CAAC,SAAS,CAAC,CAAC;QACrC,IAAI,cAAc,GAAY,EAAE,CAAC;QAEjC,IAAM,MAAM,GAAG,WAAG,CAAC,SAAS,EAAE,QAAQ,EAAE,cAAc,CAAC,CAAC;QACxD,IAAG,MAAM,EAAC;YACN,MAAM,CAAC,QAAQ,GAAG,8BAAmB,CAAC,MAAM,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;YAC5D,OAAO,MAAM,CAAC;SACjB;aAAI;YACD,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;SAC/D;KACJ;SAAI;QACD,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;KACpD;AACL,CAAC;AAIiB,4BAAW"} \ No newline at end of file diff --git a/lib/a-star-puzzle-solver.umd.js b/lib/a-star-puzzle-solver.umd.js index 4083775..265bab1 100644 --- a/lib/a-star-puzzle-solver.umd.js +++ b/lib/a-star-puzzle-solver.umd.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.AStarPuzzleSolver=t():e.AStarPuzzleSolver=t()}(window,(function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=3)}([function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.operations=void 0,function(e){e.up="UP_OPERATION",e.right="RIGHT_OPERATION",e.down="DOWN_OPERATION",e.left="LEFT_OPERATION",e.none="NONE"}(t.operations||(t.operations={}))},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function(e,t){this.line=e,this.col=t};t.default=r},function(e,t,n){"use strict";function r(e,t){for(var n in e)for(var r in e)if(e[n][r]!=t[n][r])return!1;return!0}Object.defineProperty(t,"__esModule",{value:!0}),t.isSolvable=t.readState=t.includes=t.areEqual=void 0,t.areEqual=r,t.includes=function(e,t){for(var n=0,o=t;nt[o]&&n++;return n}(e)%2==0},t.readState=function(e){console.log("---------");for(var t=0,n=e;to.evaluationFunctionValue.h&&o.evaluationFunctionValue.f>f.f&&(f.f=o.evaluationFunctionValue.f),new u.NodeInfo(f,t,e,o)}t.generateNodeList=function(e,t){var n=[],r=c(o.operations.up,e,t,e.evaluationFunctionValue.g);r&&n.push(r);var u=c(o.operations.right,e,t,e.evaluationFunctionValue.g);u&&n.push(u);var i=c(o.operations.down,e,t,e.evaluationFunctionValue.g);i&&n.push(i);var a=c(o.operations.left,e,t,e.evaluationFunctionValue.g);return a&&n.push(a),n},t.generateNode=s,t.readNode=function e(t){return f.readState(t.state),t.previousNode?e(t.previousNode):t}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.NodeInfo=void 0;var r=function(e,t,n,r){this.evaluationFunctionValue=e,this.operation=t,this.state=n,this.previousNode=r};t.NodeInfo=r},function(e,t,n){"use strict";var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.calcDistanceOfItem=t.calcHValue=void 0;var o=r(n(1));function u(e,t,n){for(var r in n){var o=n[r].indexOf(e);if(o>-1)return Math.abs(t.line-Number(r))+Math.abs(t.col-o)}return 10}t.calcHValue=function(e,t){var n=0;for(var r in e)for(var i in e[r]){var a=new o.default(Number(r),Number(i));n+=u(e[r][i],a,t)}return n},t.calcDistanceOfItem=u},function(e,t,n){"use strict";var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.getPositionOfBlankItem=t.moveLeftOperation=t.moveDownOperation=t.moveRightOperation=t.moveUpOperation=t.applyOperation=void 0;var o=n(0),u=r(n(1));function i(e){var t=c(e),n=t.line-1;return n>=0?s(t,new u.default(n,t.col),e):null}function a(e){var t=c(e),n=t.col+1;return n<=2?s(t,new u.default(t.line,n),e):null}function l(e){var t=c(e),n=t.line+1;return n<=2?s(t,new u.default(n,t.col),e):null}function f(e){var t=c(e),n=t.col-1;return n>=0?s(t,new u.default(t.line,n),e):null}function c(e){for(var t in e){var n=e[t].indexOf(0);if(n>-1)return new u.default(Number(t),Number(n))}throw new Error("Error: null item not found on state")}function s(e,t,n){var r=function(e){var t=[[0,0,0],[0,0,0],[0,0,0]];for(var n in e)for(var r in e)t[n][r]=e[n][r];return t}(n),o=n[t.line][t.col];return r[t.line][t.col]=0,r[e.line][e.col]=o,r}t.applyOperation=function(e,t){switch(t){case o.operations.up:return i(e);case o.operations.right:return a(e);case o.operations.down:return l(e);case o.operations.left:return f(e)}},t.moveUpOperation=i,t.moveRightOperation=a,t.moveDownOperation=l,t.moveLeftOperation=f,t.getPositionOfBlankItem=c},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function(e,t,n){this.g=e,this.h=t,this.f=n};t.default=r}])})); \ No newline at end of file +!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.AStarPuzzleSolver=t():e.AStarPuzzleSolver=t()}(window,(function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=4)}([function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.operations=void 0,function(e){e.up="UP_OPERATION",e.right="RIGHT_OPERATION",e.down="DOWN_OPERATION",e.left="LEFT_OPERATION",e.none="NONE"}(t.operations||(t.operations={}))},function(e,t,n){"use strict";function r(e,t){for(var n in e)for(var r in e)if(e[n][r]!=t[n][r])return!1;return!0}function o(e){var t=[];for(var n in e)for(var r in e[n])t.push(e[n][r]);return t}Object.defineProperty(t,"__esModule",{value:!0}),t.convertStateInArray=t.convertArrayInState=t.isSolvable=t.includes=t.areEqual=void 0,t.areEqual=r,t.includes=function(e,t){for(var n=0,o=t;nt[u]&&n++;return n}(e)%2==0},t.convertStateInArray=o,t.convertArrayInState=function(e){var t=[[0,0,0],[0,0,0],[0,0,0]];for(var n in t)for(var r in t[n]){var o=e.shift();o&&(t[n][r]=o)}return t}},function(e,t,n){"use strict";var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.generateNode=t.generateNodeList=void 0;var o=n(0),u=n(5),i=n(6),a=n(7),l=r(n(8));function f(e,t,n,r){var o=a.applyOperation(t.state,e);return o?c(o,e,n,r+1,t):null}function c(e,t,n,r,o){var a=i.calcHValue(e,n),f=new l.default(r,a,r+a);return o&&f.h>o.evaluationFunctionValue.h&&o.evaluationFunctionValue.f>f.f&&(f.f=o.evaluationFunctionValue.f),new u.NodeInfo(f,t,e,o)}t.generateNodeList=function(e,t){var n=[],r=f(o.operations.up,e,t,e.evaluationFunctionValue.g);r&&n.push(r);var u=f(o.operations.right,e,t,e.evaluationFunctionValue.g);u&&n.push(u);var i=f(o.operations.down,e,t,e.evaluationFunctionValue.g);i&&n.push(i);var a=f(o.operations.left,e,t,e.evaluationFunctionValue.g);return a&&n.push(a),n},t.generateNode=c},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function(e,t){this.line=e,this.col=t};t.default=r},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.isSolvable=t.convertStateInArray=t.convertArrayInState=t.solvePuzzle=void 0;var r=n(0),o=n(2),u=n(1);Object.defineProperty(t,"isSolvable",{enumerable:!0,get:function(){return u.isSolvable}}),Object.defineProperty(t,"convertArrayInState",{enumerable:!0,get:function(){return u.convertArrayInState}}),Object.defineProperty(t,"convertStateInArray",{enumerable:!0,get:function(){return u.convertStateInArray}});var i=n(9),a=n(11);t.solvePuzzle=function(e,t){var n=u.convertArrayInState(e),l=t||[[1,2,3],[4,5,6],[7,8,0]];if(u.isSolvable(n)){var f=[o.generateNode(n,r.operations.none,l,0)],c=i.run(l,f,[]);if(c)return c.solution=a.getSolutionFromNode(c.finalNode,[]),c;throw new Error("Unexpected error while processing search")}throw new Error("Initial state is not solvable")}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.NodeInfo=void 0;var r=function(e,t,n,r){this.evaluationFunctionValue=e,this.operation=t,this.state=n,this.previousNode=r};t.NodeInfo=r},function(e,t,n){"use strict";var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.calcDistanceOfItem=t.calcHValue=void 0;var o=r(n(3));function u(e,t,n){for(var r in n){var o=n[r].indexOf(e);if(o>-1)return Math.abs(t.line-Number(r))+Math.abs(t.col-o)}return 10}t.calcHValue=function(e,t){var n=0;for(var r in e)for(var i in e[r]){var a=new o.default(Number(r),Number(i));n+=u(e[r][i],a,t)}return n},t.calcDistanceOfItem=u},function(e,t,n){"use strict";var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.getPositionOfBlankItem=t.moveLeftOperation=t.moveDownOperation=t.moveRightOperation=t.moveUpOperation=t.applyOperation=void 0;var o=n(0),u=r(n(3));function i(e){var t=c(e),n=t.line-1;return n>=0?s(t,new u.default(n,t.col),e):null}function a(e){var t=c(e),n=t.col+1;return n<=2?s(t,new u.default(t.line,n),e):null}function l(e){var t=c(e),n=t.line+1;return n<=2?s(t,new u.default(n,t.col),e):null}function f(e){var t=c(e),n=t.col-1;return n>=0?s(t,new u.default(t.line,n),e):null}function c(e){for(var t in e){var n=e[t].indexOf(0);if(n>-1)return new u.default(Number(t),Number(n))}throw new Error("Error: null item not found on state")}function s(e,t,n){var r=function(e){var t=[[0,0,0],[0,0,0],[0,0,0]];for(var n in e)for(var r in e)t[n][r]=e[n][r];return t}(n),o=n[t.line][t.col];return r[t.line][t.col]=0,r[e.line][e.col]=o,r}t.applyOperation=function(e,t){switch(t){case o.operations.up:return i(e);case o.operations.right:return a(e);case o.operations.down:return l(e);case o.operations.left:return f(e)}},t.moveUpOperation=i,t.moveRightOperation=a,t.moveDownOperation=l,t.moveLeftOperation=f,t.getPositionOfBlankItem=c},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function(e,t,n){this.g=e,this.h=t,this.f=n};t.default=r},function(e,t,n){"use strict";var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.run=void 0;var o=n(1),u=n(2),i=r(n(10));t.run=function(e,t,n){var r=t.shift(),a=0;if(r){for(;!o.areEqual(r.state,e);){for(var l=0,f=u.generateNodeList(r,e);lt[o]&&n++;return n}(e)%2==0},t.readState=function(e){console.log("---------");for(var t=0,n=e;to.evaluationFunctionValue.h&&o.evaluationFunctionValue.f>f.f&&(f.f=o.evaluationFunctionValue.f),new u.NodeInfo(f,t,e,o)}t.generateNodeList=function(e,t){var n=[],r=c(o.operations.up,e,t,e.evaluationFunctionValue.g);r&&n.push(r);var u=c(o.operations.right,e,t,e.evaluationFunctionValue.g);u&&n.push(u);var i=c(o.operations.down,e,t,e.evaluationFunctionValue.g);i&&n.push(i);var a=c(o.operations.left,e,t,e.evaluationFunctionValue.g);return a&&n.push(a),n},t.generateNode=s,t.readNode=function e(t){return f.readState(t.state),t.previousNode?e(t.previousNode):t}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.NodeInfo=void 0;var r=function(e,t,n,r){this.evaluationFunctionValue=e,this.operation=t,this.state=n,this.previousNode=r};t.NodeInfo=r},function(e,t,n){"use strict";var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.calcDistanceOfItem=t.calcHValue=void 0;var o=r(n(1));function u(e,t,n){for(var r in n){var o=n[r].indexOf(e);if(o>-1)return Math.abs(t.line-Number(r))+Math.abs(t.col-o)}return 10}t.calcHValue=function(e,t){var n=0;for(var r in e)for(var i in e[r]){var a=new o.default(Number(r),Number(i));n+=u(e[r][i],a,t)}return n},t.calcDistanceOfItem=u},function(e,t,n){"use strict";var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.getPositionOfBlankItem=t.moveLeftOperation=t.moveDownOperation=t.moveRightOperation=t.moveUpOperation=t.applyOperation=void 0;var o=n(0),u=r(n(1));function i(e){var t=c(e),n=t.line-1;return n>=0?s(t,new u.default(n,t.col),e):null}function a(e){var t=c(e),n=t.col+1;return n<=2?s(t,new u.default(t.line,n),e):null}function l(e){var t=c(e),n=t.line+1;return n<=2?s(t,new u.default(n,t.col),e):null}function f(e){var t=c(e),n=t.col-1;return n>=0?s(t,new u.default(t.line,n),e):null}function c(e){for(var t in e){var n=e[t].indexOf(0);if(n>-1)return new u.default(Number(t),Number(n))}throw new Error("Error: null item not found on state")}function s(e,t,n){var r=function(e){var t=[[0,0,0],[0,0,0],[0,0,0]];for(var n in e)for(var r in e)t[n][r]=e[n][r];return t}(n),o=n[t.line][t.col];return r[t.line][t.col]=0,r[e.line][e.col]=o,r}t.applyOperation=function(e,t){switch(t){case o.operations.up:return i(e);case o.operations.right:return a(e);case o.operations.down:return l(e);case o.operations.left:return f(e)}},t.moveUpOperation=i,t.moveRightOperation=a,t.moveDownOperation=l,t.moveLeftOperation=f,t.getPositionOfBlankItem=c},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function(e,t,n){this.g=e,this.h=t,this.f=n};t.default=r}])})); \ No newline at end of file +!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.AStarPuzzleSolver=t():e.AStarPuzzleSolver=t()}(window,(function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=4)}([function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.operations=void 0,function(e){e.up="UP_OPERATION",e.right="RIGHT_OPERATION",e.down="DOWN_OPERATION",e.left="LEFT_OPERATION",e.none="NONE"}(t.operations||(t.operations={}))},function(e,t,n){"use strict";function r(e,t){for(var n in e)for(var r in e)if(e[n][r]!=t[n][r])return!1;return!0}function o(e){var t=[];for(var n in e)for(var r in e[n])t.push(e[n][r]);return t}Object.defineProperty(t,"__esModule",{value:!0}),t.convertStateInArray=t.convertArrayInState=t.isSolvable=t.includes=t.areEqual=void 0,t.areEqual=r,t.includes=function(e,t){for(var n=0,o=t;nt[u]&&n++;return n}(e)%2==0},t.convertStateInArray=o,t.convertArrayInState=function(e){var t=[[0,0,0],[0,0,0],[0,0,0]];for(var n in t)for(var r in t[n]){var o=e.shift();o&&(t[n][r]=o)}return t}},function(e,t,n){"use strict";var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.generateNode=t.generateNodeList=void 0;var o=n(0),u=n(5),i=n(6),a=n(7),l=r(n(8));function f(e,t,n,r){var o=a.applyOperation(t.state,e);return o?c(o,e,n,r+1,t):null}function c(e,t,n,r,o){var a=i.calcHValue(e,n),f=new l.default(r,a,r+a);return o&&f.h>o.evaluationFunctionValue.h&&o.evaluationFunctionValue.f>f.f&&(f.f=o.evaluationFunctionValue.f),new u.NodeInfo(f,t,e,o)}t.generateNodeList=function(e,t){var n=[],r=f(o.operations.up,e,t,e.evaluationFunctionValue.g);r&&n.push(r);var u=f(o.operations.right,e,t,e.evaluationFunctionValue.g);u&&n.push(u);var i=f(o.operations.down,e,t,e.evaluationFunctionValue.g);i&&n.push(i);var a=f(o.operations.left,e,t,e.evaluationFunctionValue.g);return a&&n.push(a),n},t.generateNode=c},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function(e,t){this.line=e,this.col=t};t.default=r},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.isSolvable=t.convertStateInArray=t.convertArrayInState=t.solvePuzzle=void 0;var r=n(0),o=n(2),u=n(1);Object.defineProperty(t,"isSolvable",{enumerable:!0,get:function(){return u.isSolvable}}),Object.defineProperty(t,"convertArrayInState",{enumerable:!0,get:function(){return u.convertArrayInState}}),Object.defineProperty(t,"convertStateInArray",{enumerable:!0,get:function(){return u.convertStateInArray}});var i=n(9),a=n(11);t.solvePuzzle=function(e,t){var n=u.convertArrayInState(e),l=t||[[1,2,3],[4,5,6],[7,8,0]];if(u.isSolvable(n)){var f=[o.generateNode(n,r.operations.none,l,0)],c=i.run(l,f,[]);if(c)return c.solution=a.getSolutionFromNode(c.finalNode,[]),c;throw new Error("Unexpected error while processing search")}throw new Error("Initial state is not solvable")}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.NodeInfo=void 0;var r=function(e,t,n,r){this.evaluationFunctionValue=e,this.operation=t,this.state=n,this.previousNode=r};t.NodeInfo=r},function(e,t,n){"use strict";var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.calcDistanceOfItem=t.calcHValue=void 0;var o=r(n(3));function u(e,t,n){for(var r in n){var o=n[r].indexOf(e);if(o>-1)return Math.abs(t.line-Number(r))+Math.abs(t.col-o)}return 10}t.calcHValue=function(e,t){var n=0;for(var r in e)for(var i in e[r]){var a=new o.default(Number(r),Number(i));n+=u(e[r][i],a,t)}return n},t.calcDistanceOfItem=u},function(e,t,n){"use strict";var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.getPositionOfBlankItem=t.moveLeftOperation=t.moveDownOperation=t.moveRightOperation=t.moveUpOperation=t.applyOperation=void 0;var o=n(0),u=r(n(3));function i(e){var t=c(e),n=t.line-1;return n>=0?s(t,new u.default(n,t.col),e):null}function a(e){var t=c(e),n=t.col+1;return n<=2?s(t,new u.default(t.line,n),e):null}function l(e){var t=c(e),n=t.line+1;return n<=2?s(t,new u.default(n,t.col),e):null}function f(e){var t=c(e),n=t.col-1;return n>=0?s(t,new u.default(t.line,n),e):null}function c(e){for(var t in e){var n=e[t].indexOf(0);if(n>-1)return new u.default(Number(t),Number(n))}throw new Error("Error: null item not found on state")}function s(e,t,n){var r=function(e){var t=[[0,0,0],[0,0,0],[0,0,0]];for(var n in e)for(var r in e)t[n][r]=e[n][r];return t}(n),o=n[t.line][t.col];return r[t.line][t.col]=0,r[e.line][e.col]=o,r}t.applyOperation=function(e,t){switch(t){case o.operations.up:return i(e);case o.operations.right:return a(e);case o.operations.down:return l(e);case o.operations.left:return f(e)}},t.moveUpOperation=i,t.moveRightOperation=a,t.moveDownOperation=l,t.moveLeftOperation=f,t.getPositionOfBlankItem=c},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function(e,t,n){this.g=e,this.h=t,this.f=n};t.default=r},function(e,t,n){"use strict";var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.run=void 0;var o=n(1),u=n(2),i=r(n(10));t.run=function(e,t,n){var r=t.shift(),a=0;if(r){for(;!o.areEqual(r.state,e);){for(var l=0,f=u.generateNodeList(r,e);l