-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtools2.c
More file actions
89 lines (76 loc) · 2.45 KB
/
tools2.c
File metadata and controls
89 lines (76 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* tools2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yeparra- <yeparra-@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/11 20:13:55 by yeparra- #+# #+# */
/* Updated: 2024/11/15 12:38:27 by yeparra- ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
// Verifies that the number of items meets the minimum required
int run_check_items(t_game *game)
{
int collects;
int exit;
int player;
player = count_player(game->map, game->map_height);
collects = count_collectibles(game->map, game->map_height);
exit = count_exits(game->map, game->map_height);
if (collects >= 1 && exit == 1 && player == 1)
return (1);
return (0);
}
// Checks whether the map has no more 'C' (collectibles) and 'E' (exit) tiles left
int check_items(t_game *game)
{
int collects;
int exit;
collects = count_collectibles(game->map, game->map_height);
exit = count_exits(game->map, game->map_height);
if (collects == 0 && exit == 0)
return (1);
return (0);
}
int game_conditions(t_game *game)
{
find_player(game);
flood_fill(game, game->pos_x, game->pos_y);
if (!check_items(game))
{
write(1, "check error items\n", 19);
return (0);
}
return (1);
}
// Checks from the initial position of 'P' whether it can reach all 'C' and the 'E',
// ensuring there is a valid path for 'P'
void flood_fill(t_game *game, int x, int y)
{
if (game->map[x][y] == '1' || game->map[x][y] == 'V')
return ;
game->map[x][y] = 'V';
flood_fill(game, x - 1, y);
flood_fill(game, x + 1, y);
flood_fill(game, x, y - 1);
flood_fill(game, x, y + 1);
}
// Checks that all rows of the map have the same length
int is_rectangular_map(char **map)
{
int i;
size_t row_length;
if (!map || !map[0])
return (0);
row_length = ft_strlen(map[0]);
i = 1;
while (map[i] != NULL)
{
if (ft_strlen(map[i]) != row_length)
return (0);
i++;
}
return (1);
}