コード例 #1
0
ファイル: MapManager.cs プロジェクト: XDKlein/forth
        List <StarSystem> GetConstellation(StarSystem system, List <StarSystem> systems)
        {
            systems.Add(system);
            List <StarSystem> systemNeighbours = system.GetConnectedNeighbours();

            if (systemNeighbours?.Count != null)
            {
                foreach (StarSystem neighbour in systemNeighbours)
                {
                    if (systems.Contains(neighbour))
                    {
                        continue;
                    }
                    List <StarSystem> subresult = GetConstellation(neighbour, new List <StarSystem>(systems));
                    foreach (StarSystem subresultSystem in subresult)
                    {
                        if (systems.Contains(subresultSystem))
                        {
                            continue;
                        }
                        systems.Add(subresultSystem);
                    }
                }
            }
            return(systems);
        }
コード例 #2
0
ファイル: MapManager.cs プロジェクト: XDKlein/forth
        //IDEAS: ConnectionLength (vector2 difference) as alternatives choose parameter; Storing shortest lengths in every node to every node;
        List <StarSystem> GetPath(StarSystem from, StarSystem to, List <StarSystem> path)
        {
            path.Add(from);
            List <StarSystem> originNeighbours = from.GetConnectedNeighbours();

            foreach (StarSystem destination in originNeighbours)
            {
                if (path.IndexOf(destination) >= 0)
                {
                    continue;
                }
                if (destination == to)
                {
                    path.Add(to);
                    return(path);
                }
                List <StarSystem> subresult = GetPath(destination, to, new List <StarSystem>(path));
                if (subresult != null)
                {
                    if (path.IndexOf(to) > 0)
                    {
                        if (subresult.Count < path.Count)
                        {
                            path = subresult;
                        }
                    }
                    else
                    {
                        path = subresult;
                    }
                }
            }
            if (path.IndexOf(to) > 0)
            {
                return(path);
            }
            return(null);
        }