Пример #1
0
        /// <summary>
        /// This method find the next path node to visit, puts that node on the
        /// closed list and adds any nodes adjacent to the visited node to the
        /// open list.
        /// </summary>
        private void DoSearchStep()
        {
            SearchNode newOpenListNode;

            bool foundNewNode = SelectNodeToVisit(out newOpenListNode);

            if (foundNewNode)
            {
                Point currentPos = newOpenListNode.Position;
                foreach (Point point in map.OpenMapTiles(currentPos))
                {
                    SearchNode mapTile = new SearchNode(point,
                                                        map.StepDistanceToEnd(point),
                                                        newOpenListNode.DistanceTraveled + 1);
                    if (!InList(openList, point) &&
                        !InList(closedList, point))
                    {
                        openList.Add(mapTile);
                        paths[point] = newOpenListNode.Position;
                    }
                }
                if (currentPos == map.EndTile)
                {
                    searchStatus = SearchStatusEnum.PathFound;
                }
                openList.Remove(newOpenListNode);
                closedList.Add(newOpenListNode);
            }
            else
            {
                searchStatus = SearchStatusEnum.NoPath;
            }
        }
Пример #2
0
        /// <summary>
        /// Setup search
        /// </summary>
        /// <param name="mazeMap">Map to search</param>
        public void Initialize(Map mazeMap)
        {
            searchStatus = SearchStatusEnum.Stopped;
            openList     = new List <SearchNode>();
            closedList   = new List <SearchNode>();
            paths        = new Dictionary <Point, Point>();
            map          = mazeMap;

            //for depth first
            visitedNodesStack = new Stack <SearchNode>();
        }
Пример #3
0
 /// <summary>
 /// Reset the search
 /// </summary>
 public void Reset()
 {
     searchStatus     = SearchStatusEnum.Stopped;
     totalSearchSteps = 0;
     Scale            = map.Scale;
     openList.Clear();
     closedList.Clear();
     paths.Clear();
     openList.Add(new SearchNode(map.StartTile,
                                 Map.StepDistance(map.StartTile, map.EndTile)
                                 , 0));
     startPosition = map.StartTile;
     visitedNodesStack.Clear();
 }