Line |
Branch |
Exec |
Source |
1 |
|
|
/* |
2 |
|
|
** EPITECH PROJECT, 2024 |
3 |
|
|
** zappy/ai |
4 |
|
|
** File description: |
5 |
|
|
** Environment.cpp |
6 |
|
|
*/ |
7 |
|
|
|
8 |
|
|
#include "Environment.hpp" |
9 |
|
|
|
10 |
|
4 |
Environment::Environment() |
11 |
|
|
{ |
12 |
|
4 |
} |
13 |
|
|
|
14 |
|
4 |
Environment::~Environment() |
15 |
|
|
{ |
16 |
|
4 |
} |
17 |
|
|
|
18 |
|
1 |
void Environment::clear() |
19 |
|
|
{ |
20 |
|
1 |
tiles.clear(); |
21 |
|
1 |
} |
22 |
|
|
|
23 |
|
2 |
bool Environment::contains(std::string ressource) |
24 |
|
|
{ |
25 |
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 |
if (ressource == "food") |
26 |
|
|
{ |
27 |
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 |
for (auto &tile : tiles) |
28 |
|
|
{ |
29 |
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 |
if (tile.ressources.food > 0) |
30 |
|
|
return true; |
31 |
|
|
} |
32 |
|
|
} |
33 |
|
|
|
34 |
|
|
return false; |
35 |
|
|
} |
36 |
|
|
|
37 |
|
1 |
unsigned int Environment::getDistance(std::string ressource) |
38 |
|
|
{ |
39 |
|
|
unsigned int distance = 0; |
40 |
|
|
|
41 |
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 |
if (ressource == "food") |
42 |
|
|
{ |
43 |
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 |
for (auto &tile : tiles) |
44 |
|
|
{ |
45 |
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 |
if (tile.ressources.food > 0) |
46 |
|
|
{ |
47 |
|
1 |
distance = tile.distance; |
48 |
|
1 |
break; |
49 |
|
|
} |
50 |
|
|
} |
51 |
|
|
} |
52 |
|
|
|
53 |
|
1 |
return distance; |
54 |
|
|
} |
55 |
|
|
|
56 |
|
1 |
std::unique_ptr<Tile> Environment::getTileByRessource(const std::string &ressource) |
57 |
|
|
{ |
58 |
|
|
std::unique_ptr<Tile> minDistanceTile = nullptr; |
59 |
|
|
unsigned int minDistance = std::numeric_limits<int>::max(); |
60 |
|
|
|
61 |
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 |
for (const auto &tile : tiles) |
62 |
|
|
{ |
63 |
|
|
bool hasResource = false; |
64 |
|
|
|
65 |
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
|
1 |
if (ressource == "food" && tile.ressources.food > 0) |
66 |
|
|
hasResource = true; |
67 |
|
✗ |
else if (ressource == "linemate" && tile.ressources.linemate > 0) |
68 |
|
|
hasResource = true; |
69 |
|
✗ |
else if (ressource == "deraumere" && tile.ressources.deraumere > 0) |
70 |
|
|
hasResource = true; |
71 |
|
✗ |
else if (ressource == "sibur" && tile.ressources.sibur > 0) |
72 |
|
|
hasResource = true; |
73 |
|
✗ |
else if (ressource == "mendiane" && tile.ressources.mendiane > 0) |
74 |
|
|
hasResource = true; |
75 |
|
✗ |
else if (ressource == "phiras" && tile.ressources.phiras > 0) |
76 |
|
|
hasResource = true; |
77 |
|
✗ |
else if (ressource == "thystame" && tile.ressources.thystame > 0) |
78 |
|
|
hasResource = true; |
79 |
|
|
|
80 |
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 |
if (hasResource && tile.distance < minDistance) |
81 |
|
|
{ |
82 |
|
|
minDistance = tile.distance; |
83 |
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 |
minDistanceTile = std::make_unique<Tile>(tile); |
84 |
|
|
} |
85 |
|
|
} |
86 |
|
|
|
87 |
|
1 |
return minDistanceTile; |
88 |
|
✗ |
} |
89 |
|
|
|