Example #1
0
        public static int FindDistance(OrbitalBody first, OrbitalBody second)
        {
            int dist = 0;
            var foundCommonAncestor = false;
            var currentBody         = first.Parent;

            while (!foundCommonAncestor)
            {
                if (currentBody.hasChild(second.Name))
                {
                    foundCommonAncestor = true;
                }
                else
                {
                    currentBody = currentBody.Parent;
                    dist++;
                }
            }
            foundCommonAncestor = false;
            currentBody         = second.Parent;
            while (!foundCommonAncestor)
            {
                if (currentBody.hasChild(first.Name))
                {
                    foundCommonAncestor = true;
                }
                else
                {
                    currentBody = currentBody.Parent;
                    dist++;
                }
            }

            return(dist);
        }
Example #2
0
        public OrbitalBody(string input, OrbitalBody parent = null)
        {
            var values = input.Split(')');

            Name           = values[0];
            OrbitingBodies = new List <OrbitalBody>();
            Parent         = parent;
        }
Example #3
0
        public static OrbitalBody GetOrbits(string name, string[] input, OrbitalBody parent)
        {
            var items = input.Where(x => x.StartsWith(name)).ToList();

            if (items.Count == 0)
            {
                return(new OrbitalBody(name, parent));
            }

            var returnval = new OrbitalBody(items[0], parent);

            foreach (var item in items)
            {
                returnval.OrbitingBodies.Add(GetOrbits(item.Split(')')[1], input.Where(x => !x.StartsWith(name)).ToArray(), returnval));
            }
            return(returnval);
        }
Example #4
0
        public static OrbitalBody FindReference(string name, OrbitalBody baseOrbit)
        {
            var match = baseOrbit.OrbitingBodies.FirstOrDefault(x => x.Name == name);

            if (match != null)
            {
                return(match);
            }

            foreach (var body in baseOrbit.OrbitingBodies)
            {
                match = FindReference(name, body);
                if (match != null)
                {
                    return(match);
                }
            }

            return(null);
        }