//Also keeps in mind the PlayerDistance Dictionary.
 public double getSystemWorth(BalancingPlayer player)
 {
     double playerDistance = PlayerDistance[player];
     //The planet is contested
     if (PlayerDistance.Count > 1)
     {
         double totalDistance = PlayerDistance.Aggregate(0.0, (accumulator, pair) => accumulator + pair.Value);
         double playerWorth = (1 - playerDistance / totalDistance) * getSystemWorth();
         return playerWorth;
     }
     else
     {
         return getSystemWorth();
     }
 }
 private double playerScore(BalancingPlayer player)
 {
     return player.Stars.Aggregate(0.0, (scoreAccumulator, system) => scoreAccumulator + system.getSystemWorth(player));
 }
        //Find nearby Stars greedily
        private HashSet<BalancingStarSystem> findNearbyStars(double maxDistance, BalancingPlayer player)
        {
            BalancingStarSystem start = player.SpawnStar;

            //Create a list of stars in range of the player and also to prevent doubly adding stars.
            HashSet<BalancingStarSystem> starsInRange = new HashSet<BalancingStarSystem>();
            SortedDictionary<double,BalancingStarSystem> visitableStars = new SortedDictionary<double,BalancingStarSystem>();

            start.PlayerDistance.Add(player, 0.0);
            visitableStars.Add(0.0, start);
            starsInRange.Add(start);

            while (visitableStars.Count > 0)
            {
                KeyValuePair<double, BalancingStarSystem> pair = visitableStars.First();
                visitableStars.Remove(pair.Key);
                //Trace.WriteLine("Visiting distance: " + pair.Key);
                HashSet<StarSystem> connectedStars = pair.Value.attachedStarSystem.destinations;

                foreach(StarSystem star in connectedStars){
                    BalancingStarSystem bstar = StarCorrespondence[star];
                    double distance = star.directDistanceTable[start.attachedStarSystem];
                    //If the target system is too far ignore it.
                    //If the the system has already been added ignore it.
                    //If there is a wormhole between the two ignore this connection.
                    if (distance < maxDistance
                        && !starsInRange.Contains(bstar)
                        && !wormhole(star, pair.Value.attachedStarSystem))
                    {
                        bstar.PlayerDistance.Add(player, distance);
                        visitableStars.Add(distance, bstar);
                        starsInRange.Add(bstar);
                    }
                }
            }

            return starsInRange;
        }