This commit is contained in:
Leo Firmin 2025-10-05 06:31:06 +02:00
parent 8eea3162d5
commit a3e025e6b9
57 changed files with 189 additions and 11 deletions

View File

@ -18,6 +18,7 @@ SRCS = $(SRCDIR)/main.c \
$(SRCDIR)/utils/utils.c \
$(SRCDIR)/utils/init.c \
$(SRCDIR)/utils/debug.c \
$(SRCDIR)/parsing/check_map.c \
INCS = $(INCDIR)/parsing.h \
$(INCDIR)/cub.h \

BIN
cub3d

Binary file not shown.

View File

@ -18,7 +18,8 @@ typedef struct s_data
//////utils/////
//utils
void ft_error(char *message);
void free_char_array(char **array);
void free_char_array(char **array);
int ft_arrlen(char **arr);
//init
int init_data(t_data *data, char *path);
void free_data(t_data *data);

View File

@ -20,7 +20,12 @@
#define ERROR_INIT_PARS "Initialization of the parsing structure failed."
#define ERROR_EMPTY "You have provided an empty file."
#define ERROR_COL "The RGB values provided are not valid."
#define ERROR_NULL_P "Player not found or multiple players."
#define ERROR_BAD_CHAR "Invalid character in map."
#define ERROR_POS "Player position not found."
#define ERROR_ALLOC "Allocation failed."
#define ERROR_PLAYER "Player not found or multiple players."
#define ERROR_CHAR "Invalid character in map."
#define ERROR_NOT_CLOSE "Map is not closed by walls."
#define DEBUG "test"
#endif

View File

@ -36,6 +36,7 @@ typedef struct s_data_parsing
char **raw_map;
int fd_map;
int fd_map_dup;
int player[3];
} t_data_parsing;
//parsing
@ -69,4 +70,7 @@ int get_rgb_values(char *line, int rgb[3]);
//check_colors
int check_colors(t_textures *texture);
int is_rgb(int color[3]);
// check_mao
int validate_map(char **map, int *player);
#endif

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

157
srcs/parsing/check_map.c Normal file
View File

@ -0,0 +1,157 @@
#include "cub.h"
int has_playable_neighbor(int x, int y, char **map)
{
if (map[y] && map[y][x + 1] &&
(map[y][x + 1] == '0' || map[y][x + 1] == 'N' ||
map[y][x + 1] == 'S' || map[y][x + 1] == 'E' ||
map[y][x + 1] == 'W'))
return (1);
if (x > 0 && map[y][x - 1] &&
(map[y][x - 1] == '0' || map[y][x - 1] == 'N' ||
map[y][x - 1] == 'S' || map[y][x - 1] == 'E' ||
map[y][x - 1] == 'W'))
return (1);
if (map[y + 1] && map[y + 1][x] &&
(map[y + 1][x] == '0' || map[y + 1][x] == 'N' ||
map[y + 1][x] == 'S' || map[y + 1][x] == 'E' ||
map[y + 1][x] == 'W'))
return (1);
if (y > 0 && map[y - 1] && map[y - 1][x] &&
(map[y - 1][x] == '0' || map[y - 1][x] == 'N' ||
map[y - 1][x] == 'S' || map[y - 1][x] == 'E' ||
map[y - 1][x] == 'W'))
return (1);
return (0);
}
int check_isolated_walls(char **map)
{
int i = 0;
int j;
while (map[i])
{
j = 0;
while (map[i][j])
{
if (map[i][j] == '1')
{
if (!has_playable_neighbor(j, i, map))
return (0); // '1' isolé détecté
}
j++;
}
i++;
}
return (1); // Pas de '1' isolé
}
int check_map_char(char **map)
{
int i = 0;
int j;
int p = 0;
while (map[i])
{
j = 0;
while (map[i][j])
{
if (map[i][j] == '1' || map[i][j] == '0' ||
map[i][j] == ' ' || map[i][j] == '\n')
j++;
else if (map[i][j] == 'S' || map[i][j] == 'N' ||
map[i][j] == 'E' || map[i][j] == 'W')
{
j++;
p++;
}
else
return (2);
}
i++;
}
if (p != 1)
return (1);
return (0);
}
void find_player_pos(char **map, int *player)
{
int i = 0;
int j;
while (map[i])
{
j = 0;
while (map[i][j])
{
if (map[i][j] == 'S' || map[i][j] == 'N' ||
map[i][j] == 'E' || map[i][j] == 'W')
{
player[0] = j;
player[1] = i;
player[2] = map[i][j];
return;
}
j++;
}
i++;
}
}
int is_closed_at(int x, int y, char **map)
{
if (!map[y] || !map[y][x] || map[y][x] == '\0')
return (0);
if (map[y][x] == ' ')
return (0);
return (1);
}
int check_walls(char **map)
{
int i = 0;
int j;
while (map[i])
{
j = 0;
while (map[i][j])
{
if (map[i][j] == '0' || map[i][j] == 'N' ||
map[i][j] == 'S' || map[i][j] == 'E' || map[i][j] == 'W')
{
if (!is_closed_at(j + 1, i, map) ||
!is_closed_at(j - 1, i, map) ||
!is_closed_at(j, i + 1, map) ||
!is_closed_at(j, i - 1, map))
return (0);
}
j++;
}
i++;
}
return (1);
}
int validate_map(char **map, int *player)
{
int result;
result = check_map_char(map);
if (result == 1)
return (ft_error(ERROR_PLAYER), 1);
if (result == 2)
return (ft_error(ERROR_CHAR), 1);
find_player_pos(map, player);
if (!check_walls(map))
return (ft_error(ERROR_NOT_CLOSE), 1);
// if (!check_isolated_walls(map))
// return (ft_error("Isolated wall detected"), 1);
return (0);
}

View File

@ -20,5 +20,7 @@ int parsing(t_data *data)
close(data->parsing.fd_map_dup);
if (check_colors(data->texture) == 1)
return (1);
if (validate_map(data->parsing.raw_map, data->parsing.player) == 0)
return (1);
return (0);
}

View File

@ -32,4 +32,3 @@ void free_data(t_data *data)
if (data->texture)
free(data->texture);
}

View File

@ -35,3 +35,11 @@ void free_char_array(char **array)
free(array[i++]);
free(array);
}
int ft_arrlen(char **arr)
{
int i;
while(arr[i])
i++;
return (i);
}

View File

@ -18,16 +18,17 @@ NO textures/test/north.xpm
WE textures/test/west.xpm
C 200,200,200
11111
10001
F 200,200,200
11
1001
10S01
10001
10001
10001
11001
10101
10001
10001
10001
10001
10001
11111
10001
10001
11