Ejemplo n.º 1
0
 public double GetMetalFromPlanets()
 {
     return(Planets.Count() * GlobalConst.PlanetMetalPerTurn);
 }
Ejemplo n.º 2
0
        public List <string> GetWarnings()
        {
            var warnings           = new List <string>();
            var planetIDs          = Planets.Select(p => p.ID).ToHashSet();
            var playerNames        = Players.Select(p => p.Name).ToHashSet();
            var factionNames       = Factions.Select(f => f.Name).ToHashSet();
            var playerFactionNames = Factions.Select(p => p.Name).ToHashSet();
            var ownerNames         = Planets.Select(p => p.OwnerName).Where(n => n != null).ToHashSet();

            if (!ownerNames.IsSubsetOf(playerNames))
            {
                warnings.Add("Planet owner does not exist.");
            }
            if (!playerFactionNames.IsSubsetOf(factionNames))
            {
                warnings.Add("Player faction does not exist.");
            }
            if (planetIDs.Count != Planets.Count)
            {
                warnings.Add("Duplicate planet ID.");
            }
            if (playerNames.Count != Players.Count)
            {
                warnings.Add("Duplicate player name.");
            }
            if (factionNames.Count != Factions.Count)
            {
                warnings.Add("Duplicate faction.");
            }
            {
                var link = Links.FirstOrDefault(l => l[0] == l[1]);
                if (link != null)
                {
                    warnings.Add(String.Format("Link has same source and destination: {0} {1}", link[0], link[1]));
                }
            }
            foreach (var link in Links)
            {
                if (!planetIDs.IsSupersetOf(link.PlanetIDs))
                {
                    warnings.Add("Link points to inexistent planet");
                }
                Array.Sort(link.PlanetIDs);
            }
            foreach (var link1 in Links)
            {
                foreach (var link2 in Links)
                {
                    if (link1 != link2 && link1.PlanetIDs.SequenceEqual(link2.PlanetIDs))
                    {
                        warnings.Add("Duplicate Link");
                    }
                }
            }
            Func <string, Planet, string> format = (s, p) => String.Format("Planet {0} {1} missing.", p.Name ?? String.Empty, s);

            foreach (var p in Planets)
            {
                if (p.OwnerName != null || p.FactionName != null || p.MapName != null)
                {
                    if (p.OwnerName == null)
                    {
                        warnings.Add(p.Name + format("owner", p));
                    }
                    if (p.FactionName == null)
                    {
                        warnings.Add(format("faction", p));
                    }
                    if (p.MapName == null)
                    {
                        warnings.Add(format("map", p));
                    }
                    if (p.Name == null)
                    {
                        warnings.Add(format("name", p));
                    }
                }
            }

            if (Planets.Count(p => p.IsStartingPlanet) != Factions.Count)
            {
                warnings.Add("Wrong number of starting planets.");
            }

            if (Round == 0 && Planets.Any(p => p.OwnerName == null) && !playerNames.All(ownerNames.Contains))
            {
                warnings.Add("Galaxy has free space and a player has no planet.");
            }
            if (Planets.Count > MapNames.Count)
            {
                warnings.Add("Not enough maps.");
            }

            if (Factions.Count < 2)
            {
                warnings.Add("Not enough factions.");
            }
            return(warnings);
        }