Esempio n. 1
0
        public IEnumerable <Point> FindPath(IMap map, Point from, Point to)
        {
            var points = new AvlTree <AStarPoint>();
            var path   = new System.Collections.Generic.Dictionary <AStarPoint, AStarPoint>();
            var start  = new AStarPoint(from, to, null);
            var finish = new AStarPoint(to, to, null);

            points.Insert(start);
            path[start] = null;
            while (points.Count != 0)
            {
                var point = points.GetMinOrThrow();
                if (point.Point.Equals(to))
                {
                    break;
                }
                var nextPoints = map.GetAreaOfPoint(point.Point)
                                 .Where(map.IsCouldVisited)
                                 .Select(p => new AStarPoint(p, to, point))
                                 .Where(p => !path.ContainsKey(p));
                foreach (var aStarPoint in nextPoints)
                {
                    points.Insert(aStarPoint);
                    path[aStarPoint] = point;
                }
                points.Remove(point);
            }
            foreach (var point in BuildPath(path, finish))
            {
                yield return(point);
            }
        }
Esempio n. 2
0
 public void FindMin()
 {
     for (var i = 0; i < 5; i++)
     {
         _avlTree.Insert(i);
     }
     _avlTree.GetMinOrThrow().Should().Be(0);
 }