From 06e47c03093e103ab222db9804474ee851ddfa4e Mon Sep 17 00:00:00 2001 From: Baptiste Goulard coderc de lacam Date: Fri, 20 Dec 2024 16:56:04 +0100 Subject: [PATCH] Fix: fix on multiple player catch + traverse map ' ' != wall --- includes/cub3d_struct.h | 3 ++- parsing/load_tiles.c | 22 +++++++++------------- parsing/traverse_map.c | 4 ++-- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/includes/cub3d_struct.h b/includes/cub3d_struct.h index c788560..3bc24e9 100644 --- a/includes/cub3d_struct.h +++ b/includes/cub3d_struct.h @@ -6,7 +6,7 @@ /* By: bgoulard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/11/28 13:53:54 by bgoulard #+# #+# */ -/* Updated: 2024/12/20 15:42:21 by bgoulard ### ########.fr */ +/* Updated: 2024/12/20 16:54:34 by bgoulard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -72,6 +72,7 @@ typedef enum e_tile { EMPTY = 0, WALL = 1, + WALL_ERR = 3, NONE = 2 } t_tile_type; diff --git a/parsing/load_tiles.c b/parsing/load_tiles.c index fcaf4af..1a17126 100644 --- a/parsing/load_tiles.c +++ b/parsing/load_tiles.c @@ -6,7 +6,7 @@ /* By: bgoulard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/12/01 17:47:15 by bgoulard #+# #+# */ -/* Updated: 2024/12/20 16:35:03 by bgoulard ### ########.fr */ +/* Updated: 2024/12/20 16:54:12 by bgoulard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -29,8 +29,10 @@ int str_to_tile(const char *str, t_tile *tile, size_t size) i = 0; while (str[i]) { - if (str[i] == '1' || str[i] == ' ') + if (str[i] == '1') tile[i].tile_type = WALL; + else if (str[i] == ' ') + tile[i].tile_type = WALL_ERR; else if (!ft_strchr("0NSWE", str[i])) return (-1); else @@ -69,28 +71,22 @@ t_vector *load_vector(t_map *map) static bool multiple_player_same_line(const char *str) { - const bool p_symbol[8] = {\ - !ft_strchr(str, 'S'), !ft_strchr(str, 'E'), !ft_strchr(str, 'W'), \ - !ft_strchr(str, 'N'), !(ft_strrchr(str, 'N') - ft_strchr(str, 'N')), \ - !(ft_strrchr(str, 'E') - ft_strchr(str, 'E')), \ - !(ft_strrchr(str, 'W') - ft_strchr(str, 'W')), \ - !(ft_strrchr(str, 'S') - ft_strchr(str, 'S')), }; + const char *identifiers = "NEWS"; int i; int j; i = 0; while (i < 4) { + if (ft_strchr(str, identifiers[i]) != ft_strrchr(str, identifiers[i])) + return (true); j = i + 1; while (j < 4) - if (!p_symbol[j++] && !p_symbol[i]) + if (ft_strchr(str, identifiers[j++]) && \ + ft_strchr(str, identifiers[i])) return (true); i++; } - i = 0; - while (i < 4) - if (p_symbol[i++ + 4] && !p_symbol[i]) - return (true); return (false); } diff --git a/parsing/traverse_map.c b/parsing/traverse_map.c index 8444880..8ae1105 100644 --- a/parsing/traverse_map.c +++ b/parsing/traverse_map.c @@ -6,7 +6,7 @@ /* By: bgoulard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/12/01 17:49:12 by bgoulard #+# #+# */ -/* Updated: 2024/12/20 14:49:43 by bgoulard ### ########.fr */ +/* Updated: 2024/12/20 16:54:55 by bgoulard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -33,7 +33,7 @@ bool flood_fill(t_tile *tiles, t_ipoint pos, t_ipoint maxs) current = c3_get_cell(tiles, maxs, pos); if (current->tile_visited == true || current->tile_type == WALL) return (true); - if (current->tile_type == NONE) + if (current->tile_type == NONE || current->tile_type == WALL_ERR) return (false); current->tile_visited = true; i = 0;