-
-
Notifications
You must be signed in to change notification settings - Fork 588
Expand file tree
/
Copy pathCalculatePopulation.cs
More file actions
65 lines (52 loc) · 2.08 KB
/
CalculatePopulation.cs
File metadata and controls
65 lines (52 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
namespace AutoEvo;
using System.Collections.Generic;
using Xoshiro.PRNG64;
/// <summary>
/// Step that calculates the populations for all species
/// </summary>
public class CalculatePopulation : IRunStep
{
private readonly IAutoEvoConfiguration configuration;
private readonly PatchMap map;
private readonly WorldGenerationSettings worldSettings;
private readonly Dictionary<Species, Species>? replaceSpecies;
private readonly bool collectEnergyInfo;
public CalculatePopulation(IAutoEvoConfiguration configuration, WorldGenerationSettings worldSettings,
PatchMap map, Dictionary<Species, Species>? replaceSpecies = null, bool collectEnergyInfo = false)
{
this.configuration = configuration;
this.worldSettings = worldSettings;
this.map = map;
this.replaceSpecies = replaceSpecies;
this.collectEnergyInfo = collectEnergyInfo;
}
public int TotalSteps => 1;
public bool CanRunConcurrently => false;
/// <summary>
/// Used to overwrite <see cref="SimulationConfiguration.EnsurePatchesHaveSpecies"/> for the population
/// calculation run.
/// </summary>
public Dictionary<Patch, Species>? EnsurePatchesHaveSpecies { get; set; }
public bool RunStep(RunResults results, SimulationCache cache)
{
// ReSharper disable RedundantArgumentDefaultValue
var config = new SimulationConfiguration(configuration, map, worldSettings)
{
Results = results,
CollectEnergyInformation = collectEnergyInfo,
EnsurePatchesHaveSpecies = EnsurePatchesHaveSpecies,
};
// ReSharper restore RedundantArgumentDefaultValue
if (replaceSpecies != null)
{
foreach (var entry in replaceSpecies)
{
config.ReplacedSpecies.Add(entry.Key, entry.Value);
}
}
// Directly feed the population results to the main results object
// TODO: allow passing in a random seed
MichePopulation.Simulate(config, cache, new XoShiRo256starstar());
return true;
}
}