106 lines
2.4 KiB
C
106 lines
2.4 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* parsing.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2023/01/05 20:14:44 by cchauvet #+# #+# */
|
|
/* Updated: 2023/01/08 12:18:52 by cchauvet ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "solong.h"
|
|
|
|
int ft_test_map_dimmention(t_map *map)
|
|
{
|
|
size_t i;
|
|
size_t len;
|
|
|
|
len = ft_strlen(map->patern[0]);
|
|
i = 1;
|
|
while (map->patern[i] != NULL)
|
|
{
|
|
if (ft_strlen(map->patern[i]) != len)
|
|
return (0);
|
|
i++;
|
|
}
|
|
map->x_len = len;
|
|
map->y_len = i;
|
|
return (1);
|
|
}
|
|
|
|
int ft_test_map_content1(t_map *map)
|
|
{
|
|
size_t x;
|
|
size_t y;
|
|
size_t nb_collectable;
|
|
|
|
nb_collectable = 0;
|
|
y = 0;
|
|
while (y < map->y_len)
|
|
{
|
|
x = 0;
|
|
while (x < map->x_len)
|
|
{
|
|
if (ft_is_in("01CEP", map->patern[y][x]) == 0)
|
|
return (0);
|
|
if (map->patern[y][x] == 'C')
|
|
nb_collectable++;
|
|
x++;
|
|
}
|
|
y++;
|
|
}
|
|
if (nb_collectable == 0)
|
|
return (0);
|
|
map->nb_collectable = nb_collectable;
|
|
return (1);
|
|
}
|
|
|
|
int ft_test_map_content2(t_map *map)
|
|
{
|
|
ssize_t cord[2];
|
|
|
|
cord[1] = -1;
|
|
while ((size_t) ++cord[1] < map->y_len)
|
|
{
|
|
cord[0] = -1;
|
|
while ((size_t) ++cord[0] < map->x_len)
|
|
{
|
|
if (map->patern[cord[1]][cord[0]] == 'E')
|
|
{
|
|
map->exit[0] = cord[0];
|
|
map->exit[1] = cord[1];
|
|
map->exit[2]++;
|
|
}
|
|
else if (map->patern[cord[1]][cord[0]] == 'P')
|
|
{
|
|
map->player_pos[0] = cord[0];
|
|
map->player_pos[1] = cord[1];
|
|
map->player_pos[2]++;
|
|
}
|
|
}
|
|
}
|
|
if (map->player_pos[2] == 1 && map->exit[2] == 1)
|
|
return (1);
|
|
return (0);
|
|
}
|
|
|
|
int ft_test_map_is_finishable(t_map map)
|
|
{
|
|
(void) map;
|
|
return (1);
|
|
}
|
|
|
|
int ft_map_is_correct(t_map *map)
|
|
{
|
|
int i;
|
|
|
|
i = ft_test_map_dimmention(map);
|
|
i += ft_test_map_content1(map);
|
|
i += ft_test_map_content2(map);
|
|
i += ft_test_map_dimmention(map);
|
|
i += ft_test_map_is_finishable(*map);
|
|
return (i == 5);
|
|
}
|