Пример #1
0
        public Planet(LehmerPRNG lehmer, double distanceFromStar)
        {
            this.lehmer      = lehmer;
            DistanceFromStar = distanceFromStar;
            HasRings         = lehmer.NextBool(RING_CHANCE);
            var candidates = planetTypes.Where(pt => pt.MaxDistance >= distanceFromStar && pt.MinDistance <= distanceFromStar);
            var planetType = lehmer.NextChoice(candidates);

            Type   = planetType.Type;
            Radius = lehmer.NextDouble(planetType.MinRadius, planetType.MaxRadius);

            var hasMoons = lehmer.NextBool(MOON_CHANCE);

            if (!hasMoons)
            {
                return;
            }

            Moons = new List <Moon>();
            var numMoons = lehmer.NextInt(1, 4);

            var currentDisanceInPU = lehmer.NextDouble(0.5, 4);

            for (int i = 0; i < numMoons; i++)
            {
                Moons.Add(new Moon(lehmer, currentDisanceInPU, Radius));
                currentDisanceInPU += lehmer.NextDouble(0.5, 1.5) * (i + 1) * 0.5;
            }
        }
Пример #2
0
        public Star(LehmerPRNG lehmer)
        {
            this.lehmer = lehmer;

            this.Name = GenerateName();

            var type = lehmer.NextChoice(starTypes, starTypes.Select(st => st.Prevalence));

            this.TypeOfStar = type.Type;
            this.Radius     = lehmer.NextDouble(type.MinRadius, type.MaxRadius);

            var hasPlanets = lehmer.NextBool(CHANCE_OF_PLANETS);

            if (!hasPlanets)
            {
                return;
            }
            Planets = new List <Planet>();
            var numPlanets = lehmer.NextInt(1, 10);

            var currentDisanceInAU = lehmer.NextDouble(0.5, 4);

            for (int i = 0; i < numPlanets; i++)
            {
                Planets.Add(new Planet(lehmer, currentDisanceInAU));
                currentDisanceInAU += lehmer.NextDouble(0.5, 1.5) * (i + 1) * 0.5;
            }
        }
Пример #3
0
        private string GenerateName()
        {
            StringBuilder sb          = new StringBuilder();
            int           length      = lehmer.NextInt(3, 11);
            bool          isConsonant = lehmer.NextBool();

            for (int i = 0; i < length; i++)
            {
                sb.Append(isConsonant ? NextConsonant() : NextVowel());
                isConsonant = !isConsonant;
            }
            return(CultureInfo.InvariantCulture.TextInfo.ToTitleCase(sb.ToString()));
        }
Пример #4
0
        public Zone(UPoint at)
        {
            this.at = at;
            // The seed is generated by combining the lowest 2 bytes of x and y into 1 unit.
            // This means that the universe will repeat every 65536 x and y b
            lehmer = new LehmerPRNG((at.X & 0xFFFF) << 16 | (at.Y & 0xFFFF));

            var isStar = lehmer.NextBool(CHANCE_OF_STAR);

            if (!isStar)
            {
                return;
            }

            this.Star = new Star(lehmer);
        }