Ejemplo n.º 1
0
        public void connectExits(Map map)
        {
            var closed      = new Dictionary <string, HashSet <string> >();
            var pathfinding = new SimplePathfinding();
            int numPaths    = 0;

            foreach (ExitPoint exit1 in exits)
            {
                foreach (ExitPoint exit2 in exits)
                {
                    if (exit1.x == exit2.x && exit1.y == exit2.y)
                    {
                        continue;
                    }
                    if (closed.ContainsKey(exit1.id) && closed[exit1.id].Contains(exit2.id))
                    {
                        continue;
                    }
                    if (closed.ContainsKey(exit2.id) && closed[exit2.id].Contains(exit1.id))
                    {
                        continue;
                    }

                    var path = pathfinding.SimplePath(map, int.MaxValue, exit1.x, exit1.y, exit2.x, exit2.y, this);
                    if (path != null)
                    {
                        if (!closed.ContainsKey(exit1.id))
                        {
                            closed[exit1.id] = new HashSet <string>();
                        }
                        if (!closed.ContainsKey(exit2.id))
                        {
                            closed[exit2.id] = new HashSet <string>();
                        }
                        closed[exit1.id].Add(exit2.id);
                        closed[exit2.id].Add(exit1.id);
                        addPath(exit1, exit2, path);
                        ++numPaths;
                    }
                }
            }
            Out.put("Cluster " + id + ": paths count : " + numPaths);
            //foreach (ExitPoint exit1 in exits)
            //{
            //    Out.put(exit1.id);
            //}
        }
        public List<Node> findPath(Node start, Node end)
        {
            Cluster startCluster;
            Cluster endCluster;
            //first find which are our start and endClusters     
            findEndClusters(start, end, out startCluster, out endCluster);

            //if we start and end in the same cluster, check if we can get a path without leaving the cluster
            if(startCluster == endCluster)
            {
                var simplePath = new SimplePathfinding();
                var path = simplePath.SimplePath(clusterMap.getMap(), int.MaxValue, start, end, startCluster);
                if (path != null)
                    return path;
            }



            return null;
        }
Ejemplo n.º 3
0
 Pathfinder()
 {
     pathfinder = new SimplePathfinding();
 }