Exemplo n.º 1
0
        public void FindBestWay()
        {
            List <Cell> unavailable  = new List <Cell>();
            Cell        startCell    = this.entryCell;
            Cell        finishCell   = null;
            bool        target_found = false;
            string      partOfWay    = string.Empty;

            while (finishCell != this.exitCell)
            {
                this.Locate(startCell);
                if (points.Count == 0)
                {
                    finishCell = exitCell;
                }
                else
                {
                    unavailable = points.Where(x => x.GetDistance() == int.MaxValue - 1).ToList();
                    foreach (Cell c in unavailable)
                    {
                        points.Remove(c);
                    }
                    points     = points.OrderBy(x => x.GetDistance()).ToList();
                    finishCell = points.First();
                    points.Remove(finishCell);
                }
                finishCell.Walk(finishCell.GetDistance() + 1, ref partOfWay, ref target_found);
                startCell = finishCell;
                this.SetWay(partOfWay);
                partOfWay    = string.Empty;
                target_found = false;
                this.ResetDistances();
            }
        }