public List <Garden> nextStep(List <Garden> ancestor, int numberofChildren, int movementMax, GardenEvaluator ge) { List <Tuple <Garden, double> > allDecendants = new List <Tuple <Garden, double> >(); List <Garden> tempGardens = new List <Garden>(); Tuple <Garden, double> tempTuple; double tempScore; for (int i = 0; i < numberofChildren && i < ancestor.Count; i++) { tempGardens.AddRange(makeChildren(ancestor[i], movementMax, numberofChildren)); foreach (Garden child in tempGardens) { tempScore = ge.scoreGarden(child); tempTuple = new Tuple <Garden, double>(child, tempScore); allDecendants.Add(tempTuple); } } tempGardens = new List <Garden>(); //Order by the top scoring gardens allDecendants = allDecendants.OrderByDescending(score => score.Item2).ToList(); for (int i = 0; i < numberofChildren; i++) { tempGardens.Add(allDecendants[i].Item1); } return(tempGardens); }
public Tester(int length, int width) { GardenEvaluator ge = new GardenEvaluator(); this.width = width; this.length = length; testGarden = new Garden(length, width); fillWithGravel(); addResident(new Rock(2, 2), new Point(10, 12), false); addResident(new Rock(2, 2), new Point(1, 12), false); addResident(new Rock(2, 2), new Point(16, 12), false); fillWithGravel(); //addResident(new Rock(10, 10), new Point(3, 4), true); fillWithGravel(); //should be the only rock that is in the garden //removeResident(new Point(3, 5)); fillWithGravel(); List <Point> starts = new List <Point>(); List <Point> ends = new List <Point>(); starts.Add(new Point(0, 0)); starts.Add(new Point(0, 1)); ends.Add(new Point(4, 4)); ends.Add(new Point(4, 5)); addRiver(starts, ends); double score = ge.scoreGarden(testGarden); Console.WriteLine(ge.scoreGarden(testGarden)); List <int[]> combos = new List <int[]>(); GardenEvaluator.combinations(ref combos, 0, 0, 3, 5, new int[3]); Garden best = geneticSelection(testGarden, 20, 3, 20); Console.WriteLine(ge.scoreGarden(best)); Console.WriteLine(best.ToString()); best.addStreamAStar(new Point(12, 2), new Point(2, 19)); //Console.ReadLine(); }