public override AbstractPhenotype Translate(BitVector genom) { var battles = new List<double>(); for (int i = 0; i < genom.Vector.Count; i = i + 4) { string binaryStrength = genom.Vector[i].ToString() + genom.Vector[i + 1].ToString() + genom.Vector[i + 2].ToString() + genom.Vector[i + 3].ToString(); var armyStrength = (double) Convert.ToInt32(binaryStrength, 2); battles.Add(armyStrength); } double sum = battles.Sum(); List<double> army = battles.Select(battleStrength => (battleStrength/sum)).ToList(); var cbp = new ColonelBlottoPhenotype {Genotype = genom, Army = army, Strength = 1.0, Wins = 0, Ties = 0}; cbp.CalculateEntropy(); return cbp; }
public void War(ColonelBlottoPhenotype army1, ColonelBlottoPhenotype army2) { for (int i = 0; i < army1.Army.Count; i++) { if ((army1.Army[i]*army1.Strength) > (army2.Army[i]*army2.Strength)) { army1.Wins++; army1.Redeployment(i, (army1.Army[i] - army2.Army[i]), RedeploymentFraction); army2.Strength -= LossFraction; } else if ((army2.Army[i]*army2.Strength) > (army1.Army[i]*army1.Strength)) { army2.Wins++; army2.Redeployment(i, (army2.Army[i] - army1.Army[i]), RedeploymentFraction); army1.Strength -= LossFraction; } else { army1.Ties++; army2.Ties++; } } army1.Strength = 1.0; army2.Strength = 1.0; }
public void GetWinner() { double max = Population.CurrentPopulation.Cast<ColonelBlottoPhenotype>().Max(x => x.Fitness); Winner = Population.CurrentPopulation.Cast<ColonelBlottoPhenotype>().FirstOrDefault(x => x.Fitness >= max); }