var t = require; var e = module; var i = exports; Object.defineProperty(i, "__esModule", {value: !0}), (i.default = class { constructor(t) { (this.COST_STRAIGHT = 10), (this.COST_DIAGONAL = 10), (this.maxStep = 1e3), (this._round1 = [ [0, -1], [1, -1], [1, 0], [0, 1], [-1, 0], [-1, -1] ]), (this._round2 = [ [0, -1], [1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0] ]), (this.handle = -1), (this.optimize = !0), (this._roadNodes = t); } seekPath(t, e) { if ( ((this._startNode = t), (this._currentNode = t), (this._targetNode = e), !this._startNode || !this._targetNode) ) return []; if (1 == this._targetNode.value) return console.log("目标不可达到:"), []; (this._openlist = []), (this._closelist = []); for (var i = 0; ; ) { if (i > this.maxStep) return []; if ((i++, this.searchRoundNodes(this._currentNode), 0 == this._openlist.length)) return []; if ( (this._openlist.sort(this.sortNode), (this._currentNode = this._openlist.shift()), this._currentNode == this._targetNode) ) return this.getPath(); this._closelist.push(this._currentNode); } return []; } seekPath2(t, e) { if ( ((this._startNode = t), (this._currentNode = t), (this._targetNode = e), !this._startNode || !this._targetNode) ) return []; (this._openlist = []), (this._closelist = []); for (var i = 0, s = null; ; ) { if (i > this.maxStep) return console.log("没找到目标计算步骤为:", i), this.seekPath(t, s); if ((i++, this.searchRoundNodes(this._currentNode), 0 == this._openlist.length)) return console.log("没找到目标计算步骤为:", i), this.seekPath(t, s); if ( (this._openlist.sort(this.sortNode), (this._currentNode = this._openlist.shift()), (null == s || this._currentNode.h < s.h) && (s = this._currentNode), this._currentNode == this._targetNode) ) return console.log("找到目标计算步骤为:", i), this.getPath(); this._closelist.push(this._currentNode); } return this.seekPath(t, s); } sortNode(t, e) { return t.f < e.f ? -1 : t.f > e.f ? 1 : 0; } getPath() { for (var t = [], e = this._targetNode; e != this._startNode; ) t.unshift(e), (e = e.parent); if ((t.unshift(this._startNode), !this.optimize)) return t; for (var i = 1; i < t.length - 1; i++) { var s = t[i - 1], o = t[i], a = t[i + 1], n = !1, r = null; (n = (r = 2 == Math.abs(a.cx - s.cx) && s.cy == a.cy ? o.cx % 2 == 0 ? o.cy == s.cy ? this._roadNodes[o.cx + "_" + (o.cy + 1)] : this._roadNodes[o.cx + "_" + (o.cy - 1)] : o.cy == s.cy ? this._roadNodes[o.cx + "_" + (o.cy - 1)] : this._roadNodes[o.cx + "_" + (o.cy + 1)] : r) ? 1 != r.value : n) && (t.splice(i, 1), i--); } for (i = 1; i < t.length - 1; i++) { (s = t[i - 1]), (o = t[i]), (a = t[i + 1]); var l = o.cx == s.cx && o.cx == a.cx, h = o.cy == s.cy && o.cy == a.cy && s.cx % 2 == o.cx % 2 && o.cx % 2 == a.cx % 2, c = s.cy - Math.floor(s.cx / 2) == o.cy - Math.floor(o.cx / 2) && o.cy - Math.floor(o.cx / 2) == a.cy - Math.floor(a.cx / 2), d = s.cy + Math.ceil(s.cx / 2) == o.cy + Math.ceil(o.cx / 2) && o.cy + Math.ceil(o.cx / 2) == a.cy + Math.ceil(a.cx / 2); (l || h || c || d) && (t.splice(i, 1), i--); } return t; } testSeekPathStep(t, e, i, s, o = 100) { var a; (this._startNode = t), (this._currentNode = t), (this._targetNode = e), 1 != this._targetNode.value && ((this._openlist = []), (this._closelist = []), (a = 0), clearInterval(this.handle), (this.handle = setInterval( () => a > this.maxStep ? (console.log("没找到目标计算步骤为:", a), void clearInterval(this.handle)) : (a++, this.searchRoundNodes(this._currentNode), 0 == this._openlist.length ? (console.log("没找到目标计算步骤为:", a), void clearInterval(this.handle)) : (this._openlist.sort(this.sortNode), (this._currentNode = this._openlist.shift()), void (this._currentNode == this._targetNode ? (console.log("找到目标计算步骤为:", a), clearInterval(this.handle), i.apply(s, [ this._startNode, this._targetNode, this._currentNode, this._openlist, this._closelist, this.getPath() ])) : (this._closelist.push(this._currentNode), i.apply(s, [ this._startNode, this._targetNode, this._currentNode, this._openlist, this._closelist, null ]))))), o ))); } searchRoundNodes(t) { for (var e = t.cx % 2 == 0 ? this._round1 : this._round2, i = 0; i < e.length; i++) { var s = t.cx + e[i][0], o = t.cy + e[i][1], o = this._roadNodes[s + "_" + o]; null == o || o == this._startNode || 1 == o.value || this.isInCloseList(o) || this.setNodeF(o); } } setNodeF(t) { var e = t.cx == this._currentNode.cx || t.cy == this._currentNode.cy ? this._currentNode.g + this.COST_STRAIGHT : this._currentNode.g + this.COST_DIAGONAL; if (this.isInOpenList(t)) { if (!(e < t.g)) return; t.g = e; } else (t.g = e), this._openlist.push(t); (t.parent = this._currentNode), (t.h = (Math.abs(this._targetNode.cx - t.cx) + Math.abs(this._targetNode.cy - t.cy)) * this.COST_STRAIGHT), (t.f = t.g + t.h); } isInOpenList(t) { return -1 != this._openlist.indexOf(t); } isInCloseList(t) { return -1 != this._closelist.indexOf(t); } inInCorner(t) { if (t.cx == this._currentNode.cx || t.cy == this._currentNode.cy) return !1; var e = this._roadNodes[this._currentNode.cx + "_" + t.cy], t = this._roadNodes[t.cx + "_" + this._currentNode.cy]; return null == e || 0 != e.value || null == t || 0 != t.value; } dispose() { (this._roadNodes = null), (this._round1 = null), (this._round2 = null); } });