almost finished norm

This commit is contained in:
Theo Champion 2025-06-21 00:17:09 +02:00
parent 977385492b
commit b185cddbf0

View file

@ -6,7 +6,7 @@
/* By: tchampio <tchampio@student.42lehavre. +#+ +:+ +#+ */ /* By: tchampio <tchampio@student.42lehavre. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/06/06 17:54:42 by tchampio #+# #+# */ /* Created: 2025/06/06 17:54:42 by tchampio #+# #+# */
/* Updated: 2025/06/20 19:53:53 by tchampio ### ########.fr */ /* Updated: 2025/06/21 00:10:08 by tchampio ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -227,20 +227,20 @@ bool check_walls(t_mapdata *map)
{ {
int i; int i;
int j; int j;
int line_length;
i = 0; i = 0;
while (i < map->mapheight) while (i < map->mapheight)
{ {
j = 0; j = 0;
line_length = ft_strlen(map->map[i]);
while (map->map[i][j] == ' ') while (map->map[i][j] == ' ')
j++; j++;
if (map->map[i][j] != '1' && map->map[i][line_length - 1] != '1') if (map->map[i][j] != '1'
&& map->map[i][ft_strlen(map->map[i]) - 1] != '1')
return (false); return (false);
if (i == 0 || i == map->mapheight - 1) if (i == 0 || i == map->mapheight - 1)
{ {
while (map->map[i][j] == '1' || map->map[i][j] == ' ' || map->map[i][j] == '\n') while (map->map[i][j] == '1' || map->map[i][j] == ' '
|| map->map[i][j] == '\n')
j++; j++;
if (ft_strlen(map->map[i]) != (unsigned int)j) if (ft_strlen(map->map[i]) != (unsigned int)j)
return (false); return (false);
@ -252,7 +252,7 @@ bool check_walls(t_mapdata *map)
return (true); return (true);
} }
void print_map(char **map) void print_map(char **map)
{ {
int i; int i;
@ -311,7 +311,8 @@ bool check_cubfile(char *file, t_mapdata *map)
populate_maps(map, fd); populate_maps(map, fd);
if (!check_walls(map)) if (!check_walls(map))
return (close(fd), ft_strlcpy(map->error, return (close(fd), ft_strlcpy(map->error,
"Map is malformed (invalid chars or missing walls)", 51), false); "Map is malformed (invalid chars or missing walls)", 51),
false);
if (!check_bare_minimum(map)) if (!check_bare_minimum(map))
return (close(fd), false); return (close(fd), false);
return (true); return (true);