Наследование: IComparable
Пример #1
0
        internal static List <int> BFS(int s, int d)
        {
            lock (Rooms)
            {
                InitBFSVertices();
                Queue <MappedRoom> Q = new Queue <MappedRoom>();
                int srcidx           = FindRoom(s); // logn
                if (srcidx < 0)
                {
                    return(null);
                }
                MappedRoom source = Rooms[srcidx];
                source.Visited = true;
                Q.Enqueue(source);

                while (Q.Count > 0)
                {
                    MappedRoom dequeued = Q.Dequeue();
                    if (dequeued.Id == d)
                    {
                        // return a result
                        return(BFSPath(source, dequeued));
                    }
                    foreach (MappedRoom neighbor in dequeued.MappedNeighbors)
                    {
                        if (!neighbor.Visited)
                        {
                            neighbor.Visited = true;
                            neighbor.Pi      = dequeued;
                            Q.Enqueue(neighbor);
                        }
                    }
                }
                return(null);
            }
        }
Пример #2
0
        internal void Spider(object p_bound)
        {
            string bound = p_bound == null ? string.Empty : ((string)p_bound).ToLower();
                // should probably update UI as well
                CoreUI.Instance.Settings.AutoTeleport = false;

                // start in this room
                RefreshRoom();

                Stack<int> s = new Stack<int>();
                List<int> completed = new List<int>();

                // start spidering
                Globals.Spidering = true;
                do
                {
                    if (bound != string.Empty && bound == Location.Name.ToLower())
                    {
                        if (!completed.Contains(Location.Id))
                            completed.Add(Location.Id);
                        goto prep;
                    }

                    // make sure links of current room are in rooms db
                    List<MappedRoom> rooms = Pathfinder.Rooms.FindAll(delegate(MappedRoom rm)
                    {
                        return rm.Id == Location.Id;
                    });

                    if (rooms.Count < 1)
                    {
                        // new room
                        List<int> l = new List<int>();
                        foreach (int k in Location.Links)
                            l.Add(k);
                        MappedRoom mr = new MappedRoom(Location.Id, Location.Name, l);
                        Pathfinder.Rooms.Add(mr);
                        //rooms.Add(mr);

                        CoreUI.Instance.LogPanel.Log(string.Format("Added new room {0}", Location.Id));
                    }
                    else
                    {
                        if (rooms.Count > 1)
                        {
                            // should only be one match
                            MessageBox.Show("problem");
                            CoreUI.Instance.LogPanel.Log(string.Format("Potential duplicate room {0}", Location.Id));
                        }

                        // already exists
                        // add links to map skeleton
                        foreach (MappedRoom rm in rooms)
                        {
                            rm.Name = Location.Name;
                            foreach (int id in Location.Links)
                            {
                                if (!rm.Neighbors.Contains(id) && id > 0)
                                {
                                    rm.Neighbors.Add(id);
                                    CoreUI.Instance.LogPanel.Log(string.Format("Added link {0} from {1}", id, Location.Id));
                                }
                            }
                        }
                    }

                    // bookkeeping
                    if (!completed.Contains(Location.Id))
                        completed.Add(Location.Id);
                    foreach (int id in Location.Links)
                    {
                        if (id > 0 && !s.Contains(id) && !completed.Contains(id))
                        {
                            Console.WriteLine("Adding link {0}->{1}", Location.Id, id);
                            List<int> nbrslist = new List<int> {Location.Id};
                            MappedRoom mr = new MappedRoom(id, string.Empty, nbrslist);
                            Pathfinder.Rooms.Add(mr);
                            s.Push(id);
                        }
                    }
                    // sort for pathfinding search
                    Pathfinder.Rooms.Sort();
                    Pathfinder.LinkRooms();

                    // add mobs
                    foreach (Mob mb in Location.Mobs)
                    {
                        mb.Initialize();
                        Pathfinder.Mobs.Add(new MappedMob(mb.Name, mb.Id, Location.Id, mb.Level, mb.Rage));
                    }

                    prep:

                    if (s.Count < 1)
                        // done
                        break;

                    // move to top of stack
                    int next = s.Pop();
                    Console.WriteLine("Pathing from {0} to {1}", Location.Id, next);
                    PathfindTo(next);
                    if(!completed.Contains(next))
                        completed.Add(next);
                } while (Globals.AttackMode);

                Globals.Spidering = false;
                MessageBox.Show("Done spidering");
        }
Пример #3
0
        private static List<int> BFSPath(MappedRoom s, MappedRoom v)
        {
            // assume BFS has just been run

            List<int> ret = new List<int>();
            while (s.Id != v.Id)
            {
                if (v.Pi == null)
                    return null;    // no path

                ret.Add(v.Id);
                v = v.Pi;
            }
            ret.Reverse();
            return ret;
        }