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()); }
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()); }