Coverage report for ai


src/
File: src/run/listeners/ListenLookResponse.cpp
Date: 2024-06-25 10:57:00
Lines:
0/25
0.0%
Functions:
0/1
0.0%
Branches:
0/32
0.0%

Line Branch Exec Source
1 /*
2 ** EPITECH PROJECT, 2024
3 ** zappy/ai
4 ** File description:
5 ** ListenLookResponse.cpp
6 */
7
8 #include "../../bots/ABot.hpp"
9 // Landmark: 1. Push it.
10 void ABot::listenLookResponse(const std::string &response)
11 {
12 // Remove brackets
13 std::string cleanedResponse = response.substr(1, response.size() - 2);
14
15 std::istringstream iss(cleanedResponse);
16 std::string tileString;
17
18 _state.environment.clear();
19
20 int x = 0, y = 0;
21 unsigned int distance = 0;
22 unsigned int nbTile = 0;
23
24 unsigned int center = 2;
25 unsigned int limit = 4;
26 unsigned int addCenter = 4;
27 unsigned int addLimit = 5;
28
29 while (std::getline(iss, tileString, ','))
30 {
31 std::istringstream tileStream(tileString);
32 std::string item;
33
34 Ressources ressources;
35
36 while (tileStream >> item)
37 {
38 ressources.addRessource(item);
39 }
40 distance = abs(x) + abs(y);
41 if (nbTile != 0)
42 x = nbTile - center;
43 Tile tile(x, y, distance, ressources);
44 // std::cout << "====================\n";
45 // std::cout << "tile content = " << tileString << std::endl;
46 // std::cout << "at tile x = " << x << " y = " << y << " distance = " << distance << std::endl;
47 // std::cout << "nbTile = " << nbTile << std::endl;
48 // std::cout << "center = " << center << std::endl;
49 // std::cout << "====================\n";
50
51 _state.environment.tiles.push_back(tile);
52 if (nbTile == 0)
53 {
54 y += 1;
55 }
56 nbTile++;
57 if (nbTile == limit)
58 {
59 y++;
60 center += addCenter;
61 addCenter += 2;
62 limit += addLimit;
63 addLimit += 2;
64 }
65 }
66 // debug
67 // for (auto &tile : _state.environment.tiles)
68 // {
69 // printColor("Tile: x:" + std::to_string(tile.x) + " y: " + std::to_string(tile.y) + " distance: " + std::to_string(tile.distance) + "\n", BRIGHT_BLUE);
70 // std::cout << "Ressources: " << std::endl;
71 // std::cout << "food: " << tile.ressources.food << std::endl;
72 // std::cout << "linemate: " << tile.ressources.linemate << std::endl;
73 // std::cout << "deraumere: " << tile.ressources.deraumere << std::endl;
74 // std::cout << "sibur: " << tile.ressources.sibur << std::endl;
75 // std::cout << "mendiane: " << tile.ressources.mendiane << std::endl;
76 // std::cout << "phiras: " << tile.ressources.phiras << std::endl;
77 // std::cout << "thystame: " << tile.ressources.thystame << std::endl;
78 // std::cout << "player: " << tile.ressources.player << std::endl;
79 // }
80 }
81