Beispiel #1
0
        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);
        }
Beispiel #2
0
 private void Reproduce()
 {
     if (age < 2)
     {
         return;
     }
     if (brain.GetOutput(NEURONOUTreproduce) > 0)
     {
         UseRelativeEnergy(ENERGYCOSTREPRODUCTION);
         if (energy > 0f)//MINIMUMREPRODUCEENERGY
         {
             double energyToUseForOffspring = brain.GetPositiveOutput(NEURONOUTenergyToOffspring) * energy;
             double mutationStrength        = brain.GetPositiveOutput(NEURONOUTmutationStrength) * MAXMUTATIONSTRENGTH;
             double mutationStrengthAngle   = brain.GetPositiveOutput(NEURONOUTmutationStrengthAngle) * MAXMUTATIONANGLESTRENGTH;
             int    numMutations            = (int)Math.Ceiling(brain.GetPositiveOutput(NEURONOUTmutationCount) * MAXMUTATIONCOUNT);
             Animal offspring = new Animal(this, UseAbsoluteEnergy(energyToUseForOffspring) / 2, animalManager);
             offspring.brain.Mutate(MAXMUTATIONCOUNT, Math.Exp(mutationStrength), mutationStrengthAngle);
             animalManager.SpawnAnimal(offspring);
             children.AddLast(offspring);
         }
     }
 }