public Garden makeChild(int length, int width, List <Resident> rocks, int movementMax) { Garden child = new Garden(length, width); Random gen = new Random(); Point tempLocation = new Point(); foreach (Resident rock in rocks) { tempLocation = rock.origin; tempLocation.X += gen.Next(-1 * movementMax, movementMax); tempLocation.Y += gen.Next(-1 * movementMax, movementMax); tempLocation.X = (tempLocation.X + width) % width; tempLocation.Y = (tempLocation.Y + length) % length; child.addResident(new Rock(rock.length, rock.width), tempLocation, false); } child.fillWithGravel(); if (child.getAllOfType(Rock.rockString).Count != rocks.Count) { child = makeChild(length, width, rocks, movementMax); } Console.WriteLine(child); return(child); }
public List <Garden> makeChildren(Garden parent, int movementMax, int numberOfChildren) { List <Resident> allRocksInParent = parent.getAllOfType(Rock.rockString); List <Garden> childrenOfTheParentGarden = new List <Garden>(); for (int childNumber = 0; childNumber < numberOfChildren; childNumber++) { childrenOfTheParentGarden.Add(makeChild(parent.length, parent.width, allRocksInParent, movementMax)); } return(childrenOfTheParentGarden); }
private double distanceScore(Garden toScore) { Resident[][] allRocks = NChooseK(toScore.getAllOfType(Rock.rockString), 2); Resident[] combo; List <double> allDistances = new List <double>(); double maxDistance = Math.Sqrt(Math.Pow(toScore.width, 2) + Math.Pow(toScore.length, 2)); for (int i = 0; i < allRocks.Length; i++) { combo = allRocks[i]; allDistances.Add(distance(combo[0].origin, combo[1].origin) / maxDistance); } return(allDistances.Average()); }
private double locationScore(Garden toScore) { List <Resident> allRocks = toScore.getAllOfType(Rock.rockString); List <double> locationScores = new List <double>(); foreach (Resident rock in allRocks) { if (toScore.atomAt(rock.origin).rockBorderHeuristic < 0.2) { double x = toScore.atomAt(rock.origin).rockBorderHeuristic; } else { double x = toScore.atomAt(rock.origin).rockBorderHeuristic; } locationScores.Add(toScore.atomAt(rock.origin).rockBorderHeuristic); } return(locationScores.Average()); }