protected override void OnUpdate() { Entities.ForEach((Bibit bibit) => { if (!bibit.isDead) { //energyupdate and generationupdate bibit.energy -= Time.deltaTime * bibit.ageModifier; BibitProducer.updateMaxGeneration(bibit.generation, bibit); //Kill if energy<100 if (bibit.energy < 100) { BibitProducer.removeBibit(bibit.gameObject); bibit.isDead = true; } else { //birth: float birthWish = (float)bibit.outBirth.getValue(); if (birthWish > 0) { if (bibit.energy > Bibit.STARTENERGY + Bibit.MINIMUMSURVIVALENERGY * bibit.birthCost * 1.15f) { bibitsToSpawn.Add(bibit.gameObject); if (bibit.isOnPoison) { bibit.energy -= Bibit.STARTENERGY * bibit.birthCost; } else { bibit.energy -= Bibit.STARTENERGY * bibit.birthCost * bibit.poisonModifier; } } } } } bibit.ageModifier = (float)(-(3 / math.pow(math.E, 0.1 * bibit.age - 10) + 1) + 3); bibit.ageModifier = math.clamp(bibit.ageModifier, 0.001f, 200); bibit.age += Time.deltaTime; }); //spawnChildren: foreach (GameObject mother in bibitsToSpawn) { BibitProducer.spawnChild(mother); } bibitsToSpawn.Clear(); }
public void pseudoConstructor2(Bibit mother) { transform.position = mother.transform.position; brain = mother.brain.cloneFullMesh(); energy = 150; displayName = mother.displayName; generation = mother.getGeneration() + 1; inBias = brain.getInputNeuronFromName(NAME_IN_BIAS); inEnergy = brain.getInputNeuronFromName(NAME_IN_ENERGY); inAge = brain.getInputNeuronFromName(NAME_IN_AGE); inMemory = brain.getInputNeuronFromName(NAME_IN_MEMORY); inDistToNearestPoison = brain.getInputNeuronFromName(NAME_IN_DISTTONEARESTPOISON); inAngleToNearestPoison = brain.getInputNeuronFromName(NAME_IN_ANGLETONEARESTPOISON); inFoodAmountAtCurrentBlock = brain.getInputNeuronFromName(NAME_IN_FOODAMOUNTATCURRENTBLOCK); inFoodAmountInSightRadius = brain.getInputNeuronFromName(NAME_IN_FOODAMOUNTINSIGHTRADIUS); inDistToMaxFoodBlockAround = brain.getInputNeuronFromName(NAME_IN_DISTTOMAXFOODBLOCKAROUND); inAngleToMaxFoodBlockAround = brain.getInputNeuronFromName(NAME_IN_ANGLETOMAXFOODBLOCKAROUND); inFoodAmountOfMaxFoodBlockAround = brain.getInputNeuronFromName(NAME_IN_FOODAMOUNTOFMAXFOODBLOCKAROUND); inNumberOfBibitsNear = brain.getInputNeuronFromName(NAME_IN_NUMBEROFBIBITSNEAR); inDistToNearestBibit = brain.getInputNeuronFromName(NAME_IN_DISTTONEARESTBIBIT); inAngleToNearestBibit = brain.getInputNeuronFromName(NAME_IN_ANGLETONEARESTBIBIT); inGeneticDifferenceToNearestBibit = brain.getInputNeuronFromName(NAME_IN_GENETICDIFFERENCETONEARESTBIBIT); inCenterPosition = brain.getInputNeuronFromName(NAME_IN_CENTERPOSITION); outBirth = brain.getOutputNeuronFromName(NAME_OUT_BIRTH); outRotate = brain.getOutputNeuronFromName(NAME_OUT_ROTATE); outForward = brain.getOutputNeuronFromName(NAME_OUT_FORWARD); outEat = brain.getOutputNeuronFromName(NAME_OUT_EAT); outMemory = brain.getOutputNeuronFromName(NAME_OUT_MEMORY); outAttack = brain.getOutputNeuronFromName(NAME_OUT_ATTACK); BibitProducer.updateGeneration(generation); // CalculateFeelerPos(); for (int i = 0; i < 10; i++) { brain.RandomMutation(0.2f); } float r = mother.color.r; float g = mother.color.g; float b = mother.color.b; r += Random.value * 0.1f - 0.05f; g += Random.value * 0.1f - 0.05f; b += Random.value * 0.1f - 0.05f; r = math.clamp(r, 0, 1); g = math.clamp(g, 0, 1); b = math.clamp(b, 0, 1); color = new Color(r, g, b); // writeStuff(mother, brain); }