private void button1_Click(object sender, EventArgs e)
        {
            tileMap.ClearPath();
            DateTime time1 = DateTime.Now;
            DateTime time2;
            if (aStar == null)
                aStar = new AStar(tileMap);

            aStar.Iterate(ref current, ref open, ref closed);

            current.SetTileType(TileType.Current);

            for (int i = 0; i < open.Count; i++)
            {
                if (open[i].TileType != TileType.Start &&
                    open[i].TileType != TileType.Goal)
                    open[i].SetTileType(TileType.Open);
            }

            for (int i = 0; i < closed.Count; i++)
            {
                if (closed[i].TileType != TileType.Start &&
                    closed[i].TileType != TileType.Goal)
                    closed[i].SetTileType(TileType.Closed);
            }
            time2 = DateTime.Now;
            timelbl.Text = "Time: " + time2.Subtract(time1).ToString();
        }
        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();
        }