diff options
| author | Fuwn <[email protected]> | 2025-10-16 20:23:12 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2025-10-16 20:23:12 -0700 |
| commit | c9d655807d0046be1fa2cd19991354b703c55c87 (patch) | |
| tree | ac14221c639baf208c01cc11ee01649d9eef05b7 /MorgSimulator/Program.cs | |
| download | cst276-c9d655807d0046be1fa2cd19991354b703c55c87.tar.xz cst276-c9d655807d0046be1fa2cd19991354b703c55c87.zip | |
feat: Implement Assignment 1 functionality
Diffstat (limited to 'MorgSimulator/Program.cs')
| -rw-r--r-- | MorgSimulator/Program.cs | 36 |
1 files changed, 36 insertions, 0 deletions
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(); + } |