コード例 #1
0
ファイル: Spider.cs プロジェクト: jonfast565/Spidr
        public void ProcessNewPaths(Page p, UrlObject domainObject)
        {
            if (p != null && domainObject != null)
            {
                Console.WriteLine("Visited: " + p.Link.GetFullPath(false));

                Unvisited.Remove(p.Link.GetFullPath(false));
                if (!Visited.ContainsKey(p.Link.GetFullPath(false)))
                {
                    Visited.Add(p.Link.GetFullPath(false), p);
                }

                foreach (LinkTag l in p.LinkTags)
                {
                    var toBeVisited = false;
                    var visited     = false;
                    try
                    {
                        var key = Unvisited[l.Url.GetFullPath(false)];
                        toBeVisited = true;
                    }
                    catch (KeyNotFoundException /* knfe */) { }

                    try
                    {
                        var key = Visited[l.Url.GetFullPath(false)];
                        visited = true;
                    }
                    catch (KeyNotFoundException /* knfe */) { }

                    if (toBeVisited != true
                        & visited != true)
                    {
                        if (l.Url.GetDomain() == domainObject.GetDomain())
                        {
                            Unvisited.Add(l.Url.GetFullPath(false), l.Url);
                        }
                    }
                }
            }
        }
コード例 #2
0
        public void Update()
        {
            Steps           += 1;
            Current          = _queue.Dequeue();
            Visited[Current] = true;

            if (Current == Goal)
            {
                Console.WriteLine($"Found goal in {Steps} steps");
                Searching   = false;
                AutoAdvance = false;

                while (Current != Start)
                {
                    Path.Add(Current);
                    Current = CameFrom[Current];
                }
                Current = null;  // To show start

                return;
            }

            foreach (Tile tile in Current.Neighbours)
            {
                if (!Visited.ContainsKey(tile) && !_queue.Contains(tile) && tile.Type != TileType.Blocked)
                {
                    _queue.Enqueue(tile);
                    CameFrom[tile] = Current;
                }
            }

            if (_queue.Count == 0)
            {
                Searching = false;
            }
        }