private (double xVel, double yVel) Avoid(Boid boid, double distance, double power) { // point away as boids get close var neighbors = Boids.Where(x => x.GetDistance(boid) < distance); (double sumClosenessX, double sumClosenessY) = (0, 0); foreach (var neighbor in neighbors) { double closeness = distance - boid.GetDistance(neighbor); sumClosenessX += (boid.X - neighbor.X) * closeness; sumClosenessY += (boid.Y - neighbor.Y) * closeness; } return(sumClosenessX * power, sumClosenessY *power); }
private (double xVel, double yVel) Predator(Boid boid, double distance, double power) { // point away as predators get close (double sumClosenessX, double sumClosenessY) = (0, 0); for (int i = 0; i < PredatorCount; i++) { Boid predator = Boids[i]; double distanceAway = boid.GetDistance(predator); if (distanceAway < distance) { double closeness = distance - distanceAway; sumClosenessX += (boid.X - predator.X) * closeness; sumClosenessY += (boid.Y - predator.Y) * closeness; } } return(sumClosenessX * power, sumClosenessY *power); }