42_solong/bonus/parsing2.c

74 lines
2.0 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 #+# #+# */
2023-01-16 13:01:46 -05:00
/* Updated: 2023/01/16 18:48:20 by cchauvet ### ########.fr */
2023-01-13 09:10:27 -05:00
/* */
/* ************************************************************************** */
#include "solong.h"
static void ft_collector(char **patern, size_t x, size_t y)
{
2023-01-16 13:01:46 -05:00
if (ft_is_in("1B", patern[y][x]))
return ;
2023-01-13 09:10:27 -05:00
patern[y][x] = '1';
2023-01-13 10:10:11 -05:00
ft_collector(patern, x, y - 1);
ft_collector(patern, x + 1, y);
ft_collector(patern, x, y + 1);
ft_collector(patern, x - 1, y);
2023-01-13 09:10:27 -05:00
}
2023-01-13 10:10:11 -05:00
static char **ft_patern_dup(char **patern)
2023-01-13 09:10:27 -05:00
{
char **patern2;
2023-01-13 10:10:11 -05:00
size_t i;
2023-01-13 09:10:27 -05:00
i = 0;
2023-01-13 10:10:11 -05:00
while (patern[i] != NULL)
2023-01-13 09:10:27 -05:00
i++;
patern2 = ft_calloc(i + 1, sizeof(char *));
if (patern2 == NULL)
return (0);
i = 0;
2023-01-13 10:10:11 -05:00
while (patern[i] != NULL)
2023-01-13 09:10:27 -05:00
{
2023-01-13 10:10:11 -05:00
patern2[i] = ft_strdup(patern[i]);
2023-01-13 09:10:27 -05:00
if (patern2[i] == NULL)
{
ft_cancel(patern2, i);
2023-01-13 10:10:11 -05:00
return (NULL);
2023-01-13 09:10:27 -05:00
}
i++;
}
patern2[i] = NULL;
2023-01-13 10:10:11 -05:00
return (patern2);
}
2023-01-13 10:28:54 -05:00
2023-01-13 10:10:11 -05:00
int ft_test_map_is_finishable(t_map *map)
{
size_t i;
int ok;
char **patern;
patern = ft_patern_dup(map->patern);
if (patern == NULL)
return (1);
2023-01-13 09:10:27 -05:00
ft_fill_pos(map);
2023-01-13 10:10:11 -05:00
ft_collector(patern, map->player_pos[0], map->player_pos[1]);
i = 1;
ok = 1;
while (patern[i + 1] != NULL)
{
if (ft_is_in(patern[i], 'C') || ft_is_in(patern[i], 'E'))
ok = 0;
i++;
}
ft_freer_tab_ultimate(1, patern);
2023-01-13 09:10:27 -05:00
return (ok);
}