Exemplo n.º 1
0
 public bool findPath(NodeGrid grid)
 {
     this._grid = grid;
     if (null == this._open)
     {
         this._open = new BinaryStack("f");
     }
     else
     {
         this._open.ClearAll();
     }
     grid.Clear();
     this._open._nodeGrid = grid;
     if (null == this._closed)
     {
         this._closed = new Dictionary <long, bool>(1000);
     }
     else
     {
         this._closed.Clear();
     }
     this._startNodeX = this._grid.startNodeX;
     this._startNodeY = this._grid.startNodeY;
     this._endNodeX   = this._grid.endNodeX;
     this._endNodeY   = this._grid.endNodeY;
     this._grid.Nodes[this._startNodeX, this._startNodeY].g = 0.0;
     this._grid.Nodes[this._startNodeX, this._startNodeY].h = this.diagonal(this._startNodeX, this._startNodeY);
     this._grid.Nodes[this._startNodeX, this._startNodeY].f = this._grid.Nodes[this._startNodeX, this._startNodeY].g + this._grid.Nodes[this._startNodeX, this._startNodeY].h;
     return(this.search());
 }
Exemplo n.º 2
0
        public bool findPath(NodeGrid grid)
        {
            _grid = grid;
            if (null == _open)
            {
                _open = new BinaryStack("f");
            }
            else
            {
                _open.ClearAll();
            }

            grid.Clear();
            _open._nodeGrid = grid; //每次寻路, 必须设置,内部使用

            if (null == _closed)
            {
                _closed = new Dictionary <long, bool>(1000);
            }
            else
            {
                _closed.Clear();
            }

            _startNodeX = _grid.startNodeX;
            _startNodeY = _grid.startNodeY;
            _endNodeX   = _grid.endNodeX;
            _endNodeY   = _grid.endNodeY;

            _grid.Nodes[_startNodeX, _startNodeY].g = 0;
            _grid.Nodes[_startNodeX, _startNodeY].h = diagonal(_startNodeX, _startNodeY);
            _grid.Nodes[_startNodeX, _startNodeY].f = _grid.Nodes[_startNodeX, _startNodeY].g + _grid.Nodes[_startNodeX, _startNodeY].h;

            return(search());
        }
Exemplo n.º 3
0
        public object Clone()
        {
            NodeGrid obj = base.MemberwiseClone() as NodeGrid;

            obj._fixedObstruction = (this._fixedObstruction.Clone() as byte[, ]);
            return(obj);
        }
Exemplo n.º 4
0
        //查寻路径
        public List <ANode> find(NodeGrid grid)
        {
            if (findPath(grid))
            {
                //这儿返回的path不要移除第一个元素,客户端移除了,但是服务器端原来没有移除,所以,这儿也不要移除
                return(_path);
            }

            return(null);
        }
Exemplo n.º 5
0
        public List <ANode> find(NodeGrid grid)
        {
            List <ANode> result;

            if (this.findPath(grid))
            {
                result = this._path;
            }
            else
            {
                result = null;
            }
            return(result);
        }