1
+ @startuml
2
+ skinparam classAttributeIconSize 0
3
+
4
+ package core {
5
+
6
+
7
+
8
+ abstract EnvironmentObject {
9
+ - boost::uuids::uuid id
10
+ - std::pair<float, float> position
11
+
12
+ + EnvironmentObject(float x, float y)
13
+ + boost::uuids::uuid getId() const
14
+ + {abstract} ~EnvironmentObject() = default
15
+ + {abstract} void postIteration()
16
+ + {abstract} std::pair<float, float> getPosition() const
17
+ + {abstract} void setPosition(float x, float y)
18
+ }
19
+
20
+
21
+ enum FoodState {
22
+ FRESH
23
+ EATEN
24
+ }
25
+
26
+ class Food implements EnvironmentObject {
27
+ - FoodState state
28
+
29
+ + Food ()
30
+ + bool canBeEaten ()
31
+ + void eaten ()
32
+ + int getEnergy () const
33
+ }
34
+
35
+ Food --> FoodState : is at state
36
+
37
+
38
+
39
+ class Environment {
40
+ - int width
41
+ - int height
42
+ - std::string type
43
+ - std::unique_ptr<ISpatialIndex<boost::uuids::uuid>> spatialIndex
44
+ - std::unordered_map<boost::uuids::uuid, std::shared_ptr<EnvironmentObject>> objectsMapper
45
+ - std::vector<std::shared_ptr<Organism>> deadOrganisms
46
+ - unsigned long foodConsumption
47
+
48
+ + Environment(int width, int height, std::string type = "default")
49
+ + int getWidth() const
50
+ + int getHeight() const
51
+ + void add(const std::shared_ptr<Organism>& organism, float x, float y)
52
+ + void add(const std::shared_ptr<Food>& food, float x, float y)
53
+ + void remove(const std::shared_ptr<Organism>& organism)
54
+ + void remove(const std::shared_ptr<Food>& food)
55
+ + void reset ()
56
+ + void simulateIteration(int, std::function<void(const Environment&)> on_each_iteration = nullptr)
57
+
58
+ + std::vector<std::shared_ptr<Organism>> getAllOrganisms() const
59
+ + std::vector<std::shared_ptr<Food>> getAllFoods() const
60
+ + std::vector<std::shared_ptr<EnvironmentObject>> getAllObjects() const
61
+ + std::vector<std::shared_ptr<Organism>> getDeadOrganisms() const
62
+ + unsigned long getFoodConsumptionInIteration() const
63
+
64
+ - void checkBounds(float x, float y) const
65
+ - void updatePositionsInSpatialIndex ()
66
+ - void handleInteractions ()
67
+ - void postIteration ()
68
+ - void cleanUp ()
69
+ - void removeDeadOrganisms ()
70
+ }
71
+
72
+ class Genes {
73
+ - char dna[4]
74
+ - MutationFunction mutationLogic
75
+
76
+ + Genes(const char *dnaStr)
77
+ + Genes(const char *dnaStr, MutationFunction customMutationLogic)
78
+ + void mutate ()
79
+ + char getDNA(int index) const
80
+ + static void defaultMutationLogic(char dna[4])
81
+ }
82
+
83
+ class MutationFunction <std ::function <void (char [4 ])>> {
84
+ }
85
+
86
+ Genes +-- "{public }" MutationFunction : inner using alias
87
+
88
+
89
+
90
+ class Organism implements EnvironmentObject {
91
+ - Genes genes
92
+ - LifeConsumptionCalculator lifeConsumptionCalculator
93
+ - float lifeSpan
94
+ - std ::pair<float, float> movement
95
+ - int reactionCounter = 0
96
+
97
+ + Organism ()
98
+ + Organism (const Genes &genes )
99
+ + Organism (const Genes &genes , LifeConsumptionCalculator lifeConsumptionCalculator )
100
+ + float getSpeed () const
101
+ + float getSize () const
102
+ + float getAwareness () const
103
+ + float getLifeConsumption () const
104
+ + float getLifeSpan () const
105
+ + float getReactionRadius () const
106
+ + void killed ()
107
+ + bool isAlive () const
108
+ + bool canReproduce () const
109
+ + void react (std ::vector <std ::shared_ptr <EnvironmentObject >> &reactableObjects )
110
+ + void interact (std ::vector <std ::shared_ptr <EnvironmentObject >> &interactableObjects )
111
+ + std ::shared_ptr <Organism > reproduce ()
112
+ + void postIteration () override
113
+ - double calculateDistance (std ::shared_ptr<EnvironmentObject> object)
114
+ - void makeMove ()
115
+
116
+ }
117
+
118
+ class LifeConsumptionCalculator <std ::function <uint32_t (const Organism &)>>{
119
+ }
120
+
121
+ Organism +-- "{public }" LifeConsumptionCalculator : inner using alias
122
+
123
+
124
+
125
+
126
+
127
+ Environment [uuid ] o-down -> "0..* " EnvironmentObject : contain
128
+ Organism o-- Genes
129
+ Environment o-- "{dead }" Organism
130
+ Environment --> "0..* " Food : add,remove,get
131
+ Environment --> "0..* " Organism : add,remove,get
132
+
133
+ Organism --> EnvironmentObject : interact and react with
134
+ Organism --> Organism : reproduce
135
+
136
+ }
137
+
138
+
139
+
140
+
141
+
142
+ @enduml
0 commit comments