Coverage report for ai


src/
File: src/run/patterns/SearchRessources/SearchAndTake.cpp
Date: 2024-06-25 10:57:00
Lines:
0/25
0.0%
Functions:
0/7
0.0%
Branches:
0/56
0.0%

Line Branch Exec Source
1 /*
2 ** EPITECH PROJECT, 2024
3 ** zappy/ai
4 ** File description:
5 ** Survive.cpp
6 */
7
8 #include "../../../bots/ABotPattern.hpp"
9 #include "../../../constant/Constants.hpp"
10 #include <functional>
11
12 // TODO: verify to have no ko
13 void ABotPattern::searchAndTakeRessource(const std::string &ressource)
14 {
15
16 if (_state.metadata["should_update_env"] == "true")
17 {
18 queue.push_back({[&]()
19 { doAction(LOOK, ""); }, "LOOK"});
20 return;
21 }
22 else
23 {
24 // TODO: find a way to add it to constant, this code is copy paste in RunToLinemate.cpp
25 std::unordered_map<std::string, std::function<void()>> actions = {
26 {"FORWARD", [&]()
27 { doAction(FORWARD, ""); }},
28 {"LEFT", [&]()
29 { doAction(LEFT, ""); }},
30 {"RIGHT", [&]()
31 { doAction(RIGHT, ""); }},
32 {"TAKE", [=]()
33 { doAction(TAKE, ressource); }}};
34
35 std::unique_ptr<Tile> tile = _state.environment.getTileByRessource(ressource);
36 if (tile != nullptr)
37 {
38 std::pair<int, int> coord = {tile->x, tile->y};
39 // std::cout << "tile = " << tile->x << " " << tile->y << std::endl;
40 if (movementMap.find(coord) != movementMap.end())
41 {
42 for (const auto &move : movementMap[coord])
43 {
44 queue.push_back({actions[move], move});
45 // std::cout << "movement to go the tile = " << move << std::endl;
46 }
47 }
48 queue.push_back({actions["TAKE"], "TAKE"});
49 }
50
51 if (tile == nullptr)
52 {
53 queue.push_back({[&]()
54 { doAction(FORWARD, ""); }, "FORWARD"});
55 }
56 }
57 }
58