layaair-js
Version:
An open source HTML5 engine. Edition JavaScript.
1 lines • 23.8 kB
JavaScript
!function(t,e,i){var n=(i.un,i.uns,i["static"],i["class"]),s=(i.getset,i.__newvec,function(){function t(){}return n(t,"PathFinding.core.DiagonalMovement"),t.Always=1,t.Never=2,t.IfAtMostOneObstacle=3,t.OnlyWhenNoObstacles=4,t}()),a=function(){function t(t,e,i){this.width=0,this.height=0,this.nodes=null;var n=0;"number"==typeof t?n=t:(e=t.length,n=t[0].length,i=t),this.width=n,this.height=e,this.nodes=this._buildNodes(n,e,i)}n(t,"PathFinding.core.Grid");var e=t.prototype;return e._buildNodes=function(t,e,i){var n=0,s=0,a=[];for(n=0;e>n;++n)for(a[n]=[],s=0;t>s;++s)a[n][s]=new o(s,n);if(null==i)return a;if(i.length!=e||i[0].length!=t)throw new Error("Matrix size does not fit");for(n=0;e>n;++n)for(s=0;t>s;++s)i[n][s]&&(a[n][s].walkable=!1);return a},e.getNodeAt=function(t,e){return this.nodes[e][t]},e.isWalkableAt=function(t,e){return this.isInside(t,e)&&this.nodes[e][t].walkable},e.isInside=function(t,e){return t>=0&&t<this.width&&e>=0&&e<this.height},e.setWalkableAt=function(t,e,i){this.nodes[e][t].walkable=i},e.getNeighbors=function(t,e){var i=t.x,n=t.y,a=[],r=!1,o=!1,h=!1,l=!1,u=!1,d=!1,f=!1,c=!1,p=this.nodes;if(this.isWalkableAt(i,n-1)&&(a.push(p[n-1][i]),r=!0),this.isWalkableAt(i+1,n)&&(a.push(p[n][i+1]),h=!0),this.isWalkableAt(i,n+1)&&(a.push(p[n+1][i]),u=!0),this.isWalkableAt(i-1,n)&&(a.push(p[n][i-1]),f=!0),e==s.Never)return a;if(e==s.OnlyWhenNoObstacles)o=f&&r,l=r&&h,d=h&&u,c=u&&f;else if(e==s.IfAtMostOneObstacle)o=f||r,l=r||h,d=h||u,c=u||f;else{if(e!=s.Always)throw new Error("Incorrect value of diagonalMovement");o=!0,l=!0,d=!0,c=!0}return o&&this.isWalkableAt(i-1,n-1)&&a.push(p[n-1][i-1]),l&&this.isWalkableAt(i+1,n-1)&&a.push(p[n-1][i+1]),d&&this.isWalkableAt(i+1,n+1)&&a.push(p[n+1][i+1]),c&&this.isWalkableAt(i-1,n+1)&&a.push(p[n+1][i-1]),a},e.clone=function(){var e=0,i=0,n=this.width,s=this.height,a=this.nodes,r=new t(n,s),h=[];for(e=0;s>e;++e)for(h[e]=[],i=0;n>i;++i)h[e][i]=new o(i,e,a[e][i].walkable);return r.nodes=h,r},e.reset=function(){for(var t,e=0;e<this.height;++e)for(var i=0;i<this.width;++i)t=this.nodes[e][i],t.g=0,t.f=0,t.h=0,t.by=0,t.parent=null,t.opened=null,t.closed=null,t.tested=null},t}(),r=function(){function t(){}return n(t,"PathFinding.core.Heuristic"),t.manhattan=function(t,e){return t+e},t.euclidean=function(t,e){return Math.sqrt(t*t+e*e)},t.octile=function(t,e){var i=Math.SQRT2-1;return e>t?i*t+e:i*e+t},t.chebyshev=function(t,e){return Math.max(t,e)},t}(),o=function(){function t(t,e,i){this.x=0,this.y=0,this.g=0,this.f=0,this.h=0,this.by=0,this.parent=null,this.opened=null,this.closed=null,this.tested=null,this.walkable=!1,void 0===i&&(i=!0),this.x=t,this.y=e,this.walkable=i}return n(t,"PathFinding.core.Node",null,"Node1"),t}(),h=function(){function t(){}return n(t,"PathFinding.core.Util"),t.backtrace=function(t){for(var e=[[t.x,t.y]];t.parent;)t=t.parent,e.push([t.x,t.y]);return e.reverse()},t.biBacktrace=function(e,i){var n=t.backtrace(e),s=t.backtrace(i);return n.concat(s.reverse())},t.pathLength=function(t){var e=0,i=0,n=0,s=0,a=0,r=0;for(e=1;e<t.length;++e)n=t[e-1],s=t[e],a=n[0]-s[0],r=n[1]-s[1],i+=Math.sqrt(a*a+r*r);return i},t.interpolate=function(t,e,i,n){var s=Math.abs,a=[],r=0,o=0,h=0,l=0,u=0,d=0;for(h=s(i-t),l=s(n-e),r=i>t?1:-1,o=n>e?1:-1,u=h-l;;){if(a.push([t,e]),t==i&&e==n)break;d=2*u,d>-l&&(u-=l,t+=r),h>d&&(u+=h,e+=o)}return a},t.expandPath=function(e){var i,n,s,a=[],r=e.length,o=0,h=0,l=0;if(2>r)return a;for(h=0;r-1>h;++h)for(i=e[h],n=e[h+1],s=t.interpolate(i[0],i[1],n[0],n[1]),o=s.length,l=0;o-1>l;++l)a.push(s[l]);return a.push(e[r-1]),a},t.smoothenPath=function(e,i){var n,s,a,r,o,h=i.length,l=i[0][0],u=i[0][1],d=i[h-1][0],f=i[h-1][1],c=0,p=0,g=0,b=0,m=0,v=0,A=!1;for(c=l,p=u,n=[[c,p]],m=2;h>m;++m){for(s=i[m],g=s[0],b=s[1],a=t.interpolate(c,p,g,b),A=!1,v=1;v<a.length;++v)if(r=a[v],!e.isWalkableAt(r[0],r[1])){A=!0;break}A&&(o=i[m-1],n.push(o),c=o[0],p=o[1])}return n.push([d,f]),n},t.compressPath=function(t){if(t.length<3)return t;var e=[],i=t[0][0],n=t[0][1],s=t[1][0],a=t[1][1],r=s-i,o=a-n,h=0,l=0,u=0,d=0,f=NaN,c=0;for(f=Math.sqrt(r*r+o*o),r/=f,o/=f,e.push([i,n]),c=2;c<t.length;c++)h=s,l=a,u=r,d=o,s=t[c][0],a=t[c][1],r=s-h,o=a-l,f=Math.sqrt(r*r+o*o),r/=f,o/=f,r===u&&o===d||e.push([h,l]);return e.push([s,a]),e},t}(),l=function(){function t(t){this.allowDiagonal=!1,this.dontCrossCorners=!1,this.heuristic=null,this.weight=0,this.diagonalMovement=0,t=t||{},this.allowDiagonal=t.allowDiagonal,this.dontCrossCorners=t.dontCrossCorners,this.heuristic=t.heuristic||r.manhattan,this.weight=t.weight||1,this.diagonalMovement=t.diagonalMovement,this.diagonalMovement||(this.allowDiagonal?this.dontCrossCorners?this.diagonalMovement=s.OnlyWhenNoObstacles:this.diagonalMovement=s.IfAtMostOneObstacle:this.diagonalMovement=s.Never),this.diagonalMovement===s.Never?this.heuristic=t.heuristic||r.manhattan:this.heuristic=t.heuristic||r.octile}n(t,"PathFinding.finders.AStarFinder");var e=t.prototype;return e.findPath=function(t,e,i,n,s){var a,r,o,l=new f(function(t,e){return t.f-e.f}),u=s.getNodeAt(t,e),d=s.getNodeAt(i,n),c=this.heuristic,p=this.diagonalMovement,g=this.weight,b=Math.abs,m=Math.SQRT2,v=0,A=0,k=0,W=0,M=0;for(u.g=0,u.f=0,l.push(u),u.opened=!0;!l.empty();){if(a=l.pop(),a.closed=!0,a===d)return h.backtrace(d);for(r=s.getNeighbors(a,p),v=0,A=r.length;A>v;++v)o=r[v],o.closed||(k=o.x,W=o.y,M=a.g+(k-a.x===0||W-a.y===0?1:m),(!o.opened||M<o.g)&&(o.g=M,o.h=o.h||g*c(b(k-i),b(W-n)),o.f=o.g+o.h,o.parent=a,o.opened?l.updateItem(o):(l.push(o),o.opened=!0)))}return[]},t}(),u=function(){function t(t){this.allowDiagonal=!1,this.dontCrossCorners=!1,this.diagonalMovement=0,this.heuristic=null,this.weight=0,t=t||{},this.allowDiagonal=t.allowDiagonal,this.dontCrossCorners=t.dontCrossCorners,this.diagonalMovement=t.diagonalMovement,this.heuristic=t.heuristic||r.manhattan,this.weight=t.weight||1,this.diagonalMovement||(this.allowDiagonal?this.dontCrossCorners?this.diagonalMovement=s.OnlyWhenNoObstacles:this.diagonalMovement=s.IfAtMostOneObstacle:this.diagonalMovement=s.Never),this.diagonalMovement==s.Never?this.heuristic=t.heuristic||r.manhattan:this.heuristic=t.heuristic||r.octile}n(t,"PathFinding.finders.BiAStarFinder");var e=t.prototype;return e.findPath=function(t,e,i,n,s){var a,r,o,l=function(t,e){return t.f-e.f},u=new f(l),d=new f(l),c=s.getNodeAt(t,e),p=s.getNodeAt(i,n),g=this.heuristic,b=this.diagonalMovement,m=this.weight,v=Math.abs,A=Math.SQRT2,k=0,W=0,M=0,y=0,w=0,N=1,C=2;for(c.g=0,c.f=0,u.push(c),c.opened=N,p.g=0,p.f=0,d.push(p),p.opened=C;!u.empty()&&!d.empty();){for(a=u.pop(),a.closed=!0,r=s.getNeighbors(a,b),k=0,W=r.length;W>k;++k)if(o=r[k],!o.closed){if(o.opened===C)return h.biBacktrace(a,o);M=o.x,y=o.y,w=a.g+(M-a.x===0||y-a.y===0?1:A),(!o.opened||w<o.g)&&(o.g=w,o.h=o.h||m*g(v(M-i),v(y-n)),o.f=o.g+o.h,o.parent=a,o.opened?u.updateItem(o):(u.push(o),o.opened=N))}for(a=d.pop(),a.closed=!0,r=s.getNeighbors(a,b),k=0,W=r.length;W>k;++k)if(o=r[k],!o.closed){if(o.opened===N)return h.biBacktrace(o,a);M=o.x,y=o.y,w=a.g+(M-a.x===0||y-a.y===0?1:A),(!o.opened||w<o.g)&&(o.g=w,o.h=o.h||m*g(v(M-t),v(y-e)),o.f=o.g+o.h,o.parent=a,o.opened?d.updateItem(o):(d.push(o),o.opened=C))}}return[]},t}(),d=(function(){function t(t){this.allowDiagonal=!1,this.dontCrossCorners=!1,this.heuristic=null,this.weight=0,this.diagonalMovement=0,t=t||{},this.allowDiagonal=t.allowDiagonal,this.dontCrossCorners=t.dontCrossCorners,this.diagonalMovement=t.diagonalMovement,this.diagonalMovement||(this.allowDiagonal?this.dontCrossCorners?this.diagonalMovement=s.OnlyWhenNoObstacles:this.diagonalMovement=s.IfAtMostOneObstacle:this.diagonalMovement=s.Never)}n(t,"PathFinding.finders.BiBreadthFirstFinder");var e=t.prototype;return e.findPath=function(t,e,i,n,s){var a,r,o,l=s.getNodeAt(t,e),u=s.getNodeAt(i,n),d=[],f=[],c=this.diagonalMovement,p=0,g=1,b=0,m=0;for(d.push(l),l.opened=!0,l.by=p,f.push(u),u.opened=!0,u.by=g;d.length&&f.length;){for(o=d.shift(),o.closed=!0,a=s.getNeighbors(o,c),b=0,m=a.length;m>b;++b)if(r=a[b],!r.closed)if(r.opened){if(r.by===g)return h.biBacktrace(o,r)}else d.push(r),r.parent=o,r.opened=!0,r.by=p;for(o=f.shift(),o.closed=!0,a=s.getNeighbors(o,c),b=0,m=a.length;m>b;++b)if(r=a[b],!r.closed)if(r.opened){if(r.by===p)return h.biBacktrace(r,o)}else f.push(r),r.parent=o,r.opened=!0,r.by=g}return[]},t}(),function(){function t(t){this.allowDiagonal=!1,this.dontCrossCorners=!1,this.heuristic=null,this.weight=0,this.diagonalMovement=0,t=t||{},this.allowDiagonal=t.allowDiagonal,this.dontCrossCorners=t.dontCrossCorners,this.diagonalMovement=t.diagonalMovement,this.diagonalMovement||(this.allowDiagonal?this.dontCrossCorners?this.diagonalMovement=s.OnlyWhenNoObstacles:this.diagonalMovement=s.IfAtMostOneObstacle:this.diagonalMovement=s.Never)}n(t,"PathFinding.finders.BreadthFirstFinder");var e=t.prototype;return e.findPath=function(t,e,i,n,s){var a,r,o,l=[],u=this.diagonalMovement,d=s.getNodeAt(t,e),f=s.getNodeAt(i,n),c=0,p=0;for(l.push(d),d.opened=!0;l.length;){if(o=l.shift(),o.closed=!0,o===f)return h.backtrace(f);for(a=s.getNeighbors(o,u),c=0,p=a.length;p>c;++c)r=a[c],r.closed||r.opened||(l.push(r),r.opened=!0,r.parent=o)}return[]},t}(),function(){function t(t){this.allowDiagonal=!1,this.dontCrossCorners=!1,this.heuristic=null,this.weight=0,this.diagonalMovement=0,this.trackRecursion=!1,this.timeLimit=NaN,t=t||{},this.allowDiagonal=t.allowDiagonal,this.dontCrossCorners=t.dontCrossCorners,this.diagonalMovement=t.diagonalMovement,this.heuristic=t.heuristic||r.manhattan,this.weight=t.weight||1,this.trackRecursion=t.trackRecursion||!1,this.timeLimit=t.timeLimit||1/0,this.diagonalMovement||(this.allowDiagonal?this.dontCrossCorners?this.diagonalMovement=s.OnlyWhenNoObstacles:this.diagonalMovement=s.IfAtMostOneObstacle:this.diagonalMovement=s.Never),this.diagonalMovement===s.Never?this.heuristic=t.heuristic||r.manhattan:this.heuristic=t.heuristic||r.octile}n(t,"PathFinding.finders.IDAStarFinder");var e=t.prototype;return e.findPath=function(t,e,i,n,s){var a,r=this,o=0,h=(new Date).getTime(),l=function(t,e){return r.heuristic(Math.abs(e.x-t.x),Math.abs(e.y-t.y))}.bind(this),u=function(t,e){return t.x===e.x||t.y===e.y?1:Math.SQRT2},d=function(t,e,i,n,a){if(o++,r.timeLimit>0&&(new Date).getTime()-h>1e3*r.timeLimit)return 1/0;var f=e+l(t,c)*r.weight;if(f>i)return f;if(t==c)return n[a]=[t.x,t.y],t;var p,g=0,b=0,m=0,v=s.getNeighbors(t,r.diagonalMovement);for(m=0,g=1/0;p=v[m];++m){if(r.trackRecursion&&(p.retainCount=p.retainCount+1||1,1!=p.tested&&(p.tested=!0)),b=d(p,e+u(t,p),i,n,a+1),b instanceof PathFinding.core.Node)return n[a]=[t.x,t.y],b;r.trackRecursion&&0===--p.retainCount&&(p.tested=!1),g>b&&(g=b)}return g}.bind(this),f=s.getNodeAt(t,e),c=s.getNodeAt(i,n),p=l(f,c),g=0,b=0;for(g=0;!0;++g){if(a=[],b=d(f,0,p,a,0),b==1/0)return[];if(b instanceof PathFinding.core.Node)return a;p=b}return[]},t}(),function(){function t(t){this.grid=null,this.openList=null,this.startNode=null,this.endNode=null,this.heuristic=null,this.trackJumpRecursion=!1,t=t||{},this.heuristic=t.heuristic||r.manhattan,this.trackJumpRecursion=t.trackJumpRecursion||!1}n(t,"PathFinding.finders.JumpPointFinderBase");var e=t.prototype;return e.findPath=function(t,e,i,n,s){var a,r=this.openList=new f(function(t,e){return t.f-e.f}),o=this.startNode=s.getNodeAt(t,e),l=this.endNode=s.getNodeAt(i,n);for(this.grid=s,o.g=0,o.f=0,r.push(o),o.opened=!0;!r.empty();){if(a=r.pop(),a.closed=!0,a==l)return h.expandPath(h.backtrace(l));this._identifySuccessors(a)}return[]},e._identifySuccessors=function(t){var e,i,n,s,a=this.grid,o=this.heuristic,h=this.openList,l=this.endNode.x,u=this.endNode.y,d=0,f=0,c=t.x,p=t.y,g=0,b=0,m=0,v=0,A=Math.abs;Math.max;for(e=this._findNeighbors(t),d=0,f=e.length;f>d;++d)if(i=e[d],n=this._jump(i[0],i[1],c,p)){if(g=n[0],b=n[1],s=a.getNodeAt(g,b),s.closed)continue;m=r.octile(A(g-c),A(b-p)),v=t.g+m,(!s.opened||v<s.g)&&(s.g=v,s.h=s.h||o(A(g-l),A(b-u)),s.f=s.g+s.h,s.parent=t,s.opened?h.updateItem(s):(h.push(s),s.opened=!0))}},e._jump=function(t,e,i,n){},e._findNeighbors=function(t){},t}()),f=(function(){function t(t){return t=t||{},t.diagonalMovement===s.Never?new m(t):t.diagonalMovement===s.Always?new p(t):t.diagonalMovement===s.OnlyWhenNoObstacles?new b(t):new g(t)}return n(t,"PathFinding.finders.JumpPointFinder"),t}(),function(){function t(t){this.allowDiagonal=!1,this.dontCrossCorners=!1,this.diagonalMovement=0,this.heuristic=null,t=t||{},this.allowDiagonal=t.allowDiagonal,this.dontCrossCorners=t.dontCrossCorners,this.heuristic=t.heuristic||r.manhattan,this.diagonalMovement=t.diagonalMovement,this.diagonalMovement||(this.allowDiagonal?this.dontCrossCorners?this.diagonalMovement=s.OnlyWhenNoObstacles:this.diagonalMovement=s.IfAtMostOneObstacle:this.diagonalMovement=s.Never),this.diagonalMovement==s.Never?this.heuristic=t.heuristic||r.manhattan:this.heuristic=t.heuristic||r.octile}n(t,"PathFinding.finders.TraceFinder");var e=t.prototype;return e.findPath=function(t,e,i,n,s){var a,r,o,l=new f(function(t,e){return t.f-e.f}),u=s.getNodeAt(t,e),d=s.getNodeAt(i,n),c=this.heuristic,p=(this.allowDiagonal,this.dontCrossCorners,Math.abs),g=Math.SQRT2,b=0,m=0,v=0,A=0,k=0;for(u.g=0,u.f=0,l.push(u),u.opened=!0;!l.empty();){if(a=l.pop(),a.closed=!0,a===d)return h.backtrace(d);for(r=s.getNeighbors(a,this.diagonalMovement),b=0,m=r.length;m>b;++b)o=r[b],o.closed||(v=o.x,A=o.y,k=a.g+(v-a.x===0||A-a.y===0?1:g),(!o.opened||k<o.g)&&(o.g=k*m/9,o.h=o.h||c(p(v-i),p(A-n)),o.f=o.g+o.h,o.parent=a,o.opened?l.updateItem(o):(l.push(o),o.opened=!0)))}return[]},t}(),function(){function t(t){this.cmp=null,this.nodes=null,this.heapFunction=new c,this.cmp=null!=t?t:this.heapFunction.defaultCmp,this.nodes=[]}n(t,"PathFinding.libs.Heap");var e=t.prototype;return e.push=function(t){return this.heapFunction.heappush(this.nodes,t,this.cmp)},e.pop=function(){return this.heapFunction.heappop(this.nodes,this.cmp)},e.peek=function(){return this.nodes[0]},e.contains=function(t){return-1!==this.nodes.indexOf(t)},e.replace=function(t){return this.heapFunction.heapreplace(this.nodes,t,this.cmp)},e.pushpop=function(t){return this.heapFunction.heappushpop(this.nodes,t,this.cmp)},e.heapify=function(){return this.heapFunction.heapify(this.nodes,this.cmp)},e.updateItem=function(t){return this.heapFunction.updateItem(this.nodes,t,this.cmp)},e.clear=function(){return this.nodes=[]},e.empty=function(){return 0===this.nodes.length},e.size=function(){return this.nodes.length},e.clone=function(){var e=new t;return e.nodes=this.nodes.slice(0),e},e.toArray=function(){return this.nodes.slice(0)},t}()),c=function(){function t(){this.defaultCmp=function(t,e){return e>t?-1:t>e?1:0}}n(t,"PathFinding.libs.HeapFunction");var e=t.prototype;return e.insort=function(t,e,i,n,s){var a=NaN;if(null==i&&(i=0),null==s&&(s=this.defaultCmp),0>i)throw new Error("lo must be non-negative");for(null==n&&(n=t.length);n>i;)a=Math.floor((i+n)/2),s(e,t[a])<0?n=a:i=a+1;return[].splice.apply(t,[i,i-i].concat(e)),e},e.heappush=function(t,e,i){return null==i&&(i=this.defaultCmp),t.push(e),this._siftdown(t,0,t.length-1,i)},e.heappop=function(t,e){var i,n;return null==e&&(e=this.defaultCmp),i=t.pop(),t.length?(n=t[0],t[0]=i,this._siftup(t,0,e)):n=i,n},e.heapreplace=function(t,e,i){var n;return null==i&&(i=this.defaultCmp),n=t[0],t[0]=e,this._siftup(t,0,i),n},e.heappushpop=function(t,e,i){var n;return null==i&&(i=this.defaultCmp),t.length&&i(t[0],e)<0&&(n=[t[0],e],e=n[0],t[0]=n[1],this._siftup(t,0,i)),e},e.heapify=function(t,e){var i,n,s,a,r=0,o=0,h=0,l=0;for(null==e&&(e=this.defaultCmp),n=function(){for(a=[],h=0,i=Math.floor(t.length/2);i>=0?i>h:h>i;i>=0?h++:h--)a.push(h);return a}.apply(this).reverse(),s=[],o=0,l=n.length;l>o;o++)r=n[o],s.push(this._siftup(t,r,e));return s},e.updateItem=function(t,e,i){var n=0;return null==i&&(i=this.defaultCmp),n=t.indexOf(e),-1===n?null:(this._siftdown(t,0,n,i),this._siftup(t,n,i))},e.nlargest=function(t,e,i){var n,s,a,r=0,o=0;if(null==i&&(i=this.defaultCmp),s=t.slice(0,e),!s.length)return s;for(this.heapify(s,i),a=t.slice(e),r=0,o=a.length;o>r;r++)n=a[r],this.heappushpop(s,n,i);return s.sort(i).reverse()},e.nsmallest=function(t,e,i){var n,s,a,r,o,h,l,u,d=0,f=0;if(null==i&&(i=this.defaultCmp),10*e<=t.length){if(r=t.slice(0,e).sort(i),!r.length)return r;for(a=r[r.length-1],h=t.slice(e),d=0,o=h.length;o>d;d++)n=h[d],i(n,a)<0&&(this.insort(r,n,0,null,i),r.pop(),a=r[r.length-1]);return r}for(this.heapify(t,i),u=[],s=f=0,l=Math.min(e,t.length);l>=0?l>f:f>l;s=l>=0?++f:--f)u.push(this.heappop(t,i));return u},e._siftdown=function(t,e,i,n){var s,a,r=0;for(null==n&&(n=this.defaultCmp),s=t[i];i>e&&(r=i-1>>1,a=t[r],n(s,a)<0);)t[i]=a,i=r;return t[i]=s},e._siftup=function(t,e,i){var n,s=0,a=0,r=0,o=0;for(null==i&&(i=this.defaultCmp),a=t.length,o=e,n=t[e],s=2*e+1;a>s;)r=s+1,a>r&&!(i(t[s],t[r])<0)&&(s=r),t[e]=t[s],e=s,s=2*e+1;return t[e]=n,this._siftdown(t,o,e,i)},t}(),p=(function(){function t(){var t={allowDiagonal:!0,dontCrossCorners:!1,heuristic:r.manhattan,weight:1},e=new l(t),i=new a(64,36),n=e.findPath(23,16,33,16,i);console.log(n.toString())}return n(t,"TestPathFinding"),t}(),function(t){function e(t){e.__super.call(this,t);var i=this.heuristic;this.heuristic=function(t,e){return 1e6*i(t,e)}}return n(e,"PathFinding.finders.BestFirstFinder",t),e}(l),function(t){function e(t){e.__super.call(this,t);var i=this.heuristic;this.heuristic=function(t,e){return 1e6*i(t,e)}}return n(e,"PathFinding.finders.BiBestFirstFinder",t),e}(u),function(t){function e(t){e.__super.call(this,t),this.heuristic=function(t,e){return 0}}return n(e,"PathFinding.finders.BiDijkstraFinder",t),e}(u),function(t){function e(t){e.__super.call(this,t),this.heuristic=function(t,e){return 0}}return n(e,"PathFinding.finders.DijkstraFinder",t),e}(l),function(t){function e(t){e.__super.call(this,t)}n(e,"PathFinding.finders.JPFAlwaysMoveDiagonally",t);var i=e.prototype;return i._jump=function(t,e,i,n){var s=this.grid,a=t-i,r=e-n;if(!s.isWalkableAt(t,e))return null;if(1==this.trackJumpRecursion&&(s.getNodeAt(t,e).tested=!0),s.getNodeAt(t,e)==this.endNode)return[t,e];if(0!==a&&0!==r){if(s.isWalkableAt(t-a,e+r)&&!s.isWalkableAt(t-a,e)||s.isWalkableAt(t+a,e-r)&&!s.isWalkableAt(t,e-r))return[t,e];if(this._jump(t+a,e,t,e)||this._jump(t,e+r,t,e))return[t,e]}else if(0!==a){if(s.isWalkableAt(t+a,e+1)&&!s.isWalkableAt(t,e+1)||s.isWalkableAt(t+a,e-1)&&!s.isWalkableAt(t,e-1))return[t,e]}else if(s.isWalkableAt(t+1,e+r)&&!s.isWalkableAt(t+1,e)||s.isWalkableAt(t-1,e+r)&&!s.isWalkableAt(t-1,e))return[t,e];return this._jump(t+a,e+r,t,e)},i._findNeighbors=function(t){var e,i,n=t.parent,a=t.x,r=t.y,o=this.grid,h=0,l=0,u=0,d=0,f=[],c=0,p=0;if(n)h=n.x,l=n.y,u=(a-h)/Math.max(Math.abs(a-h),1),d=(r-l)/Math.max(Math.abs(r-l),1),0!==u&&0!==d?(o.isWalkableAt(a,r+d)&&f.push([a,r+d]),o.isWalkableAt(a+u,r)&&f.push([a+u,r]),o.isWalkableAt(a+u,r+d)&&f.push([a+u,r+d]),o.isWalkableAt(a-u,r)||f.push([a-u,r+d]),o.isWalkableAt(a,r-d)||f.push([a+u,r-d])):0===u?(o.isWalkableAt(a,r+d)&&f.push([a,r+d]),o.isWalkableAt(a+1,r)||f.push([a+1,r+d]),o.isWalkableAt(a-1,r)||f.push([a-1,r+d])):(o.isWalkableAt(a+u,r)&&f.push([a+u,r]),o.isWalkableAt(a,r+1)||f.push([a+u,r+1]),o.isWalkableAt(a,r-1)||f.push([a+u,r-1]));else for(e=o.getNeighbors(t,s.Always),c=0,p=e.length;p>c;++c)i=e[c],f.push([i.x,i.y]);return f},e}(d)),g=function(t){function e(t){e.__super.call(this,t)}n(e,"PathFinding.finders.JPFMoveDiagonallyIfAtMostOneObstacle",t);var i=e.prototype;return i._jump=function(t,e,i,n){var s=this.grid,a=t-i,r=e-n;if(!s.isWalkableAt(t,e))return null;if(this.trackJumpRecursion===!0&&(s.getNodeAt(t,e).tested=!0),s.getNodeAt(t,e)==this.endNode)return[t,e];if(0!==a&&0!==r){if(s.isWalkableAt(t-a,e+r)&&!s.isWalkableAt(t-a,e)||s.isWalkableAt(t+a,e-r)&&!s.isWalkableAt(t,e-r))return[t,e];if(this._jump(t+a,e,t,e)||this._jump(t,e+r,t,e))return[t,e]}else if(0!==a){if(s.isWalkableAt(t+a,e+1)&&!s.isWalkableAt(t,e+1)||s.isWalkableAt(t+a,e-1)&&!s.isWalkableAt(t,e-1))return[t,e]}else if(s.isWalkableAt(t+1,e+r)&&!s.isWalkableAt(t+1,e)||s.isWalkableAt(t-1,e+r)&&!s.isWalkableAt(t-1,e))return[t,e];return s.isWalkableAt(t+a,e)||s.isWalkableAt(t,e+r)?this._jump(t+a,e+r,t,e):null},i._findNeighbors=function(t){var e,i,n=t.parent,a=t.x,r=t.y,o=this.grid,h=0,l=0,u=0,d=0,f=[],c=0,p=0;if(n)h=n.x,l=n.y,u=(a-h)/Math.max(Math.abs(a-h),1),d=(r-l)/Math.max(Math.abs(r-l),1),0!==u&&0!==d?(o.isWalkableAt(a,r+d)&&f.push([a,r+d]),o.isWalkableAt(a+u,r)&&f.push([a+u,r]),(o.isWalkableAt(a,r+d)||o.isWalkableAt(a+u,r))&&f.push([a+u,r+d]),!o.isWalkableAt(a-u,r)&&o.isWalkableAt(a,r+d)&&f.push([a-u,r+d]),!o.isWalkableAt(a,r-d)&&o.isWalkableAt(a+u,r)&&f.push([a+u,r-d])):0===u?o.isWalkableAt(a,r+d)&&(f.push([a,r+d]),o.isWalkableAt(a+1,r)||f.push([a+1,r+d]),o.isWalkableAt(a-1,r)||f.push([a-1,r+d])):o.isWalkableAt(a+u,r)&&(f.push([a+u,r]),o.isWalkableAt(a,r+1)||f.push([a+u,r+1]),o.isWalkableAt(a,r-1)||f.push([a+u,r-1]));else for(e=o.getNeighbors(t,s.IfAtMostOneObstacle),c=0,p=e.length;p>c;++c)i=e[c],f.push([i.x,i.y]);return f},e}(d),b=function(t){function e(t){e.__super.call(this,t)}n(e,"PathFinding.finders.JPFMoveDiagonallyIfNoObstacles",t);var i=e.prototype;return i._jump=function(t,e,i,n){var s=this.grid,a=t-i,r=e-n;if(!s.isWalkableAt(t,e))return null;if(this.trackJumpRecursion===!0&&(s.getNodeAt(t,e).tested=!0),s.getNodeAt(t,e)===this.endNode)return[t,e];if(0!==a&&0!==r){if(this._jump(t+a,e,t,e)||this._jump(t,e+r,t,e))return[t,e]}else if(0!==a){if(s.isWalkableAt(t,e-1)&&!s.isWalkableAt(t-a,e-1)||s.isWalkableAt(t,e+1)&&!s.isWalkableAt(t-a,e+1))return[t,e]}else if(0!==r&&(s.isWalkableAt(t-1,e)&&!s.isWalkableAt(t-1,e-r)||s.isWalkableAt(t+1,e)&&!s.isWalkableAt(t+1,e-r)))return[t,e];return s.isWalkableAt(t+a,e)&&s.isWalkableAt(t,e+r)?this._jump(t+a,e+r,t,e):null},i._findNeighbors=function(t){var e,i,n=t.parent,a=t.x,r=t.y,o=this.grid,h=0,l=0,u=0,d=0,f=[],c=0,p=0;if(n)if(h=n.x,l=n.y,u=(a-h)/Math.max(Math.abs(a-h),1),d=(r-l)/Math.max(Math.abs(r-l),1),0!==u&&0!==d)o.isWalkableAt(a,r+d)&&f.push([a,r+d]),o.isWalkableAt(a+u,r)&&f.push([a+u,r]),o.isWalkableAt(a,r+d)&&o.isWalkableAt(a+u,r)&&f.push([a+u,r+d]);else{var g;if(0!==u){g=o.isWalkableAt(a+u,r);var b=o.isWalkableAt(a,r+1),m=o.isWalkableAt(a,r-1);g&&(f.push([a+u,r]),b&&f.push([a+u,r+1]),m&&f.push([a+u,r-1])),b&&f.push([a,r+1]),m&&f.push([a,r-1])}else if(0!==d){g=o.isWalkableAt(a,r+d);var v=o.isWalkableAt(a+1,r),A=o.isWalkableAt(a-1,r);g&&(f.push([a,r+d]),v&&f.push([a+1,r+d]),A&&f.push([a-1,r+d])),v&&f.push([a+1,r]),A&&f.push([a-1,r])}}else for(e=o.getNeighbors(t,s.OnlyWhenNoObstacles),c=0,p=e.length;p>c;++c)i=e[c],f.push([i.x,i.y]);return f},e}(d),m=function(t){function e(t){e.__super.call(this,t)}n(e,"PathFinding.finders.JPFNeverMoveDiagonally",t);var i=e.prototype;return i._jump=function(t,e,i,n){var s=this.grid,a=t-i,r=e-n;if(!s.isWalkableAt(t,e))return null;if(this.trackJumpRecursion===!0&&(s.getNodeAt(t,e).tested=!0),s.getNodeAt(t,e)==this.endNode)return[t,e];if(0!==a){if(s.isWalkableAt(t,e-1)&&!s.isWalkableAt(t-a,e-1)||s.isWalkableAt(t,e+1)&&!s.isWalkableAt(t-a,e+1))return[t,e]}else{if(0===r)throw new Error("Only horizontal and vertical movements are allowed");if(s.isWalkableAt(t-1,e)&&!s.isWalkableAt(t-1,e-r)||s.isWalkableAt(t+1,e)&&!s.isWalkableAt(t+1,e-r))return[t,e];if(this._jump(t+1,e,t,e)||this._jump(t-1,e,t,e))return[t,e]}return this._jump(t+a,e+r,t,e)},i._findNeighbors=function(t){var e,i,n=t.parent,a=t.x,r=t.y,o=this.grid,h=0,l=0,u=0,d=0,f=[],c=0,p=0;if(n)h=n.x,l=n.y,u=(a-h)/Math.max(Math.abs(a-h),1),d=(r-l)/Math.max(Math.abs(r-l),1),0!==u?(o.isWalkableAt(a,r-1)&&f.push([a,r-1]),o.isWalkableAt(a,r+1)&&f.push([a,r+1]),o.isWalkableAt(a+u,r)&&f.push([a+u,r])):0!==d&&(o.isWalkableAt(a-1,r)&&f.push([a-1,r]),o.isWalkableAt(a+1,r)&&f.push([a+1,r]),o.isWalkableAt(a,r+d)&&f.push([a,r+d]));else for(e=o.getNeighbors(t,s.Never),c=0,p=e.length;p>c;++c)i=e[c],f.push([i.x,i.y]);return f},e}(d)}(window,document,Laya);