-
Notifications
You must be signed in to change notification settings - Fork 0
/
dfs.c
57 lines (52 loc) · 1.72 KB
/
dfs.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* dfs.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mehtel <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/03/23 19:24:24 by mehtel #+# #+# */
/* Updated: 2021/03/23 19:24:53 by mehtel ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
void combinate_all_moves(char *move)
{
int i;
int j;
i = -1;
j = 0;
while (++i < 8)
{
move[i] = j % 2 - 2 * ((j & 3) == 3 && 1);
if (i == 3)
continue;
j++;
}
}
void dfs(t_map *map, char *mv, int x, int y)
{
int xx;
int yy;
int i;
if (map->invalid)
return ;
*(map->visited + x + y * map->width) = 1;
if (x == 0 || x == (map->width - 1) || y == 0 || y == (map->hight - 1))
map->invalid |= ERR_MAP;
i = -1;
while (++i < 4)
{
xx = x + mv[i];
yy = y + mv[i + 4];
if (xx >= 0 && xx < map->width && yy >= 0 && yy < map->hight)
{
if (!*(map->visited + xx + yy * map->width)
&& *(map->map + xx + yy * map->width) == EMPTY_CHR)
map->invalid |= ERR_MAP;
if (!*(map->visited + xx + yy * map->width)
&& ft_strchr("SWEN02", *(map->map + xx + yy * map->width)))
dfs(map, mv, xx, yy);
}
}
}