Файловый менеджер - Редактировать - /home/jogoso94/public_html/jogos/tutti_frutti_match/pathfind.js
�азад
"use strict";{const a=0,b=Math.pow(2,26),c=2147483647;function XYToKey(t,e){return t*b+e}function KeyToXY(t){const e=Math.floor(t/b),s=t%b;return[e,s]}function Make2DCellArray(e,s){const i=[];for(let t=0;t<e;++t)i.push(new Int32Array(s));return i}const d=new Map;function GetPathfinder(t){let e=d.get(t);return e||(e=new g,d.set(t,e)),e}self.JobHandlers["PFCellData"]=function(t){const e=t["mapKey"],s=t["hcells"],i=t["vcells"],l=t["cellData"],h=GetPathfinder(e);h.Init(s,i,l)},self.JobHandlers["PFUpdateRegion"]=function(t){const e=t["mapKey"],s=t["cx1"],i=t["cy1"],l=t["lenx"],h=t["leny"],o=t["cellData"],n=GetPathfinder(e);n.UpdateRegion(s,i,l,h,o)},self.JobHandlers["PFResetAllCellData"]=function(t){for(const e of d.values())e.Clear()},self.JobHandlers["PFFindPath"]=function(t){const e=t["mapKey"],s=t["cellX"],i=t["cellY"],l=t["destCellX"],h=t["destCellY"],o=t["moveCost"],n=t["diagonalsEnabled"],a=t["directMovementMode"],r=GetPathfinder(e),_=t["pathGroup"],d=(r.IsInPathGroup()?_?r.GetPathGroupId()!==_["id"]&&(r.EndGroup(),r.StartGroup(_["id"],_["cost"],_["cellSpread"])):r.EndGroup():_&&r.StartGroup(_["id"],_["cost"],_["cellSpread"]),r.SetMoveCost(o),r.SetDiagonalsEnabled(n),r.FindPath(s,i,l,h,a));return{result:d}};let s=0;class f{constructor(t,e){this._parent=null,this._x=t||0,this._y=e||0,this._f=0,this._g=0,this._h=0,this._seq=s++}SetXY(t,e){this._x=t,this._y=e}static Sort(t,e){const s=t._f,i=e._f;return s!==i?s-i:t._seq-e._seq}}class g{constructor(){this._adjacentCost=10,this._diagonalCost=14,this._hcells=0,this._vcells=0,this._cells=null,this._openList=new self.RedBlackSet(f.Sort),this._openMap=new Map,this._closedSet=new Set,this._currentNode=null,this._targetX=0,this._targetY=0,this._diagonalsEnabled=!0,this._isInPathGroup=!1,this._pathGroupId=-1,this._pathGroupCost=0,this._pathGroupCellSpread=0,this._groupCostCells=null}Init(t,e,s){this._hcells===t&&this._vcells===e||this.EndGroup(),this._hcells=t,this._vcells=e,this._cells=s}UpdateRegion(e,s,i,t,l){const h=this._cells;if(h)for(let t=0;t<i;++t)h[e+t].set(l[t],s)}Clear(){this.EndGroup(),this._cells=null}_ClearIntermediateData(){this._openList.Clear(),this._openList=new self.RedBlackSet(f.Sort),this._openMap.clear(),this._closedSet.clear(),this._currentNode=null,s=0}UpdateRegion(s,i,t,l,h){for(let e=0;e<t;++e)for(let t=0;t<l;++t)this._cells[s+e][i+t]=h[e][t]}SetMoveCost(t){this._adjacentCost=Math.floor(t),this._diagonalCost=Math.round(this._adjacentCost*Math.SQRT2)}SetDiagonalsEnabled(t){this._diagonalsEnabled=!!t}StartGroup(t,e,s){this._isInPathGroup||(this._isInPathGroup=!0,this._pathGroupId=t,this._pathGroupCost=e,this._pathGroupCellSpread=s,this._groupCostCells=Make2DCellArray(this._hcells,this._vcells))}EndGroup(){this._isInPathGroup&&(this._isInPathGroup=!1,this._pathGroupId=-1,this._groupCostCells=null)}IsInPathGroup(){return this._isInPathGroup}GetPathGroupId(){return this._pathGroupId}At(t,e){if(t<0||e<0||t>=this._hcells||e>=this._vcells)return c;let s=this._cells[t][e];return s=null!==this._groupCostCells?Math.min(s+this._groupCostCells[t][e],c):s}IsBoxAllClear(t,e,s,i){const l=Math.min(t,s),h=Math.max(t,s),o=Math.min(e,i),n=Math.max(e,i);for(let t=l;t<=h;++t){const a=this._cells[t];for(let t=o;t<=n;++t)if(0!==a[t])return!1}return!0}FindPath(t,e,s,i,l){if(!this._cells)return null;t=Math.floor(t),e=Math.floor(e),s=Math.floor(s),i=Math.floor(i),this._targetX=s,this._targetY=i;const h=Math.min(t,s),o=Math.max(t,s),n=Math.min(e,i),a=Math.max(e,i);return h<0||n<0||o>=this._hcells||a>=this._vcells?null:0!==l&&this.IsBoxAllClear(t,e,s,i)?[{x:s,y:i}]:this._AStarFindPath(t,e,l)}_AStarFindPath(t,e,s){const i=this._adjacentCost,l=this._diagonalCost,h=this._diagonalsEnabled,o=this._openList,n=this._openMap,a=this._closedSet,r=new f(t,e);for(o.Add(r),n.set(XYToKey(t,e),r);!o.IsEmpty();){const _=o.Shift(),d=XYToKey(_._x,_._y);if(n.delete(d),a.add(d),_._x===this._targetX&&_._y===this._targetY)return this._ClearIntermediateData(),this._GetResultPath(_,s);const p=(this._currentNode=_)._x,u=_._y,C=this.At(p-1,u)===c,g=this.At(p,u-1)===c,M=this.At(p+1,u)===c,G=this.At(p,u+1)===c;C||this._AddCellToOpenList(p-1,u,i),!h||C||g||this.At(p-1,u-1)===c||this._AddCellToOpenList(p-1,u-1,l),g||this._AddCellToOpenList(p,u-1,i),!h||g||M||this.At(p+1,u-1)===c||this._AddCellToOpenList(p+1,u-1,l),M||this._AddCellToOpenList(p+1,u,i),!h||M||G||this.At(p+1,u+1)===c||this._AddCellToOpenList(p+1,u+1,l),G||this._AddCellToOpenList(p,u+1,i),!h||G||C||this.At(p-1,u+1)===c||this._AddCellToOpenList(p-1,u+1,l)}return this._ClearIntermediateData(),null}_AddCellToOpenList(t,e,s){const i=XYToKey(t,e);if(!this._closedSet.has(i)){const l=this.At(t,e),h=this._openMap.get(i);h?this._currentNode._g+s+l<h._g&&this._UpdateNodeInOpenList(h,s,l):this._AddNewNodeToOpenList(t,e,s,l)}}_UpdateNodeInOpenList(t,e,s){const i=this._openList,l=this._currentNode;i.Remove(t),t._parent=l,t._g=l._g+e+s,t._h=this._EstimateH(t._x,t._y),t._f=t._g+t._h,i.Add(t)}_AddNewNodeToOpenList(t,e,s,i){const l=new f(t,e),h=this._EstimateH(t,e),o=this._currentNode._g+s+i;l._h=h,l._g=o,l._f=h+o,l._parent=this._currentNode,this._openMap.set(XYToKey(t,e),l),this._openList.Add(l)}_EstimateH(t,e){const s=Math.abs(t-this._targetX),i=Math.abs(e-this._targetY),l=this._adjacentCost*(s+i);return this._diagonalsEnabled?l+(this._diagonalCost-2*this._adjacentCost)*Math.min(s,i):l}_GetResultPath(t,e){let s=[],i=t;for(;i;)s.push({x:i._x,y:i._y}),i=i._parent;return s.reverse(),this._isInPathGroup&&this._AddPathGroupCost(s),s=this._FilterRedundantNodes(s),2===e&&(s=this._FilterNodesForDirectMovement(s),s=this._FilterRedundantNodes(s)),1<s.length&&s.shift(),s}_AddPathGroupCost(t){const e=this._pathGroupCost,s=this._pathGroupCellSpread,i=Math.floor(s/2),l=this._hcells,h=this._vcells,o=new Set;for(const n of t){const a=n.x,r=n.y,_=Math.max(a-i,0),d=Math.max(r-i,0),c=Math.min(_+s,l),p=Math.min(d+s,h);for(let e=_;e<c;++e)for(let t=d;t<p;++t)o.add(XYToKey(e,t))}for(const u of o){const[f,C]=KeyToXY(u);this._groupCostCells[f][C]+=e}}_FilterRedundantNodes(s){if(0===s.length)return[];let i=s[0];if(1===s.length)return[i];const l=[i];let h=s[1],o=h.x-i.x,n=h.y-i.y;for(let t=1,e=s.length;t<e;++t)if(i=s[t],t===e-1)l.push(i);else{const a=(h=s[t+1]).x-i.x,r=h.y-i.y,_=Math.abs(a)<1e-7&&Math.abs(o)<1e-7&&Math.sign(r)===Math.sign(n),d=Math.abs(r)<1e-7&&Math.abs(n)<1e-7&&Math.sign(a)===Math.sign(o);!_&&!d&&.001<Math.abs(a/o-r/n)&&(l.push(i),o=a,n=r)}return l}_FilterNodesForDirectMovement(e){if(0===e.length)return[];if(e.length<=2)return e.slice(0);const t=[];let s=0,i=e.length;for(;s<i;){const l=e[s];if(t.push(l),s>=i-2)++s;else{let t=s+1;for(;t<i&&(s=t,!(++t>=i));){const h=e[t];if(!this.IsBoxAllClear(l.x,l.y,h.x,h.y))break}}}return t}}}
| ver. 1.4 |
Github
|
.
| PHP 8.2.29 | Генераци� �траницы: 0 |
proxy
|
phpinfo
|
�а�тройка