From af4075e546ecc25f0572099e95472c10e9a93f2b Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Wed, 4 Mar 2020 02:14:19 +0100 Subject: chek --- src/ft_check_map_surrounds.c | 31 ++++++++++++++++++++++++------- src/ft_parse_map.c | 2 +- 2 files changed, 25 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/ft_check_map_surrounds.c b/src/ft_check_map_surrounds.c index 8c38a85..fbe2ff8 100644 --- a/src/ft_check_map_surrounds.c +++ b/src/ft_check_map_surrounds.c @@ -15,13 +15,35 @@ #include #include +static int8_t + ft_wall_check(size_t y, size_t x, char** const map) +{ + if (map[y + 1][x] == ' ' || + map[y - 1][x] == ' ' || + map[y][x + 1] == ' ' || + map[y][x - 1] == ' ' || + map[y + 1][x + 1] == ' ' || + map[y - 1][x + 1] == ' ' || + map[y + 1][x - 1] == ' ' || + map[y - 1][x - 1] == ' ' || + map[y + 1][x] == '\0' || + map[y - 1][x] == '\0' || + map[y][x + 1] == '\0' || + map[y][x - 1] == '\0' || + map[y + 1][x + 1] == '\0' || + map[y - 1][x + 1] == '\0' || + map[y + 1][x - 1] == '\0' || + map[y - 1][x - 1] == '\0') + return (-1); + return (0); +} + void ft_check_map_surrounds(t_map *ml, t_cub *cl) { size_t y; size_t x; - (void)ml; y = 0; x = 0; while (ml->map[y]) @@ -30,12 +52,7 @@ void { if (ft_ischarset("02NESWL", ml->map[y][x])) { - if ( - ft_ischarset(" \0", ml->map[y + 1][x]) || - ft_ischarset(" \0", ml->map[y - 1][x]) || - ft_ischarset(" \0", ml->map[y][x + 1]) || - ft_ischarset(" \0", ml->map[y][x - 1]) - ) + if (ft_wall_check(y, x, ml->map) < 0) ft_map_error(FT_ERR_MAP_WALLS, cl); } x++; diff --git a/src/ft_parse_map.c b/src/ft_parse_map.c index eb62f3f..2d5590e 100644 --- a/src/ft_parse_map.c +++ b/src/ft_parse_map.c @@ -65,7 +65,7 @@ static int8_t } if (ft_ischarset("1 ", line[0])) return ((ft_get_map_first_line(line, clist) < 0) ? (-1) : (12)); - if (!ft_ischarset("RNSEWFCLM\0", line[0]) + if (!ft_ischarset("RNSEWFCLM", line[0]) || !(words = ft_split(line, ' '))) return (ft_error_here(FT_ERR_ILL_ENTRY, line, clist)); if ((ret = ft_select_get(words, clist)) == 12) -- cgit v1.2.3