public void SpawnNewCreature() { SpawnNewCreature(Rand.Range(new Vector2(settings.envSize))); }
public void SpawnNewFood() { SpawnNewFood(Rand.Range(new Vector2(settings.envSize))); }
public void Reproduce(Creature other) { // Adjust creatures stats childrenCount += 1; other.childrenCount += 1; // Resets the reproduction timer reproductionTimer = 8; // Takes appropriate amount of energy from both creature energy -= sim.settings.maxEnergy / 4; other.energy -= sim.settings.maxEnergy / 4; // Generates a new network, crossing over the two creatures' networks NeuralNet newNetwork = new NeuralNet(network, other.network, mutationRate); // Gets a new colour, halfway between the two colours Color newColor = Color.Lerp(color, other.color, 0.5f); int newGeneration = Math.Max(generation, other.generation) + 1; // Combines the two's names int firstEnd = Math.Max(0, Math.Min(name.Length, name.Length / 2 + Rand.Range(-1, 1))); string firstHalf = name.Substring(0, firstEnd); int secondStart = Math.Max(0, Math.Min(other.name.Length, other.name.Length / 2 + Rand.Range(-1, 1))); string secondHalf = other.name.Substring(secondStart, other.name.Length - secondStart); string newName = firstHalf + secondHalf; // Creates the child and adds it to simulation Creature newCreature = new Creature(position, newName, sim, newColor, newNetwork, newGeneration); sim.creatures.Add(newCreature); parent.AddComponent(newCreature); }