Esempio n. 1
0
        public IPathGraph <TKey, TNode> Find(
            IPathMaker <TKey, TNode> pathMaker,
            TKey startKey,
            Func <TNode, bool> pathingBlocked,
            IGraph <TKey> graph
            )
        {
            var explored    = pathMaker.GetGraph();
            var currentNode = pathMaker.MakeNode(startKey, null);
            var frontier    = new PriorityList <float, TNode>();

            while (currentNode != null)
            {
                explored.Add(currentNode);
                var surroundingNodes = GetSurroundingNodes(graph, currentNode, explored);
                if (surroundingNodes != null)
                {
                    ExploreSurroundingNodes(pathingBlocked, currentNode, frontier, surroundingNodes, pathMaker, explored);
                }
                if (frontier.Count == 0)
                {
                    currentNode = null;
                    break;
                }
                currentNode = frontier[frontier.Count - 1];
                frontier.RemoveAt(frontier.Count - 1);
            }
            return(explored);
        }
Esempio n. 2
0
 public Traveler(string currentZoneName, World world, IWalker walker)
 {
     Walker                  = walker;
     Walker.IsStuck         += WalkerOnIsStuck;
     Walker.PropertyChanged += WalkerOnPropertyChanged;
     World       = world;
     CurrentZone = world.GetZoneByName(currentZoneName);
     // Position = walker.CurrentPosition;
     CurrentZone.Map.AddKnownNode(walker.CurrentPosition);
     PathMaker = new GridPathMaker
     {
         ZoneMap = CurrentZone.Map
     };
 }
Esempio n. 3
0
 private void ExploreSurroundingNodes(
     Func <TNode, bool> pathingBlocked,
     TNode currentNode,
     PriorityList <float, TNode> frontier,
     IEnumerable <TKey> surroundingNodes,
     IPathMaker <TKey, TNode> pathMaker,
     IPathGraph <TKey, TNode> explored)
 {
     foreach (TKey key in surroundingNodes)
     {
         TNode newNode = pathMaker.MakeNode(key, currentNode);
         if (pathingBlocked(newNode))
         {
             continue;
         }
         AddNodeToFrontier(explored, newNode, frontier);
     }
 }