42_solong/parsing2.c

57 lines
1.7 KiB
C
Raw Normal View History

2023-01-13 09:10:27 -05:00
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parsing2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/12 16:17:20 by cchauvet #+# #+# */
/* Updated: 2023/01/13 14:48:02 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "solong.h"
static void ft_collector(char **patern, size_t x, size_t y)
{
if (patern[y][x] == '1')
return ;
patern[y][x] = '1';
ft_collector(patern, y - 1, x);
ft_collector(patern, y, x + 1);
ft_collector(patern, y + 1, x);
ft_collector(patern, y, x - 1);
ft_printf("%S\n", patern);
}
int ft_test_map_is_finishable(t_map *map)
{
size_t i;
int ok;
char **patern2;
i = 0;
while (map->patern[i] != NULL)
i++;
patern2 = ft_calloc(i + 1, sizeof(char *));
if (patern2 == NULL)
return (0);
i = 0;
while (map->patern[i] != NULL)
{
patern2[i] = ft_strdup(map->patern[i]);
if (patern2[i] == NULL)
{
ft_cancel(patern2, i);
return (0);
}
i++;
}
patern2[i] = NULL;
ft_fill_pos(map);
ft_collector(patern2, map->player_pos[0], map->player_pos[1]);
ok = ft_test_map_content2(patern2);
ft_freer_tab_ultimate(1, patern2);
return (ok);
}