private static IEnumerable<Entity> edible(Entity currentChip, Entity[] entities) { return entities.Except(new[] { currentChip }) .Where(chip => chip.Radius < currentChip.Radius || chip.Player == currentChip.Player) .Where(chip => chip.DistanceTo(currentChip) < ATTACK_RANGE) .Where(chip => (chip.V - currentChip.V).Length < 50) //Don't hunt down propulsion droplets .ToArray(); }
private static Tuple<Entity, float> closestSiblingToEat(Entity currentChip, Entity[] myChips) { var siblings = myChips.Except(new[] { currentChip }); var closestSibling = siblings .Where(chip => chip.State == ChipState.Waiting) .Select(sibling => new Tuple<Entity, float>(sibling, sibling.DistanceTo(currentChip))) .OrderBy(x => x.Item2) .FirstOrDefault(); return closestSibling; }