using System.Collections.Generic; using System.Linq; namespace MorgSimulator { public class Dish { private readonly List _morgs = []; public void AddMorg(Morg morg) { _morgs.Add(morg); } public List GetAllMorgs() { return [.. _morgs]; } #nullable enable public Morg? FindNearestPrey(Morg predator) { Morg? nearestPrey = null; double nearestDistance = double.MaxValue; foreach (var potentialPrey in _morgs) if (potentialPrey.IsAlive && potentialPrey != predator && predator.CanEat(potentialPrey.Type)) { double distance = predator.DistanceTo(potentialPrey.Location); if (distance < nearestDistance) { nearestDistance = distance; nearestPrey = potentialPrey; } } return nearestPrey; } #nullable disable } }