/// <summary> /// Rebuilds the car graphics at the starting position. /// </summary> public void ResetEntity() { ClearEntity(); var definition = Phenotype.ToDefinition(); m_entity = new Entity(definition, m_physicsManager) { Id = Id }; m_physicsManager.PostStep += PhysicsPostStep; // reset the overview line alpha for (var i = 0; i < m_overviewLine.Length; i++) { m_overviewLine[i].Color.A = 255; } HealthChanged = null; Position = StartPosition; m_lastPosition = StartPosition; MaxDistance = 0; MaxDistancePosition = Vector2.Zero; DistanceTraveled = 0; m_health = MaxHealth; Speed = 0; m_losingHealth = false; m_speedSampleDelay = SpeedSampleDelay; }
/// <summary> /// Replace this car by performing a crossover with the two provided /// phenotypes. /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <param name="mutate"> /// If true, perform a mutation after the crossover. /// </param> public void ReplaceWithCrossover(Phenotype a, Phenotype b, bool mutate) { Phenotype = Phenotype.CrossOver(a, b); if (mutate) { Phenotype.Mutate(); } ResetEntity(); }
/// <summary> /// Creates a new car. /// </summary> /// <param name="physicsManager"></param> /// <param name="phenotype"> /// Sets the phenotype of the car. If null, generates a random phenotype. /// </param> public Car(PhysicsManager physicsManager, Phenotype phenotype = null) { if (physicsManager == null) { throw new ArgumentNullException("physicsManager"); } m_physicsManager = physicsManager; if (phenotype != null) { Phenotype = phenotype; ResetEntity(); } else { Generate(); } }
/// <summary> /// Replace this car with a new randomly generated car. /// </summary> public void Generate() { ClearEntity(); Phenotype = new Phenotype(); ResetEntity(); }
/// <summary> /// Generates a new Phenotype by crossing the two parents. /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static Phenotype CrossOver(Phenotype a, Phenotype b) { Debug.Assert(CrossoverStrategy != null); return(new Phenotype(CrossoverStrategy(a.m_genome, b.m_genome))); }