From 18afe258077dd3a86284cd43245c920d88ff80e9 Mon Sep 17 00:00:00 2001 From: Maelys Date: Wed, 11 Sep 2024 22:20:37 +0200 Subject: [PATCH] =?UTF-8?q?=E3=80=8C=F0=9F=8F=97=EF=B8=8F=E3=80=8D=20wip:?= =?UTF-8?q?=20parsing=20map=20nighty=20percent=20done?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 6 ++- src/cub3d.c | 6 ++- src/parsing/check_arg.c | 3 +- src/parsing/check_map.c | 84 +++++++++++++++++++++++++++++++++++----- src/parsing/memo_parsing | 2 +- src/utils/parse_utils.c | 10 ++++- 6 files changed, 94 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index 08c4959..c00c275 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,11 @@ MACRO_DIR = MacroLibX/ INCLUDE = -I $(I_DIR) -I $(LIBFT_DIR)/$(I_DIR) -I $(MACRO_DIR)/$(I_DIR) -SRCS = $(shell find src -name '*.c') +SRCS = src/utils/mess_error.c \ + src/utils/parse_utils.c \ + src/parsing/check_map.c \ + src/parsing/check_arg.c \ + src/cub3d.c OBJS = $(addprefix $(OBJSDIR), $(SRCS:.c=.o)) diff --git a/src/cub3d.c b/src/cub3d.c index 91172c7..9b326ec 100644 --- a/src/cub3d.c +++ b/src/cub3d.c @@ -6,7 +6,7 @@ /* By: madumerg +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/09/04 16:58:27 by madumerg #+# #+# */ -/* Updated: 2024/09/11 14:53:49 by madumerg ### ########.fr */ +/* Updated: 2024/09/11 22:16:46 by madumerg ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,9 +14,11 @@ int main(int ac, char **av) { + char **map; + if (check_err_arg(ac, av) == 1) return (1); - char **map = parse_map(av[1]); + map = parse_map(av[1]); if (verif_all_map(map) == 1) return (1); return (0); diff --git a/src/parsing/check_arg.c b/src/parsing/check_arg.c index adea941..521549e 100644 --- a/src/parsing/check_arg.c +++ b/src/parsing/check_arg.c @@ -6,7 +6,7 @@ /* By: madumerg +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/09/04 21:33:35 by madumerg #+# #+# */ -/* Updated: 2024/09/11 11:19:25 by madumerg ### ########.fr */ +/* Updated: 2024/09/11 22:12:13 by madumerg ### ########.fr */ /* */ /* ************************************************************************** */ @@ -43,4 +43,3 @@ int check_format_file(char *file) return (1); return (0); } - diff --git a/src/parsing/check_map.c b/src/parsing/check_map.c index 9b543b8..c838ebf 100644 --- a/src/parsing/check_map.c +++ b/src/parsing/check_map.c @@ -6,23 +6,89 @@ /* By: madumerg +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/09/11 11:24:13 by madumerg #+# #+# */ -/* Updated: 2024/09/11 15:24:53 by madumerg ### ########.fr */ +/* Updated: 2024/09/11 22:14:44 by madumerg ### ########.fr */ /* */ /* ************************************************************************** */ #include "cub3d.h" +int err_not_close(char after, char before, char down, char up) +{ + if (after == ' ' || after == '\0') + return (1); + else if (before == ' ' || before == '\0') + return (1); + else if (down == ' ' || down == '\0') + return (1); + else if (up == ' ' || up == '\0') + return (1); + return (0); +} + +int actual_char(char actual) +{ + if (actual == '0' || actual == 'N' || actual == 'W' || \ + actual == 'S' || actual == 'E') + return (0); + return (1); +} + +int check_map_close(char **map) +{ + int y; + int x; + + y = 0; + while (map[y]) + { + x = 0; + while (map[y][x]) + { + if (actual_char(map[y][x]) == 0 && \ + (err_not_close(map[y][x + 1], map[y][x - 1], \ + map[y + 1][x], map[y - 1][x]) == 1)) + return (1); + else + x++; + } + y++; + } + return (0); +} + +int count_player(char **map) +{ + int y; + int x; + int cpt; + + cpt = 0; + y = 0; + while (map[y]) + { + x = 0; + while (map[y][x]) + { + if (map[y][x] == 'N' || map[y][x] == 'S' || \ + map[y][x] == 'E' || map[y][x] == 'W') + cpt++; + x++; + } + y++; + } + if (cpt != 1) + return (1); + return (0); +} + int verif_all_map(char **map) { if (check_char_map(map) == 1) return (err_mess(WRONG_CHAR)); - return (0); -} - -int verif_char(char c) -{ - if (c != '1' && c != '0' && c != 'N' && c != 'S' && c != 'W' && c != 'E' && c != ' ') - return (1); + if (count_player(map) == 1) + return (err_mess(ERR_PLAYER)); + if (check_map_close(map) == 1) + return (err_mess(NOT_CLOSE)); return (0); } @@ -70,5 +136,3 @@ char **parse_map(char *map) close(fd); return (parse_map); } - - diff --git a/src/parsing/memo_parsing b/src/parsing/memo_parsing index 415f036..c207192 100644 --- a/src/parsing/memo_parsing +++ b/src/parsing/memo_parsing @@ -12,7 +12,7 @@ //envoyer de 4 a 5 inclus dans check rgb format //envoyer de 6 a jusqu a la fin dans check map - // convertir tt les whites spaces en simple espace + // convertir tt les whites spaces en simple espace //prblm avec les tab struct typedef s_pars { diff --git a/src/utils/parse_utils.c b/src/utils/parse_utils.c index e60c690..8ef46ef 100644 --- a/src/utils/parse_utils.c +++ b/src/utils/parse_utils.c @@ -6,7 +6,7 @@ /* By: madumerg +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/09/11 14:20:54 by madumerg #+# #+# */ -/* Updated: 2024/09/11 14:31:27 by madumerg ### ########.fr */ +/* Updated: 2024/09/11 22:15:23 by madumerg ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,3 +24,11 @@ void convert_white_s(char *str) i++; } } + +int verif_char(char c) +{ + if (c != '1' && c != '0' && c != 'N' && c != 'S' && c != 'W' && \ + c != 'E' && c != ' ') + return (1); + return (0); +}