1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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();
}
|