Beispiel #1
0
 public ReproductionSystem(EntityManager pool, NeatMutationConfig config, InnovationIdManager innovationIdManager, EnergyManager energyManager, int currentMaxSpeciesId, float similarityThreshold, Simulation simulation)
     : base(pool, (e) => e.HasComponents(typeof(ReproductionComponent), typeof(EnergyComponent)))
 {
     _muationManager       = new MutationManager(config);
     _innovationIdManager  = innovationIdManager;
     _energyManager        = energyManager;
     _nextSpeciesIdCounter = currentMaxSpeciesId + 1;
     _similarityThreshold  = similarityThreshold;
     _simulation           = simulation;
 }
Beispiel #2
0
 /// <summary>
 /// Mutates the given genotype with the assigned mutators.
 /// Mutators each have an assigned probability of activating (ProbabiltiyOfMutation). The list of mutators is read from the lowest index up until the highest.
 /// If a mutator activates, then no more mutators can be activated and the mutattion finishes.
 /// A mutator with a ProbabiltiyOfMutation will always activate if we reach it in the list.
 /// </summary>
 /// <param name="genotype">Genotype to mutate</param>
 /// <param name="innovationIdManager">Innovation id manager. New innovation ids will be taken from here.</param>
 public void Mutate(NeatBrainGenotype genotype, InnovationIdManager innovationIdManager)
 {
     foreach (AbstractMutator mutator in Mutators)
     {
         if (Random.NextDouble() < mutator.ProbabiltiyOfMutation)
         {
             mutator.Mutate(genotype, Random, innovationIdManager);
         }
     }
 }
        protected override void Initialize()
        {
            _grid = new AdjacencyGrid(_settings.WorldWidth, _settings.WorldHeight, 25);

            _renderSystem             = new RenderSystem(EntityManager, this);
            _transformHierarchySystem = new TransformHierarchySystem(EntityManager, _grid);
            _velocitySystem           = new VelocitySystem(EntityManager);

            // Declare rigidbody collision system
            _rigidbodyCollisionSystem = new SortAndSweep(EntityManager,
                                                         (e) => e.HasComponents(typeof(CircleColliderComponent), typeof(RigidBodyComponent)),
                                                         (e1, e2) => true); // All collisions should be resolved

            _mouthCollisionSystem = new SortAndSweep(EntityManager,
                                                     (e) => e.HasComponents(typeof(CircleColliderComponent)) &&
                                                     (e.HasComponents(typeof(MouthComponent)) || e.HasComponents(typeof(EdibleComponent))),
                                                     // Only resolve if 1 has a food and the other a mouth (but not both)
                                                     (e1, e2) =>
                                                     (e1.HasComponent <MouthComponent>() && e2.HasComponent <EdibleComponent>())
                                                     ^ (e2.HasComponent <MouthComponent>() && e1.HasComponent <EdibleComponent>())
                                                     );

            _weaponHealthCollisionSystem = new SortAndSweep(EntityManager,
                                                            (e) => e.HasComponents(typeof(CircleColliderComponent)) &&
                                                            (e.HasComponent <HealthComponent>() || e.HasComponent <WeaponComponent>()),
                                                            // Only resolve if 1 is a weapon and the other a health
                                                            (e1, e2) =>
                                                            (e1.HasComponent <HealthComponent>() && e2.HasComponent <WeaponComponent>())
                                                            ^ (e2.HasComponent <HealthComponent>() && e1.HasComponent <WeaponComponent>())
                                                            );

            _rigidBodySystem       = new RigidBodySystem(EntityManager);
            _dragSystem            = new DragSystem(EntityManager, _settings.MassDensity);
            _movementControlSystem = new MovementControlSystem(EntityManager);
            _brainSystem           = new BrainSystem(EntityManager, Settings);
            WorldBorderSystem      = new WorldBorderSystem(EntityManager, _worldWidth, _worldHeight);
            _visionSystem          = new VisionSystem(EntityManager, _grid);

            // These systems take a reference to a list of collisions. This means that should collision code checking change, the objects do not.
            RigidbodyCollisionSystem = new RigidBodyCollisionSystem(_rigidbodyCollisionSystem.Collisions);
            MouthFoodCollisionSystem = new MouthFoodCollisionSystem(EntityManager, _mouthCollisionSystem.Collisions);
            InfoRenderSystem         = new InfoRenderSystem(EntityManager, this);
            _noseSystem = new NoseSystem(EntityManager, _grid);

            // Global energy manager. This Ensures a closed system so there is a fixed amount of enegry in the simulation
            _energyManager = new EnergyManager(_settings.InitialWorldEnergy);

            // These are systems that take into account energy and need the energy manager system

            EnergyDeathSystem = new EnergyDeathSystem(EntityManager);
            HealthDeathSystem = new HealthDeathSystem(EntityManager, this, _energyManager);
            OldAgeDeathSystem = new OldAgeDeathSystem(EntityManager, this, _energyManager, _settings.OldAgeEnabled, _settings.OldAgeMultiplier);

            WeaponSystem = new WeaponSystem(EntityManager, _weaponHealthCollisionSystem.Collisions, _energyManager);
            _movementControlEnergyCostSystem = new MovementControlEnergyCostSystem(EntityManager, _energyManager);

            InnovationIdManager innovationIdManager = new InnovationIdManager(100, 100);

            // So textures are constantly refreshed
            _renderSystem.EditorMode = true;
        }