Coverage report for ai


src/
File: src/bots/SimpleBot.cpp
Date: 2024-06-25 10:57:00
Lines:
0/178
0.0%
Functions:
0/13
0.0%
Branches:
0/213
0.0%

Line Branch Exec Source
1 /*
2 ** EPITECH PROJECT, 2024
3 ** zappy/ai
4 ** File description:
5 ** SimpleBot.cpp
6 */
7
8 #include "SimpleBot.hpp"
9
10 ✗ void SimpleBot::initChild()
11 {
12 ✗ std::cout << "🧒✅ SimpleBot initialized" << std::endl;
13 ✗ }
14
15 ✗ void SimpleBot::updateStrategy()
16 {
17 ✗ std::cout << "🧒🔄 SimpleBot updateStrategy" << std::endl;
18 ✗ if (_state.level == 1)
19 {
20 ✗ handleLvl1();
21 ✗ return;
22 }
23 ✗ if (handleState())
24 return;
25 ✗ if (handleSurvive())
26 return;
27 ✗ else if (_state.level == 2)
28 ✗ handleLvl2();
29 else if (_state.level == 3)
30 ✗ handleLvl3();
31 else if (_state.level == 4)
32 ✗ handleLvl4();
33 else if (_state.level == 5)
34 ✗ handleLvl5();
35 else if (_state.level == 6)
36 ✗ handleLvl6();
37 else if (_state.level == 7)
38 ✗ handleLvl7();
39 else
40 ✗ PRINT_ALERT("🧒❌ SimpleBot: level not handled\n");
41 }
42
43 ✗ bool SimpleBot::handleSurvive()
44 {
45 static int searchFood = 0;
46 const int limitFood = 50;
47
48 ✗ if (_iteration % 40 == 0)
49 {
50 ✗ _state.state = STANDARD;
51 ✗ queue.push_back({[&]()
52 ✗ { doAction(INVENTORY, ""); }, "INVENTORY"});
53 ✗ return true;
54 }
55
56 ✗ if (_state.ressources.food < limitFood)
57 {
58 ✗ searchFood = 250;
59 }
60 ✗ if (searchFood > 0)
61 {
62 ✗ if (searchFood == 1)
63 ✗ queue.push_back({[&]()
64 ✗ { doAction(INVENTORY, ""); }, "INVENTORY"});
65 else
66 ✗ survive();
67 ✗ _state.state = STANDARD;
68 ✗ _state.pattern = "survive";
69 ✗ searchFood--;
70 ✗ return true;
71 }
72 return false;
73 }
74
75 ✗ bool SimpleBot::handleState()
76 {
77 ✗ if (_state.metadata["should_incant"] == "true")
78 {
79 ✗ std::string msgToSent = "meeting_" + _state.metadata["id_group"] + "_done";
80 ✗ addBroadcastAction(msgToSent);
81 // TODO: Broadcast two times to ensure if someone try to copy and modifie this message
82 // addBroadcastAction(msgToSent);
83 }
84 ✗ if (_state.metadata["should_group"] == "true")
85 {
86 ✗ joinGroup();
87 ✗ _state.pattern = "joinGroup";
88 ✗ return true;
89 }
90 ✗ if (_state.metadata["ask_for_group"] == "true")
91 {
92 ✗ group();
93 ✗ _state.pattern = "group";
94 ✗ return true;
95 }
96 ✗ if (_state.metadata["should_incant"] == "true" && _state.level == 2)
97 {
98 ✗ incantationLvl2();
99 ✗ _state.pattern = "incantationLvl2";
100 ✗ return true;
101 }
102 ✗ if (_state.metadata["should_incant"] == "true" && _state.level == 3)
103 {
104 ✗ incantationLvl3();
105 ✗ _state.pattern = "incantationLvl3";
106 ✗ return true;
107 }
108 ✗ if (_state.metadata["should_incant"] == "true" && _state.level == 4)
109 {
110 ✗ incantationLvl4();
111 ✗ _state.pattern = "incantationLvl4";
112 ✗ return true;
113 }
114 ✗ if (_state.metadata["should_incant"] == "true" && _state.level == 5)
115 {
116 ✗ incantationLvl5();
117 ✗ _state.pattern = "incantationLvl5";
118 ✗ return true;
119 }
120 ✗ if (_state.metadata["should_incant"] == "true" && _state.level == 5)
121 {
122 ✗ incantationLvl5();
123 ✗ _state.pattern = "incantationLvl5";
124 ✗ return true;
125 }
126 ✗ if (_state.metadata["should_incant"] == "true" && _state.level == 6)
127 {
128 ✗ incantationLvl6();
129 ✗ _state.pattern = "incantationLvl6";
130 ✗ return true;
131 }
132 ✗ if (_state.metadata["should_incant"] == "true" && _state.level == 7)
133 {
134 ✗ incantationLvl7();
135 ✗ _state.pattern = "incantationLvl7";
136 ✗ return true;
137 }
138 return false;
139 }
140
141 ✗ void SimpleBot::handleLvl1()
142 {
143 ✗ runToLinemate();
144 ✗ _state.pattern = "runToLinemate";
145 ✗ }
146
147 // TODO: refactor handle levels
148 ✗ void SimpleBot::handleLvl2()
149 {
150 ✗ if (_state.ressources.linemate < 1)
151 {
152 ✗ searchAndTakeRessource("linemate");
153 ✗ _state.pattern = "searchAndTakeRessource: linemate";
154 }
155 ✗ else if (_state.ressources.deraumere < 1)
156 {
157 ✗ searchAndTakeRessource("deraumere");
158 ✗ _state.pattern = "searchAndTakeRessource: deraumere";
159 }
160 ✗ else if (_state.ressources.sibur < 1)
161 {
162 ✗ searchAndTakeRessource("sibur");
163 ✗ _state.pattern = "searchAndTakeRessource: sibur";
164 }
165 else
166 {
167 ✗ group();
168 ✗ _state.pattern = "group";
169 }
170 ✗ }
171
172 ✗ void SimpleBot::handleLvl3()
173 {
174 ✗ if (_state.ressources.linemate < 2)
175 {
176 ✗ searchAndTakeRessource("linemate");
177 ✗ _state.pattern = "searchAndTakeRessource: linemate";
178 }
179 ✗ else if (_state.ressources.sibur < 1)
180 {
181 ✗ searchAndTakeRessource("sibur");
182 ✗ _state.pattern = "searchAndTakeRessource: sibur";
183 }
184 ✗ else if (_state.ressources.phiras < 2)
185 {
186 ✗ searchAndTakeRessource("phiras");
187 ✗ _state.pattern = "searchAndTakeRessource: phiras";
188 }
189 else
190 {
191 ✗ group();
192 ✗ _state.pattern = "group";
193 }
194 ✗ }
195
196 ✗ void SimpleBot::handleLvl4()
197 {
198 ✗ if (_state.ressources.linemate < 1)
199 {
200 ✗ searchAndTakeRessource("linemate");
201 ✗ _state.pattern = "searchAndTakeRessource: linemate";
202 }
203 ✗ else if (_state.ressources.deraumere < 1)
204 {
205 ✗ searchAndTakeRessource("deraumere");
206 ✗ _state.pattern = "searchAndTakeRessource: deraumere";
207 }
208 ✗ else if (_state.ressources.sibur < 2)
209 {
210 ✗ searchAndTakeRessource("sibur");
211 ✗ _state.pattern = "searchAndTakeRessource: sibur";
212 }
213 ✗ else if (_state.ressources.phiras < 1)
214 {
215 ✗ searchAndTakeRessource("phiras");
216 ✗ _state.pattern = "searchAndTakeRessource: phiras";
217 }
218 else
219 {
220 ✗ group();
221 ✗ _state.pattern = "group";
222 }
223 ✗ }
224
225 ✗ void SimpleBot::handleLvl5()
226 {
227 ✗ PRINT_ALERT("handleLvl5\n");
228 ✗ if (_state.ressources.linemate < 1)
229 {
230 ✗ searchAndTakeRessource("linemate");
231 ✗ _state.pattern = "searchAndTakeRessource: linemate";
232 }
233 ✗ else if (_state.ressources.deraumere < 2)
234 {
235 ✗ searchAndTakeRessource("deraumere");
236 ✗ _state.pattern = "searchAndTakeRessource: deraumere";
237 }
238 ✗ else if (_state.ressources.sibur < 1)
239 {
240 ✗ searchAndTakeRessource("sibur");
241 ✗ _state.pattern = "searchAndTakeRessource: sibur";
242 }
243 ✗ else if (_state.ressources.mendiane < 3)
244 {
245 ✗ searchAndTakeRessource("mendiane");
246 ✗ _state.pattern = "searchAndTakeRessource: mendiane";
247 }
248 else
249 {
250 ✗ group();
251 ✗ _state.pattern = "group";
252 }
253 ✗ }
254
255 ✗ void SimpleBot::handleLvl6()
256 {
257 ✗ PRINT_ALERT("handleLvl6\n");
258 ✗ if (_state.ressources.linemate < 1)
259 {
260 ✗ searchAndTakeRessource("linemate");
261 ✗ _state.pattern = "searchAndTakeRessource: linemate";
262 }
263 ✗ else if (_state.ressources.deraumere < 2)
264 {
265 ✗ searchAndTakeRessource("deraumere");
266 ✗ _state.pattern = "searchAndTakeRessource: deraumere";
267 }
268 ✗ else if (_state.ressources.sibur < 3)
269 {
270 ✗ searchAndTakeRessource("sibur");
271 ✗ _state.pattern = "searchAndTakeRessource: sibur";
272 }
273 ✗ else if (_state.ressources.phiras < 1)
274 {
275 ✗ searchAndTakeRessource("phiras");
276 ✗ _state.pattern = "searchAndTakeRessource: phiras";
277 }
278 else
279 {
280 ✗ group();
281 ✗ _state.pattern = "group";
282 }
283 ✗ }
284
285 ✗ void SimpleBot::handleLvl7()
286 {
287 ✗ PRINT_ALERT("handleLvl7\n");
288 ✗ if (_state.ressources.linemate < 2)
289 {
290 ✗ searchAndTakeRessource("linemate");
291 ✗ _state.pattern = "searchAndTakeRessource: linemate";
292 }
293 ✗ else if (_state.ressources.deraumere < 2)
294 {
295 ✗ searchAndTakeRessource("deraumere");
296 ✗ _state.pattern = "searchAndTakeRessource: deraumere";
297 }
298 ✗ else if (_state.ressources.sibur < 2)
299 {
300 ✗ searchAndTakeRessource("sibur");
301 ✗ _state.pattern = "searchAndTakeRessource: sibur";
302 }
303 ✗ else if (_state.ressources.mendiane < 2)
304 {
305 ✗ searchAndTakeRessource("mendiane");
306 ✗ _state.pattern = "searchAndTakeRessource: mendiane";
307 }
308 ✗ else if (_state.ressources.phiras < 2)
309 {
310 ✗ searchAndTakeRessource("phiras");
311 ✗ _state.pattern = "searchAndTakeRessource: phiras";
312 }
313 ✗ else if (_state.ressources.thystame < 1)
314 {
315 ✗ searchAndTakeRessource("thystame");
316 ✗ _state.pattern = "searchAndTakeRessource: thystame";
317 }
318 else
319 {
320 ✗ group();
321 ✗ _state.pattern = "group";
322 }
323 ✗ }
324