Esempio n. 1
0
        public static CityNode ClosestParking(CityNode goal)
        {
            List <CityNode> current = new List <CityNode>();
            List <CityNode> next    = new List <CityNode>();

            current.Add(goal);

            int len = 0;

            while (len < 100)
            {
                foreach (CityNode n in current)
                {
                    if (n is ParkingNode && (n as ParkingNode).vehicle == null)
                    {
                        return(n);
                    }
                    foreach (CityPath p in n.paths)
                    {
                        next.Add(p.e);
                    }
                }

                current = next;
                next    = new List <CityNode>();

                len++;
            }

            throw new Exception("NO AVAILABLE PARKING");
        }
Esempio n. 2
0
        public CityNode NearestNode(int x, int y, CityPathType type)
        {
            double   minDist = 100000;
            CityNode nearest = null;

            foreach (CityNode n in nodes)
            {
                bool typeGood = false;
                foreach (CityPath p in n.paths)
                {
                    if (p.type == type)
                    {
                        typeGood = true;
                    }
                }
                if (typeGood)
                {
                    double dist = Util.Distance(x, y, n.x, n.y);
                    if (dist <= minDist)
                    {
                        minDist = dist;
                        nearest = n;
                    }
                }
            }
            return(nearest);
        }
Esempio n. 3
0
        public CityPath(CityNode s, CityNode e, CityPathType type, double radius)
        {
            this.s      = s;
            this.e      = e;
            this.radius = radius;

            this.type = type;

            vehicles = new List <Vehicle>();
            PATHS_COUNT++;
        }
Esempio n. 4
0
        //Connect this node to next with the specified transportation type and turn radius, and return the path created.
        public CityPath Connect(CityNode next, CityPathType type, double radius)
        {
            if (next == null)
            {
                throw new Exception("Trying to connect a node to null");
            }
            CityPath p = new CityPath(this, next, type, radius);

            paths.Add(p);
            return(p);
        }
Esempio n. 5
0
        public static List <CityPath> GetPath(CityNode start, CityNode end, CityPathType type)
        {
            List <CityNode>       tested  = new List <CityNode>();
            List <PathFinderNode> current = new List <PathFinderNode>();
            List <PathFinderNode> next    = new List <PathFinderNode>();

            current.Add(new PathFinderNode(new CityPath(null, start, type), null));

            int len = 0;

            while (len < 100)
            {
                foreach (PathFinderNode n in current)
                {
                    if (n.path.e == end)
                    {
                        return(n.GetPath());
                    }
                    tested.Add(n.path.e);
                    foreach (CityPath p in n.path.e.paths)
                    {
                        if (tested.Contains(p.e))
                        {
                            continue;
                        }
                        if (p.type != type)
                        {
                            continue;
                        }
                        next.Add(new PathFinderNode(p, n));
                    }
                }

                current = next;
                next    = new List <PathFinderNode>();

                len++;
            }

            throw new Exception("NO PATH FOUND");
        }