public static Animal ReadWithBrain(BinaryReader reader, AnimalManager manager, String path) { Animal animal = ReadWithoutBrain(reader, manager); animal.ReadBrain(path); return(animal); }
public Animal(Animal mother, double startEnergy, AnimalManager animalManager) { brain = new NeuralNetwork(mother.brain); this.pos = mother.pos; this.color = MutateColor(mother.color); this.rotation = mother.rotation + (float)Simulation.NextRandomDouble() * 4 - 2f; energy = startEnergy; this.animalManager = animalManager; this.Id = animalManager.GetNextId(); this.Generation = mother.Generation + 1; this.ParentId = mother.Id; }
public Animal(Vector2 pos, AnimalManager animalManager) { brain = new NeuralNetwork(new int[] { NUMNEURONIN + feelerPos.Length * NUMNEURONINPERFEELER + NUMNEURONMEMORY, 20, NUMNEURONOUT + NUMNEURONMEMORY }); this.pos = pos; this.color = new Color((float)Simulation.NextRandomDouble(), (float)Simulation.NextRandomDouble(), (float)Simulation.NextRandomDouble()); this.rotation = (float)(Simulation.NextRandomDouble() * Math.PI * 2); energy = INITIALENERGY; this.animalManager = animalManager; this.Id = animalManager.GetNextId(); this.Generation = 0; this.ParentId = AnimalManager.IDNONE; }
public void SaveTick(AnimalManager manager) { foodAvailableCounts.AddLast(manager.Map.CountAvailableFood()); while (foodAvailableCounts.Count > MAXTICKSTATISTICSSAVED) { foodAvailableCounts.RemoveFirst(); } animalsAliveCounts.AddLast(manager.AnimalCount); while (animalsAliveCounts.Count > MAXTICKSTATISTICSSAVED) { animalsAliveCounts.RemoveFirst(); } if (manager.AnimalCount > 0) { Animal oldestAnimal = manager.Animals.MaxObject(delegate(Animal a, Animal b) { return(a.Age > b.Age ? a : b); }); if (!oldestAnimals.Contains(oldestAnimal)) { oldestAnimals.AddLast(oldestAnimal); } Animal energyRichestAnimal = manager.Animals.MaxObject(delegate(Animal a, Animal b) { return(a.Energy > b.Energy ? a : b); }); if (!energyRichestAnimals.Contains(energyRichestAnimal)) { energyRichestAnimals.AddLast(energyRichestAnimal); } Animal mostConsumingAnimal = manager.Animals.MaxObject(delegate(Animal a, Animal b) { return(a.EnergyConsumed > b.EnergyConsumed ? a : b); }); if (!mostConsumingAnimals.Contains(mostConsumingAnimal)) { mostConsumingAnimals.AddLast(mostConsumingAnimal); } Animal mostOffspringAnimal = manager.Animals.MaxObject(delegate(Animal a, Animal b) { return(a.NumDirectOffspring > b.NumDirectOffspring ? a : b); }); if (!mostOffspringAnimals.Contains(mostOffspringAnimal)) { mostOffspringAnimals.AddLast(mostOffspringAnimal); } } while (oldestAnimals.Count > MAXBESTANIMALSTATISTICSSAVED) { oldestAnimals.RemoveFirst(); } while (energyRichestAnimals.Count > MAXBESTANIMALSTATISTICSSAVED) { energyRichestAnimals.RemoveFirst(); } while (mostConsumingAnimals.Count > MAXBESTANIMALSTATISTICSSAVED) { mostConsumingAnimals.RemoveFirst(); } while (mostOffspringAnimals.Count > MAXBESTANIMALSTATISTICSSAVED) { mostOffspringAnimals.RemoveFirst(); } }
public static Animal ReadWithoutBrain(BinaryReader reader, AnimalManager manager) { long id = reader.ReadInt64(); Vector2 pos = reader.ReadVector2(); Color color = reader.ReadColor(); float rotation = reader.ReadSingle(); double energy = reader.ReadDouble(); int generation = reader.ReadInt32(); long age = reader.ReadInt64(); double energyConsumed = reader.ReadDouble(); long parentId = reader.ReadInt64(); LinkedList <long> children = reader.ReadLinkedList(delegate() { return(reader.ReadInt64()); }); return(new Animal(pos, manager, color, rotation, energy, generation, age, energyConsumed, id, children, parentId)); }
private Animal(Vector2 pos, AnimalManager animalManager, Color color, float rotation, double energy, int generation, long age, double energyConsumed, long id, LinkedList <long> children, long parentId, NeuralNetwork brain = null) { this.brain = brain; this.pos = pos; this.color = color; this.rotation = rotation; this.energy = energy; this.animalManager = animalManager; this.Generation = generation; this.age = age; this.energyConsumed = energyConsumed; this.Id = id; this.childrenIdOnly = children; this.ParentId = parentId; }
protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); Animal.LoadTexture(Content); statisticsGUI = new StatisticsGUI(this); camera = new Camera(); try{ map = Map.Deserialize(savePath, this, camera, statisticsGUI); }catch (Exception e) { map = new Map(this, camera, statisticsGUI); } try{ animalManager = AnimalManager.Read(savePath, map, delegate(Animal animal) { }); } catch (Exception e) { animalManager = new AnimalManager(map, delegate(Animal animal) { }); } // TODO: use this.Content to load your game content here }
public static AnimalManager Read(String path, Map map, Action <Animal> animalSaver) { LinkedList <Animal> animals = new LinkedList <Animal>(); AnimalManager manager = new AnimalManager(map, animalSaver); FileStream file = File.Open(path + "/manager.aemanager", FileMode.Open); BinaryReader reader = new BinaryReader(file); //Read Start manager.highestId = reader.ReadInt64(); int animalCount = reader.ReadInt32(); for (int i = 0; i < animalCount; i++) { manager.SpawnAnimal(Animal.ReadWithBrain(reader, manager, path)); } //Read End file.Close(); manager.LinkChildren(); return(manager); }