15static bool is_enclosed_on_remaining_area(
16 t_map *map,
bool **visited)
22 while (y < map->height)
25 while (x < map->width)
27 if (map->data[y][x] ==
'0' && visited[y][x] ==
false)
28 if (flood_fill(map, x, y, (
bool **)visited) !=
true)
37static bool **init_visited(
t_map *map)
42 visited = (
bool **)malloc((
size_t)map->height *
sizeof(
bool *));
44 while (i < (
size_t)map->height)
46 visited[i] = (
bool *)ft_calloc((
size_t)map->width,
sizeof(bool));
49 return ((
bool **)visited);
52void free_visited(
bool **visited,
size_t size)
57 while (i < (
size_t)size)
65static t_bool process_false_or_error(t_bool is_surrounded,
66 bool **visited,
size_t size)
68 if (is_surrounded == ENUM_FALSE)
70 free_visited(visited, size);
71 ft_eprintf(
"%s%s\n", ERR_PROMPT, EMSG_MAP_NOT_ENCLOSED);
73 return (is_surrounded);
84int check_enclosed_by_walls(
const char *line,
t_parse *parse)
92 visited = init_visited(&parse->game->map);
94 return (EXIT_FAILURE);
95 start_x = parse->player_grid.x;
96 start_y = parse->player_grid.y;
97 map = &parse->game->map;
98 is_surrounded = ENUM_TRUE;
99 is_surrounded = flood_fill(map, start_x, start_y, visited);
100 if (process_false_or_error(is_surrounded, visited, (
size_t)map->height)
102 return (EXIT_FAILURE);
103 is_surrounded = is_enclosed_on_remaining_area(map, visited);
104 if (process_false_or_error(is_surrounded, visited, (
size_t)map->height)
106 return (EXIT_FAILURE);
107 free_visited(visited, (
size_t)map->height);
109 return (EXIT_SUCCESS);