public NewGameController(IEnumerable <TracableStream> staticDataSources) { foreach (var aiFactory in PlayerAssets.AIDefinitions.Values) { aiPlayers.Add(new PlayerType(PlayerControlType.LocalAI, aiFactory)); } //TODO(v0.8) move to controller user players.Add(new NewGamePlayerInfo("Marko Kovač", colors.Take(), null, localHuman)); players.Add(new NewGamePlayerInfo(generateAiName(), colors.Take(), null, aiPlayers.Pick())); this.Statics = StaticsDB.Load(staticDataSources); this.evaluator = new SystemEvaluator(this.Statics); foreach (var populator in MapAssets.StarPopulators) { populator.SetGameData( this.Statics.StarTraits, this.Statics.PlanetTraits, this.Statics.PlanetForumlas.ToDictionary(x => x.Key, x => x.Value.ImplicitTraits) ); } this.CustomStart = LastStartingCondition ?? DefaultStartingCondition; this.StarPositioner = ParameterLoadingVisitor.Load(Settings.Get.LastGame.StarPositionerConfig, MapAssets.StarPositioners); this.StarConnector = ParameterLoadingVisitor.Load(Settings.Get.LastGame.StarConnectorConfig, MapAssets.StarConnectors); this.StarPopulator = ParameterLoadingVisitor.Load(Settings.Get.LastGame.StarPopulatorConfig, MapAssets.StarPopulators); }
public NewGameController(IEnumerable <NamedStream> staticDataSources) { foreach (var aiFactory in PlayerAssets.AIDefinitions.Values) { aiPlayers.Add(new PlayerType(PlayerControlType.LocalAI, aiFactory)); } //TODO(v0.9) move to controller user this.players.AddRange( Settings.Get.LastGame.PlayersConfig != null && Settings.Get.LastGame.PlayersConfig.Length > 1 ? loadPlayerSetup(Settings.Get.LastGame.PlayersConfig) : this.defaultPlayerSetup() ); this.Statics = StaticsDB.Load(staticDataSources); this.evaluator = new SystemEvaluator(this.Statics); foreach (var populator in MapAssets.StarPopulators) { populator.SetGameData( this.Statics.StarTraits, this.Statics.PlanetTraits, this.Statics.PlanetForumlas.ToDictionary(x => x.Key, x => x.Value.ImplicitTraits) ); } this.CustomStart = LastStartingCondition ?? DefaultStartingCondition; this.StarPositioner = ParameterLoadingVisitor.Load(Settings.Get.LastGame.StarPositionerConfig, MapAssets.StarPositioners); this.StarConnector = ParameterLoadingVisitor.Load(Settings.Get.LastGame.StarConnectorConfig, MapAssets.StarConnectors); this.StarPopulator = ParameterLoadingVisitor.Load(Settings.Get.LastGame.StarPopulatorConfig, MapAssets.StarPopulators); }
public IEnumerable <StarSystemBuilder> Generate(Random rng, SystemEvaluator evaluator, StarPositions starPositions) { var namer = new StarNamer(starPositions.Stars.Count, new Random()); var uninhabitedStars = starPositions.Stars.Where((x, i) => !starPositions.HomeSystems.Contains(i)); var homeStars = new HashSet <Vector2D>(starPositions.HomeSystems.Select(i => starPositions.Stars[i])); var potentials = new Dictionary <Vector2D, double>(); var starts = new Dictionary <Vector2D, double>(); var climate = this.climateLevels[this.climateParameter.Value]; var potential = this.potentialLevels[this.potentialParameter.Value]; foreach (var home in homeStars) { potentials[home] = potential.HomesystemPotentialScore; starts[home] = Math.Min(climate.HomesystemStartScore, potentials[home]); } var undistributed = new HashSet <Vector2D>(uninhabitedStars); var weightSum = potential.Ranges.Sum(x => x.Weight); foreach (var range in potential.Ranges) { var count = (int)Math.Round(range.Weight * undistributed.Count() / weightSum); foreach (var star in spreadPoints(rng, undistributed, count)) { potentials[star] = Methods.Lerp(rng.NextDouble(), range.Min, range.Max); undistributed.Remove(star); } weightSum -= range.Weight; } undistributed = new HashSet <Vector2D>(uninhabitedStars); weightSum = climate.Ranges.Sum(x => x.Weight); foreach (var range in climate.Ranges) { var undistributedCandidates = new HashSet <Vector2D>(undistributed.Where(x => potentials[x] >= range.Min)); var count = Math.Min( (int)Math.Round(range.Weight * undistributed.Count / weightSum), undistributedCandidates.Count ); foreach (var star in spreadPoints(rng, undistributedCandidates, count)) { starts[star] = Methods.Lerp(rng.NextDouble(), range.Min, range.Max); undistributed.Remove(star); } weightSum -= range.Weight; } //TODO(v0.8): Star size and trait distribution foreach (var position in starPositions.Stars) { yield return(generateSystem(namer, position, rng, evaluator, starts[position], potentials[position], homeStars.Contains(position))); } }
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 ))); }
internal MapPreview(IEnumerable <StarSystemBuilder> systems, HashSet <StarData> homewolrds, IEnumerable <Wormhole> starlanes, SystemEvaluator evaluator) { this.Systems = systems.Select(x => new SystemPreview( x.Star, homewolrds.Contains(x.Star), evaluator.StartingScore(x.Star, x.Planets), evaluator.PotentialScore(x.Star, x.Planets) )).ToList(); this.Starlanes = starlanes.Select(x => new WormholeInfo(x)).ToList(); }