public static float[] getEvolved(IWeapon parent, int efficiencyPercentage) { ArrayList population = getRandomPopulation(parent, 1f); float[] behaviorValues = parent.BehaviorTracker.getNormalizedBehavior(); int maxIndex = 0; for (int i = 1; i < behaviorValues.Length; i++) if (Math.Abs(behaviorValues[i] - 50) > Math.Abs(behaviorValues[maxIndex] - 50)) maxIndex = i; int[] factorArray = getFactorArray(maxIndex); float[] bestIndividual = (float[])population[0]; float bestFitness = -1; foreach (float[] individual in population) { float fitness = fitnessFunction(factorArray, individual); if (fitness > bestFitness) { bestIndividual = individual; bestFitness = fitness; } } return bestIndividual; }
private static ArrayList getRandomPopulation(IWeapon parent, float efficiencyPercentage) { ArrayList population = new ArrayList(); float[] parentCharacteristics = parent.getCharacteristics(); float[] parentWeaponBias = parent.getWeaponBias(); for (int i = 0; i < populationSize; i++) { float[] characteristics = new float[(int)IWeapon.Stats.END]; for (int j = 0; j < (int)IWeapon.Stats.END; j++) { characteristics[j] = parentCharacteristics[j] + (float)random.NextDouble() * parentWeaponBias[j] * efficiencyPercentage; } population.Add(characteristics); } return population; }
public static float[] getRandomIndividual(IWeapon parent, int efficiencyPercentage) { ArrayList population = getRandomPopulation(parent, (efficiencyPercentage / 100f)); return (float[])population[random.Next(population.Count)]; }
public float getCharacteristic(IWeapon.Stats stat) { return characteristics[(int)stat]; }