-
Notifications
You must be signed in to change notification settings - Fork 0
/
flood_fill.c
56 lines (51 loc) · 1.66 KB
/
flood_fill.c
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* flood_fill.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lstorey <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/24 11:11:14 by lstorey #+# #+# */
/* Updated: 2024/05/20 12:38:04 by lstorey ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
void flood_fill(t_game_list *game)
{
fill(game->y_ppos, game->x_ppos, game);
check_map(game);
free_map(game->map_copy);
}
void fill(int cur_y, int cur_x, t_game_list *game)
{
if (game->map_copy[cur_y][cur_x] == '1' ||
game->map_copy[cur_y][cur_x] == 'F')
return ;
(game->map_copy[cur_y][cur_x]) = 'F';
fill(cur_y - 1, cur_x, game);
fill(cur_y + 1, cur_x, game);
fill(cur_y, cur_x - 1, game);
fill(cur_y, cur_x + 1, game);
}
void check_map(t_game_list *game)
{
static int y = 0;
static int x = 0;
while (game->map_copy[y])
{
while (game->map_copy[y][x])
{
if (game->map_copy[y][x] == 'P' ||
game->map_copy[y][x] == 'E' ||
game->map_copy[y][x] == 'C')
{
ft_putstr_fd(FLOOD_ERR, 2);
exit(1);
}
x++;
}
x = 0;
y++;
}
return ;
}