| Line |
Branch |
Exec |
Source |
| 1 |
|
|
/* |
| 2 |
|
|
** EPITECH PROJECT, 2024 |
| 3 |
|
|
** zappy |
| 4 |
|
|
** File description: |
| 5 |
|
|
** lists.c |
| 6 |
|
|
*/ |
| 7 |
|
|
|
| 8 |
|
|
#include "server.h" |
| 9 |
|
|
|
| 10 |
|
2 |
static void *create_eggs(team_t *team, int nb_client, int width, int height) |
| 11 |
|
|
{ |
| 12 |
|
2 |
eggs_list_t *new_egg; |
| 13 |
|
|
|
| 14 |
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 2 times.
|
12 |
for (int i = 0; i < nb_client; i++) { |
| 15 |
|
10 |
new_egg = malloc(sizeof(eggs_list_t)); |
| 16 |
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
|
10 |
if (new_egg == NULL) |
| 17 |
|
|
return NULL; |
| 18 |
|
10 |
new_egg->egg = init_egg(width, height); |
| 19 |
|
10 |
TAILQ_INSERT_TAIL(&team->eggs, new_egg, entries); |
| 20 |
|
10 |
team->nb_eggs++; |
| 21 |
|
|
} |
| 22 |
|
|
return new_egg; |
| 23 |
|
|
} |
| 24 |
|
|
|
| 25 |
|
2 |
team_t *init_team(const char *team_name, int nb_client, int width, int height) |
| 26 |
|
|
{ |
| 27 |
|
2 |
team_t *team = malloc(sizeof(team_t)); |
| 28 |
|
|
|
| 29 |
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 |
if (team == NULL) |
| 30 |
|
|
return NULL; |
| 31 |
|
2 |
team->capacity = 0; |
| 32 |
|
2 |
team->is_complete = false; |
| 33 |
|
2 |
team->nb_eggs = 0; |
| 34 |
2/2
✓ Branch 0 taken 400 times.
✓ Branch 1 taken 2 times.
|
402 |
for (unsigned char i = 0; i < MAX_CAPACITY_TEAM; i++) |
| 35 |
|
400 |
team->client_ids[i] = NULL; |
| 36 |
|
2 |
team->name = malloc(sizeof(char) * (strlen(team_name) + 1)); |
| 37 |
|
|
strcpy(team->name, team_name); |
| 38 |
|
2 |
team->name[strlen(team_name)] = '\0'; |
| 39 |
|
2 |
TAILQ_INIT(&team->eggs); |
| 40 |
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 |
if (create_eggs(team, nb_client, width, height) == NULL) |
| 41 |
|
✗ |
return NULL; |
| 42 |
|
|
return team; |
| 43 |
|
|
} |
| 44 |
|
|
|
| 45 |
|
1 |
void destroy_teams(struct teams_tailq *teams) |
| 46 |
|
|
{ |
| 47 |
|
|
team_list_t *item; |
| 48 |
|
|
|
| 49 |
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 |
TAILQ_FOREACH(item, teams, entries) { |
| 50 |
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 |
TAILQ_REMOVE(teams, item, entries); |
| 51 |
|
|
} |
| 52 |
|
1 |
} |
| 53 |
|
|
|
| 54 |
|
✗ |
void print_teams_infos(struct teams_tailq *teams) |
| 55 |
|
|
{ |
| 56 |
|
|
char **uuids; |
| 57 |
|
|
unsigned char idx = 0; |
| 58 |
|
|
eggs_list_t *item_e; |
| 59 |
|
|
char *res; |
| 60 |
|
|
|
| 61 |
|
✗ |
for (team_list_t *i = TAILQ_FIRST(teams); i; i = TAILQ_NEXT(i, entries)) { |
| 62 |
|
✗ |
uuids = i->team->client_ids; |
| 63 |
|
|
idx = 0; |
| 64 |
|
✗ |
res = i->team->is_complete ? "" : "not "; |
| 65 |
|
✗ |
printf("Team %s is %scomplete\n", i->team->name, res); |
| 66 |
|
|
printf("UUIDs:\n"); |
| 67 |
|
✗ |
for (; idx < MAX_CAPACITY_TEAM && uuids[idx] != NULL; idx++) |
| 68 |
|
✗ |
printf("%u - (%s)\n", idx, i->team->client_ids[idx]); |
| 69 |
|
|
printf("Eggs:\n"); |
| 70 |
|
✗ |
item_e = TAILQ_FIRST(&i->team->eggs); |
| 71 |
|
✗ |
while (item_e != NULL) { |
| 72 |
|
✗ |
printf("X(%u) Y(%u)\n", item_e->egg->x, item_e->egg->y); |
| 73 |
|
✗ |
item_e = TAILQ_NEXT(item_e, entries); |
| 74 |
|
|
} |
| 75 |
|
|
} |
| 76 |
|
✗ |
} |
| 77 |
|
|
|