public void Reset() { for (int i = 0; i < NodeCost.Length; i++) { NodeCost[i] = 0; ParentNode[i] = -1; } OpenList.Clear(); ClosedList.Clear(); }
/// <summary> /// 重置 /// </summary> public void ReSet() { if (StartCell != null) { MapBmpFillRectangle(StartCell, this._whiteSmoke); StartCell = null; } if (GoalCell != null) { MapBmpFillRectangle(GoalCell, this._whiteSmoke); GoalCell = null; } MapBmpFillRectangles(StoneCells, this._whiteSmoke); StoneCells.Clear(); MapBmpFillRectangles(ClosedList, this._whiteSmoke); ClosedList.Clear(); MapBmpFillRectangles(OpenList, this._whiteSmoke); OpenList.Clear(); }
public override ArrayList FindPaths(int StartPos, int InEndPos, int InID) { ArrayList Paths = new ArrayList(); if (!IsValidPosIndex(StartPos) || !IsValidPosIndex(InEndPos)) { return(Paths); } CTimeCheck.Start(InID); EndPos = InEndPos; ClosedList.Clear(); OpenList.Clear(); foreach (Tile tile in Tiles) { if (tile.bBlock) { ClosedList.Add(tile.Index); } tile.Reset(); } ClosedList.Add(StartPos); int FindNextPath = StartPos; int path_make_start_time = Environment.TickCount; while (true) { //if (100 <= Environment.TickCount - path_make_start_time) // return Paths; ArrayList MakedOpenList = MakeOpenList(FindNextPath); if (OpenList.Count == 0) { CDebugLog.Log(ELogType.AStar, "OpenList.Count == 0"); } //FindNextPath = FindNextPathIndex(ref MakedOpenList); ////FindNextPath = FindNextPathIndexFromOpenList(); //if (-1 == FindNextPath) //{ FindNextPath = FindNextPathIndexFromOpenList(); //} if (-1 == FindNextPath) { CTimeCheck.End(ELogType.AStar, "Failed FindPaths"); return(Paths); } if (FindNextPath == EndPos) { break; } OpenList.Remove(FindNextPath); ClosedList.Add(FindNextPath); } int path_index = EndPos; Paths.Add(EndPos); while (true) { if (path_index == StartPos) { break; } Paths.Add(((Tile)Tiles[path_index]).ParentTile); path_index = ((Tile)Tiles[path_index]).ParentTile; } Paths.Reverse(); CTimeCheck.End(ELogType.AStar, "Success FindPaths"); return(Paths); }