internal static double Evaluate(RicochetIndividual individual) { var xOlds = new List <int>(); var yOlds = new List <int>(); bool end = false; var listRem = new List <GeneRicochet>(); foreach (GeneRicochet g in individual.genome) { if (!end) { xOlds.Add(g.Pawn.X); yOlds.Add(g.Pawn.Y); Board.MovePawn(g.Direction, (PawnModel)g.Pawn); end = g.Pawn.X == Board.Target.X && g.Pawn.Y == Board.Target.Y; } else { listRem.Add(g); } } foreach (var g in listRem) { individual.genome.Remove(g); } int distance = Math.Abs(Board.Target.X - Board.Target.Pawn.X) + Math.Abs(Board.Target.Y - Board.Target.Pawn.Y); for (var i = individual.genome.Count - 1; i >= 0; i--) { GeneRicochet genome = (GeneRicochet)individual.genome[i]; genome.Pawn.X = xOlds[i]; genome.Pawn.Y = yOlds[i]; } return(distance * 100); }
public GeneRicochet(GeneRicochet g) { Direction = g.Direction; Pawn = (PawnModel)g.Pawn; }