상속: MonoBehaviour
            public object Clone()
            {
                PathOpen newPath = (PathOpen)this.MemberwiseClone();

                newPath.waypoints = new List <Road>(this.waypoints);
                return(newPath);
            }
        public static List <PathOpen> BranchPath(PathOpen root, int maxDist)
        {
            List <PathOpen> pathBranches = new List <PathOpen>();

            Map.Direction[] directions = (Map.Direction[])Enum.GetValues(typeof(Map.Direction));

            foreach (Map.Direction dir in directions)
            {
                bool isBackwardMove;
                if (root.waypoints.Count - 2 >= 0)
                {
                    isBackwardMove = root.waypoints.Last().GetIntersectionLink(dir) == root.waypoints[root.waypoints.Count - 2];
                }
                else
                {
                    isBackwardMove = false;
                }
                if (root.waypoints.Last().GetIntersectionLink(dir) != null && !isBackwardMove)
                {
                    PathOpen newPath = (PathOpen)root.Clone();
                    int      addDist = root.waypoints.Last().GetLinkDistance(dir);
                    newPath.distActualWorking += addDist;
                    newPath.waypoints.Add(root.waypoints.Last().GetIntersectionLink(dir));
                    pathBranches.Add(newPath);
                }
            }
            return(pathBranches);
        }
        public static Path FinalizePathOpen(PathOpen pathOpen)
        {
            Path finalizedPath = new Path();

            finalizedPath.waypoints = pathOpen.waypoints;
            int finalDist = pathOpen.GetDistWorkingTotal();

            finalizedPath.distActual = finalDist;
            finalizedPath.waypoints.Add(pathOpen.destination);
            return(finalizedPath);
        }
        public static Path FindPath(Road source, Road dest)
        {
            List <PathOpen> openPaths         = new List <PathOpen>();
            int             shortestDistFound = Map.mapHeight * Map.mapWidth;
            Path            shortestPathFound = new Path();
            PathOpen        initialPath       = new PathOpen(source, dest);

            openPaths.Add(initialPath);

            while (openPaths.Count > 0)
            {
                PathOpen workingPath = openPaths[0];
                openPaths.RemoveAt(0);
                // Checks if the working path is on the same street as the destination.
                if (AreSameStreet(workingPath.waypoints.Last(), dest))
                {
                    // If it's on the same street finalize the working path
                    Path finalizedPath = FinalizePathOpen(workingPath);
                    // Check if the newly finialized path is shorter than the shortest found.
                    if (finalizedPath.distActual < shortestDistFound)
                    {
                        // Then Update the shortest path.
                        shortestPathFound = finalizedPath;
                        shortestDistFound = finalizedPath.distActual;
                        openPaths         = CullOpenPaths(openPaths, shortestDistFound);
                    }
                }
                else
                {
                    List <PathOpen> branchedPath = BranchPath(workingPath, shortestDistFound);
                    openPaths.AddRange(branchedPath);
                    openPaths = CullOpenPaths(openPaths, shortestDistFound);
                    openPaths.OrderBy(x => x.GetDistWorkingTotal()).ToList();
                }
            }
            return(shortestPathFound);
        }