private void timer1_Tick(object sender, EventArgs e) { aStar = new AStar(tileMap); List<Tile> path = aStar.FindPath(); int index = r.Next(path.Count); if (path.Count > 0) { while (path[index].TileType == TileType.Goal || path[index].TileType == TileType.Start || index == path.Count - 2 || index == 1) { index = r.Next(path.Count); } blocked.Add(path[index]); panel33_MouseDown(path[index].Panel, null); ExecuteAStar(); } else { int count = 0; int index2; int minRemove = blocked.Count / 3; while (path.Count == 0 || count < minRemove) { index2 = r.Next(blocked.Count); panel33_MouseDown(blocked[index2].Panel, null); blocked.RemoveAt(index2); ExecuteAStar(); aStar = new AStar(tileMap); path = aStar.FindPath(); count++; } } }
private void ExecuteAStar() { tileMap.ClearPath(); DateTime time1; DateTime time2; TimeSpan tSpan = new TimeSpan(); aStar = new AStar(tileMap); time1 = DateTime.Now; List<Tile> path = aStar.FindPath(); time2 = DateTime.Now; tSpan = time2.Subtract(time1); for (int i = 0; i < path.Count; i++) { if (path[i].TileType != TileType.Start && path[i].TileType != TileType.Goal) path[i].SetTileType(TileType.Path); } avgTime = ((avgTime * iters) + tSpan.TotalMilliseconds) / (iters + 1); iters++; StringBuilder s = new StringBuilder(); s.AppendLine("Time: " + tSpan.ToString()); s.AppendLine("Avg: " + avgTime); s.AppendLine("Iters: " + iters); timelbl.Text = s.ToString(); }