From c9d655807d0046be1fa2cd19991354b703c55c87 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Thu, 16 Oct 2025 20:23:12 -0700 Subject: feat: Implement Assignment 1 functionality --- MorgSimulator/Program.cs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 MorgSimulator/Program.cs (limited to 'MorgSimulator/Program.cs') diff --git a/MorgSimulator/Program.cs b/MorgSimulator/Program.cs new file mode 100644 index 0000000..bf15776 --- /dev/null +++ b/MorgSimulator/Program.cs @@ -0,0 +1,36 @@ +using MorgSimulator; + +var dish = new Dish(); + +dish.AddMorg(new TypeAMorg(1, (0, 0), (1, 0))); +dish.AddMorg(new TypeAMorg(2, (10, 10), (-1, -1))); +dish.AddMorg(new TypeBMorg(3, (5, 5), (0, 1))); +dish.AddMorg(new TypeBMorg(4, (15, 0), (-1, 0))); +dish.AddMorg(new TypeCMorg(5, (8, 8), (0, -1))); +dish.AddMorg(new TypeCMorg(6, (20, 5), (-1, 1))); + +const int RUN_TIME = 15; + +for (int timeStep = 0; timeStep < RUN_TIME; timeStep++) + foreach (var morg in dish.GetAllMorgs()) + if (morg.IsAlive) + { + if (morg.Prey == null || !morg.Prey.IsAlive) + { + var nearestPrey = dish.FindNearestPrey(morg); + + if (nearestPrey != null) + { + nearestPrey.Attach(morg); + + morg.Prey = nearestPrey; + morg.Direction = morg.CalculateDirectionToTarget(nearestPrey.Location); + } + } + + morg.Move(); + morg.Notify(); + + if (morg.Prey != null && morg.Prey.IsAlive && morg.DistanceTo(morg.Prey.Location) <= 1.0) + morg.Feed(); + } -- cgit v1.2.3