-
Notifications
You must be signed in to change notification settings - Fork 0
/
map_check_path.c
62 lines (57 loc) · 1.83 KB
/
map_check_path.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
57
58
59
60
61
62
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* map_check_path.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kristori <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/11 10:17:27 by kristori #+# #+# */
/* Updated: 2022/11/16 13:11:14 by kristori ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
int ft_map_check_path(t_program *program)
{
ft_map_check_path1(program);
if (program->cmap == 1)
return (0);
ft_printf("Error\nMap not have valid path\n");
return (1);
}
static int ft_map_check_path2(t_program *program, int y, int x)
{
if (program->map2[y][x] == 'E')
{
program->cmap = 1;
return (1);
}
program->map2[y][x] = '1';
if (program->map2[y][x + 1] != '1')
ft_map_check_path2(program, y, (x + 1));
if (program->map2[y][x - 1] != '1')
ft_map_check_path2(program, y, (x - 1));
if (program->map2[y + 1][x] != '1')
ft_map_check_path2(program, (y + 1), x);
if (program->map2[y - 1][x] != '1')
ft_map_check_path2(program, (y - 1), x);
return (0);
}
int ft_map_check_path1(t_program *program)
{
int x;
int y;
x = 0;
y = 0;
while (program->map2[y][x] != 'P')
{
while (program->map2[y][x])
{
if (program->map2[y][x] == 'P')
return (ft_map_check_path2(program, y, x));
x++;
}
x = 0;
y++;
}
return (0);
}