示例#1
0
        private StarSystemBuilder generateSystem(StarNamer namer, Vector2D position, Random rng, SystemEvaluator evaluator, double startingScore, double potentialScore, bool isHomeSystem)
        {
            var starType = isHomeSystem ? this.homeStarType : starTypes[rng.Next(starTypes.Length)];
            var starName = namer.NextName();

            var fixedParts = new StarSystemBuilder(
                starType.Hue,
                (float)Methods.Lerp(rng.NextDouble(), starType.MinScale, starType.Maxscale),
                starName, position,
                new List <StarTraitType>(starType.Traits.Select(x => this.starTraits[x]))
                );
            var usedPositions = new HashSet <int>();

            if (isHomeSystem)
            {
                fixedParts.AddPlanet(this.homeworldPosition, PlanetType.Rock, this.homeworldSize, this.homeworldTraits.Select(x => this.planetTraits[x]));
                usedPositions.Add(this.homeworldPosition);
            }

            var systems = new List <StarSystemBuilder>();

            for (int i = 0; i < SysGenRepeats; i++)
            {
                var system = new StarSystemBuilder(fixedParts);
                systems.Add(system);
                var planets      = rng.Next(5);
                var bodyPosition = 1;
                for (int p = 0; p < planets; p++)
                {
                    var type = bodyTypes()[rng.Next(3)];
                    var size = Math.Round(Methods.Lerp(rng.NextDouble(), 50, 200));
                    while (usedPositions.Contains(bodyPosition))
                    {
                        bodyPosition++;
                    }

                    system.AddPlanet(bodyPosition, type, size, randomTraits(rng, type, size));
                    bodyPosition++;
                }
            }

            return(Methods.FindWorst(systems, x => Methods.MeanSquareError(
                                         evaluator.StartingScore(x) - startingScore,
                                         evaluator.PotentialScore(x) - potentialScore
                                         )));
        }
        public IEnumerable <StarSystem> Generate(Random rng, StarPositions starPositions, IEnumerable <BodyTraitType> planetTraits)
        {
            int colorI = 0;
            var namer  = new StarNamer(starPositions.Stars.Length);

            //UNDONE(later): Picks star types cyclicaly
            //TODO(later): Randomize star type distribution
            //TODO(later): Star size and radiation distribution
            foreach (var position in starPositions.Stars)
            {
                var star = new StarData(starTypes[colorI++ % starTypes.Length].Hue, 1, namer.NextName(), position, new List <BodyTraitType>());

                yield return(new StarSystem(
                                 star,
                                 new Planet[] {
                    new Planet(star, 1, PlanetType.Rock, 100, planetTraits.Take(1).ToList()),
                    new Planet(star, 2, PlanetType.Asteriod, 100, new List <BodyTraitType>()),
                    new Planet(star, 3, PlanetType.GasGiant, 100, new List <BodyTraitType>()),
                }));
            }
        }