/******/ (() => { // webpackBootstrap
/******/ 	"use strict";
/******/ 	var __webpack_modules__ = ({

/***/ 117:
/***/ ((__unused_webpack_module, exports) => {


Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.INTERVAL = void 0;
exports.INTERVAL = 50;


/***/ }),

/***/ 191:
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {


var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
var utils_1 = __webpack_require__(147);
var constants_1 = __webpack_require__(117);
var runSmartCathet = function (changeStateFields) {
    return function (_a) {
        var _this = this;
        var toX = _a.x, toY = _a.y;
        if (this._interval) {
            clearInterval(this._interval);
        }
        var path = findPath.call(this, { x: this.state.x, y: this.state.y, cost: 0 }, { x: toX, y: toY, cost: 0 });
        var currentIndex = path.length - 1;
        var prevPoint = path[currentIndex];
        this._interval = setInterval(function () {
            var point = path[currentIndex];
            if (!point) {
                _this.setState(__assign({}, changeStateFields({ dX: 0, dY: 0, isLast: true })));
                clearInterval(_this._interval);
                return;
            }
            var xSign = point.x - prevPoint.x;
            var ySign = point.y - prevPoint.y;
            if (point) {
                _this.setState(__assign({ x: point.x, y: point.y }, changeStateFields({ dX: xSign, dY: ySign })));
            }
            currentIndex--;
            prevPoint = point;
        }, constants_1.INTERVAL);
    };
};
function findPath(startNode, endNode) {
    var _a;
    console.log('findPath');
    var reachable = (_a = {}, _a[(0, utils_1.getMapKey)(startNode.x, startNode.y)] = startNode, _a);
    var explored = {};
    while (Object.keys(reachable).length) {
        var node = chooseNode(reachable);
        var nodeKey = (0, utils_1.getMapKey)(node.x, node.y);
        if (node.x === endNode.x && node.y === endNode.y) {
            return buildPath(node);
        }
        explored[nodeKey] = node;
        delete reachable[nodeKey];
        var newReachable = omitNodes(getAdjacentNodes.call(this, node), explored);
        for (var adjacentKey in newReachable) {
            if (!reachable[adjacentKey]) {
                newReachable[adjacentKey].previous = node;
                reachable[adjacentKey] = newReachable[adjacentKey];
            }
            if (node.cost + 1 < newReachable[adjacentKey].cost) {
                newReachable[adjacentKey].previous = node;
                newReachable[adjacentKey].cost = node.cost + 1;
            }
        }
    }
    console.log('Путь не найден');
    return [];
}
function getAdjacentNodes(node) {
    var _this = this;
    var isExistPoint = function (x, y) { return !!_this.map[(0, utils_1.getMapKey)(x, y)]; };
    var isOwnPoints = function (x, y) { return _this.map[(0, utils_1.getMapKey)(x, y)].id === _this.id; };
    var isInfinity = function (x, y) { return _this.map[(0, utils_1.getMapKey)(x, y)].cost === Infinity; };
    var nodes = {};
    for (var x = -1; x <= 1; x++) {
        for (var y = -1; y <= 1; y++) {
            if (x === 0 && y === 0)
                continue;
            var itemX = node.x + x;
            var itemY = node.y + y;
            var isAllow = true;
            for (var oX = 0; oX < this.state.sprite.hitboxWidth; oX++) {
                for (var oY = 0; oY < this.state.sprite.hitboxHeight; oY++) {
                    var xInObjectWidth = itemX + oX;
                    var yInObjectHeight = itemY + oY;
                    if (!isExistPoint(xInObjectWidth, yInObjectHeight)) {
                        isAllow = false;
                        continue;
                    }
                    if (isInfinity(xInObjectWidth, yInObjectHeight) && !isOwnPoints(xInObjectWidth, yInObjectHeight)) {
                        isAllow = false;
                    }
                }
            }
            if (isAllow) {
                nodes[(0, utils_1.getMapKey)(itemX, itemY)] = __assign(__assign({}, this.map[(0, utils_1.getMapKey)(itemX, itemY)]), { cost: 0 });
            }
        }
    }
    return nodes;
}
var omitNodes = function (map, omitted) {
    return Object.entries(map).reduce(function (prev, _a) {
        var _b;
        var key = _a[0], value = _a[1];
        if (!omitted[key]) {
            return __assign(__assign({}, prev), (_b = {}, _b[key] = value, _b));
        }
        return prev;
    }, {});
};
var buildPath = function (goalNode) {
    var path = [];
    while (goalNode) {
        path.push(goalNode);
        goalNode = goalNode.previous;
    }
    return path;
};
var chooseNode = function (reachable) {
    var bestNode = null;
    for (var key in reachable) {
        if (bestNode === null || bestNode.cost > reachable[key].cost) {
            bestNode = reachable[key];
        }
    }
    return bestNode;
};
exports["default"] = runSmartCathet;


/***/ }),

/***/ 147:
/***/ ((__unused_webpack_module, exports) => {


Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.getMapKey = void 0;
var getMapKey = function (x, y) { return "x".concat(x, "y").concat(y); };
exports.getMapKey = getMapKey;


/***/ })

/******/ 	});
/************************************************************************/
/******/ 	// The module cache
/******/ 	var __webpack_module_cache__ = {};
/******/ 	
/******/ 	// The require function
/******/ 	function __webpack_require__(moduleId) {
/******/ 		// Check if module is in cache
/******/ 		var cachedModule = __webpack_module_cache__[moduleId];
/******/ 		if (cachedModule !== undefined) {
/******/ 			return cachedModule.exports;
/******/ 		}
/******/ 		// Create a new module (and put it into the cache)
/******/ 		var module = __webpack_module_cache__[moduleId] = {
/******/ 			// no module.id needed
/******/ 			// no module.loaded needed
/******/ 			exports: {}
/******/ 		};
/******/ 	
/******/ 		// Execute the module function
/******/ 		__webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/ 	
/******/ 		// Return the exports of the module
/******/ 		return module.exports;
/******/ 	}
/******/ 	
/************************************************************************/
/******/ 	
/******/ 	// startup
/******/ 	// Load entry module and return exports
/******/ 	// This entry module is referenced by other modules so it can't be inlined
/******/ 	var __webpack_exports__ = __webpack_require__(191);
/******/ 	var __webpack_export_target__ = exports;
/******/ 	for(var i in __webpack_exports__) __webpack_export_target__[i] = __webpack_exports__[i];
/******/ 	if(__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, "__esModule", { value: true });
/******/ 	
/******/ })()
;