public void Serialize(int n = 1) { foreach (Cat cat in cats.OrderByDescending(c => c.GetFitness()).Take(n)) { DNASerializer.ToFile <G>(cat.GetDNA <G>(), $"gen{id}_cat{cat.id}_fit{cat.GetFitness()}"); } }
// Start is called before the first frame update void Start() { if (catFile != "") { Debug.Log($"Loading cat {catFile}"); DNA <BasicGene> dna = DNASerializer.FromFile <BasicGene>(catFile); GetComponent <Cat>().Init <BasicGene, BasicStrategyContinuous>(dna); } else { Debug.Log("Generating random cat"); GetComponent <Cat>().Init <BasicGene, BasicStrategyContinuous>(simulationConfig.config); } }
public SimulationEngine(Func <Action, Task> invokeEvent = null) { cyclePerSecondTimer = new Timer(CyclePerSecondTick, null, -1, 1000); Field.Size = new Vector2(1000, 1000); for (var i = 0; i < InitialRobotCount; i++) { var bot = new Bot(invokeEvent) { Position = new Vector2((float)random.NextDouble() * Field.Size.X, (float)random.NextDouble() * Field.Size.Y), Speed = new Vector2(0, 0), DNA = DNASerializer.DeserializeDNA("test-dna.txt"), Orientation = (float)(random.NextDouble() * Math.PI * 2), Color = Color.Red }; botsToAdvertise.Add(bot); Bots.Add(bot); } for (var i = 0; i < InitialRobotCount; i++) { var bot = new Bot(invokeEvent) { Position = new Vector2( (float)random.NextDouble() * Field.Size.X, (float)random.NextDouble() * Field.Size.Y), Speed = new Vector2(0, 0), DNA = DNASerializer.DeserializeDNA("test-dna-2.txt"), Orientation = (float)(random.NextDouble() * Math.PI * 2), Color = Color.Green, IsFixed = true }; botsToAdvertise.Add(bot); Bots.Add(bot); } }