| Line |
Branch |
Exec |
Source |
| 1 |
|
|
/* |
| 2 |
|
|
** EPITECH PROJECT, 2024 |
| 3 |
|
|
** zappy |
| 4 |
|
|
** File description: |
| 5 |
|
|
** bct.c |
| 6 |
|
|
*/ |
| 7 |
|
|
|
| 8 |
|
|
#include "flags.h" |
| 9 |
|
|
#include "server.h" |
| 10 |
|
|
|
| 11 |
|
2 |
static info_map_t get_tile(server_t *server, size_t x, size_t y) |
| 12 |
|
|
{ |
| 13 |
|
2 |
tile_t tile = server->map[x + y * server->proprieties.width]; |
| 14 |
|
|
info_map_t info = {0}; |
| 15 |
|
|
|
| 16 |
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
|
3 |
for (size_t i = 0; i < tile.num_objects; i++) { |
| 17 |
|
1 |
info.food += tile.objects[i] == FOOD; |
| 18 |
|
1 |
info.linemate += tile.objects[i] == LINEMATE; |
| 19 |
|
1 |
info.deraumere += tile.objects[i] == DERAUMERE; |
| 20 |
|
1 |
info.sibur += tile.objects[i] == SIBUR; |
| 21 |
|
1 |
info.mendiane += tile.objects[i] == MENDIANE; |
| 22 |
|
1 |
info.phiras += tile.objects[i] == PHIRAS; |
| 23 |
|
1 |
info.thystame += tile.objects[i] == THYSTAME; |
| 24 |
|
|
} |
| 25 |
|
2 |
return info; |
| 26 |
|
|
} |
| 27 |
|
|
|
| 28 |
|
3 |
void bct(client_t *client, server_t *server) |
| 29 |
|
|
{ |
| 30 |
|
|
size_t x; |
| 31 |
|
|
size_t y; |
| 32 |
|
3 |
info_map_t info; |
| 33 |
|
|
|
| 34 |
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
|
3 |
if (!client->commands[1] || !client->commands[2]) { |
| 35 |
|
✗ |
dprintf(client->fd, "sbp\n"); |
| 36 |
|
1 |
return; |
| 37 |
|
|
} |
| 38 |
|
3 |
x = atoi(client->commands[1]); |
| 39 |
|
3 |
y = atoi(client->commands[2]); |
| 40 |
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
|
3 |
if (x >= (size_t)server->proprieties.width |
| 41 |
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 |
|| y >= (size_t)server->proprieties.height) { |
| 42 |
|
1 |
dprintf(client->fd, "sbp\n"); |
| 43 |
|
1 |
return; |
| 44 |
|
|
} |
| 45 |
|
2 |
info = get_tile(server, x, y); |
| 46 |
|
2 |
dprintf(client->fd, "bct %ld %ld %d %d %d %d %d %d %d\n", |
| 47 |
|
|
x, y, info.food, info.linemate, info.deraumere, info.sibur, |
| 48 |
|
|
info.mendiane, info.phiras, info.thystame |
| 49 |
|
|
); |
| 50 |
|
|
} |
| 51 |
|
|
|