Skip to content

Commit

Permalink
refactor: validation functions to include check for valid characters …
Browse files Browse the repository at this point in the history
…in the map
  • Loading branch information
Nathalia Vitoria Buchholz committed Feb 5, 2025
1 parent e7c657c commit e64e485
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
12 changes: 8 additions & 4 deletions src/utils_validation_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: nbuchhol <nbuchhol@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/24 13:55:48 by nbuchhol #+# #+# */
/* Updated: 2025/02/03 13:41:49 by nbuchhol ### ########.fr */
/* Updated: 2025/02/05 12:53:23 by nbuchhol ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -28,6 +28,11 @@ int count_lines(int file)
return (lines);
}

static int is_valid_char(char c)
{
return (ft_strchr("EPC10", c) != NULL);
}

int valid_chars(t_game game)
{
size_t y;
Expand All @@ -37,9 +42,9 @@ int valid_chars(t_game game)
while (y < game.map_h)
{
x = 0;
while (x < game.map_w)
while (x < game.map_w - 1)
{
if (!ft_strchr("EPC10", game.map[y][x]))
if (!is_valid_char(game.map[y][x]))
return (1);
x++;
}
Expand All @@ -56,5 +61,4 @@ int valid_chars(t_game game)
// int is_all_wall()
// {
// //comprimento -2 => linhas do meio => checar primeira e última posição do x

// }
4 changes: 2 additions & 2 deletions src/validate_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: nbuchhol <nbuchhol@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/09 09:58:46 by nbuchhol #+# #+# */
/* Updated: 2025/02/03 17:39:21 by nbuchhol ### ########.fr */
/* Updated: 2025/02/05 12:40:16 by nbuchhol ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -26,7 +26,7 @@ int valid_map(char *map_file)
game.map = load_map(map_fd, &game);
if (!game.map)
close_game(map_fd, game.map, 2);
if (is_rectangle(game))
if (is_rectangle(game) || valid_chars(game))
close_game(map_fd, game.map, 2);
return (0);
}
Expand Down

0 comments on commit e64e485

Please sign in to comment.