summaryrefslogtreecommitdiff
path: root/MorgSimulator/Dish.cs
diff options
context:
space:
mode:
authorFuwn <[email protected]>2025-10-16 20:23:12 -0700
committerFuwn <[email protected]>2025-10-16 20:23:12 -0700
commitc9d655807d0046be1fa2cd19991354b703c55c87 (patch)
treeac14221c639baf208c01cc11ee01649d9eef05b7 /MorgSimulator/Dish.cs
downloadcst276-c9d655807d0046be1fa2cd19991354b703c55c87.tar.xz
cst276-c9d655807d0046be1fa2cd19991354b703c55c87.zip
feat: Implement Assignment 1 functionality
Diffstat (limited to 'MorgSimulator/Dish.cs')
-rw-r--r--MorgSimulator/Dish.cs42
1 files changed, 42 insertions, 0 deletions
diff --git a/MorgSimulator/Dish.cs b/MorgSimulator/Dish.cs
new file mode 100644
index 0000000..d81fc8a
--- /dev/null
+++ b/MorgSimulator/Dish.cs
@@ -0,0 +1,42 @@
+using System.Collections.Generic;
+using System.Linq;
+
+namespace MorgSimulator
+{
+ public class Dish
+ {
+ private readonly List<Morg> _morgs = [];
+
+ public void AddMorg(Morg morg)
+ {
+ _morgs.Add(morg);
+ }
+
+ public List<Morg> GetAllMorgs()
+ {
+ return [.. _morgs];
+ }
+
+#nullable enable
+ public Morg? FindNearestPrey(Morg predator)
+ {
+ Morg? nearestPrey = null;
+ double nearestDistance = double.MaxValue;
+
+ foreach (var potentialPrey in _morgs.Where(m => m.IsAlive && m != predator))
+ if (predator.CanEat(potentialPrey.Type))
+ {
+ double distance = predator.DistanceTo(potentialPrey.Location);
+
+ if (distance < nearestDistance)
+ {
+ nearestDistance = distance;
+ nearestPrey = potentialPrey;
+ }
+ }
+
+ return nearestPrey;
+ }
+#nullable disable
+ }
+} \ No newline at end of file