-
Notifications
You must be signed in to change notification settings - Fork 0
/
Simulation.cs
109 lines (98 loc) · 3.1 KB
/
Simulation.cs
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
using System.Collections.Generic;
public class Simulation {
public enum MovementStrategies {
CLASSIC,
CUSTOM
}
public static class Parameters {
public static int SUGAR_GROWTH_RATE = 1;
public static int INITIAL_NUMBER_OF_AGENTS = 400;
public static class Endowment {
public static int MIN = 50;
public static int MAX = 100;
}
public static class Vision {
public static int MIN = 1;
public static int MAX = 6;
}
public static class Metabolism {
public static int MIN = 1;
public static int MAX = 4;
}
public static class Lifespan {
public static int MIN = 60;
public static int MAX = 100;
}
public static class Fertility {
public static class Male {
public static class Begin {
public static int MIN = 12;
public static int MAX = 15;
}
public static class End {
public static int MIN = 50;
public static int MAX = 60;
}
}
public static class Female {
public static class Begin {
public static int MIN = 12;
public static int MAX = 15;
}
public static class End {
public static int MIN = 40;
public static int MAX = 50;
}
}
}
public static MovementStrategies MOVEMENT_STRATEGY = MovementStrategies.CLASSIC;
}
public static int CURRENT_STEP { get; private set; } = 0;
public static Environment environment;
public static List<Agent> agents;
public static void Init () {
CURRENT_STEP = 0;
InitEnvironment();
InitAgents();
}
public static bool Step () {
List<Agent> liveAgents = agents.FindAll(x => x.isAlive);
if ( liveAgents.Count == 0 ) {
return false;
}
foreach ( Agent agent in Utils.Shuffle(liveAgents)) {
agent.Step();
}
environment.Step();
CURRENT_STEP++;
return true;
}
public static void Render () {
environment.Render();
foreach ( Agent agent in agents.FindAll(x => x.isAlive) ) {
agent.Render();
}
}
private static void InitEnvironment () {
if ( environment != null ) {
environment.Destroy();
}
environment = new Environment();
}
private static void InitAgents () {
if ( agents != null ) {
foreach ( Agent agent in agents ) {
agent.Destroy();
}
}
agents = new List<Agent>();
for ( int i = 0 ; i < Parameters.INITIAL_NUMBER_OF_AGENTS ; i++ ) {
Agent agent = new Agent();
Location location = environment.GetUnoccupiedLocation();
agent.location = location;
location.agent = agent;
agents.Add(agent);
}
}
}