push3
This commit is contained in:
parent
a3e025e6b9
commit
2fa3015af4
5
Makefile
5
Makefile
|
|
@ -1,5 +1,5 @@
|
||||||
CC = gcc
|
CC = gcc
|
||||||
CFLAGS = -Wall -Wextra -Werror
|
CFLAGS = -fsanitize=address -g -Wall -Wextra -Werror
|
||||||
NAME = cub3d
|
NAME = cub3d
|
||||||
|
|
||||||
SRCDIR = srcs
|
SRCDIR = srcs
|
||||||
|
|
@ -17,12 +17,11 @@ SRCS = $(SRCDIR)/main.c \
|
||||||
$(SRCDIR)/parsing/check_colors.c \
|
$(SRCDIR)/parsing/check_colors.c \
|
||||||
$(SRCDIR)/utils/utils.c \
|
$(SRCDIR)/utils/utils.c \
|
||||||
$(SRCDIR)/utils/init.c \
|
$(SRCDIR)/utils/init.c \
|
||||||
$(SRCDIR)/utils/debug.c \
|
|
||||||
$(SRCDIR)/parsing/check_map.c \
|
$(SRCDIR)/parsing/check_map.c \
|
||||||
|
$(SRCDIR)/parsing/check_map_2.c \
|
||||||
|
|
||||||
INCS = $(INCDIR)/parsing.h \
|
INCS = $(INCDIR)/parsing.h \
|
||||||
$(INCDIR)/cub.h \
|
$(INCDIR)/cub.h \
|
||||||
$(INCDIR)/messages.h \
|
|
||||||
|
|
||||||
all: $(NAME)
|
all: $(NAME)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,9 +16,8 @@ INCS_DIR = includes/
|
||||||
OBJ_DIR = obj/
|
OBJ_DIR = obj/
|
||||||
|
|
||||||
SRC = get_next_line.c get_next_line_utils.c
|
SRC = get_next_line.c get_next_line_utils.c
|
||||||
|
|
||||||
CC = cc
|
CC = cc
|
||||||
CFLAGS = -Wall -Wextra -Werror
|
CFLAGS = -Wall -Wextra -Werror -fPIE
|
||||||
INCLUDE = -I $(INCS_DIR)
|
INCLUDE = -I $(INCS_DIR)
|
||||||
SRCS = $(addprefix $(SRCS_DIR), $(SRC))
|
SRCS = $(addprefix $(SRCS_DIR), $(SRC))
|
||||||
OBJ = $(addprefix $(OBJ_DIR), $(SRC:.c=.o))
|
OBJ = $(addprefix $(OBJ_DIR), $(SRC:.c=.o))
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
|
|
@ -1,11 +1,40 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* cub.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/08/22 14:56:25 by lfirmin #+# #+# */
|
||||||
|
/* Updated: 2025/10/07 12:14:42 by lfirmin ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
#ifndef CUB_H
|
#ifndef CUB_H
|
||||||
#define CUB_H
|
|
||||||
|
|
||||||
#include "parsing.h"
|
# define CUB_H
|
||||||
#include "messages.h"
|
|
||||||
#include "../libft/include/libft.h"
|
# include "parsing.h"
|
||||||
#include "../gnl/include/get_next_line.h"
|
# include "../libft/include/libft.h"
|
||||||
|
# include "../gnl/include/get_next_line.h"
|
||||||
|
|
||||||
|
# define ERROR_PREFIX "Error\n"
|
||||||
|
# define ERROR_EXT "Invalid file extension. Only .cub files are accepted."
|
||||||
|
# define ERROR_EMPT_PATH "Invalid map file path."
|
||||||
|
# define ERROR_INIT_DATA "Initialization of the data structure failed."
|
||||||
|
# define ERROR_INIT_TEX "Initialization of the textures structure failed."
|
||||||
|
# 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 or absent."
|
||||||
|
# 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_DOUBLE "Multiple images/colors have been provided \
|
||||||
|
for the same texture."
|
||||||
|
# define ERROR_NOT_CLOSE "Map is not closed by walls."
|
||||||
|
# define ERROR_NOT_XMP "The texture file is not an xpm image."
|
||||||
|
|
||||||
typedef struct s_data
|
typedef struct s_data
|
||||||
{
|
{
|
||||||
|
|
@ -15,16 +44,14 @@ typedef struct s_data
|
||||||
t_data_parsing parsing;
|
t_data_parsing parsing;
|
||||||
} t_data;
|
} t_data;
|
||||||
|
|
||||||
//////utils/////
|
|
||||||
//utils
|
//utils
|
||||||
void ft_error(char *message);
|
void ft_error(char *message);
|
||||||
void free_char_array(char **array);
|
void free_char_array(char **array);
|
||||||
int ft_arrlen(char **arr);
|
int ft_arrlen(char **arr);
|
||||||
|
void print_array(char **array);//temp
|
||||||
|
|
||||||
//init
|
//init
|
||||||
int init_data(t_data *data, char *path);
|
int init_data(t_data *data, char *path);
|
||||||
void free_data(t_data *data);
|
void free_data(t_data *data);
|
||||||
|
|
||||||
/////debug
|
|
||||||
void print_char_array_debug(char **arr, char *name);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -1,31 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* messages.h :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2025/08/22 15:00:45 by lfirmin #+# #+# */
|
|
||||||
/* Updated: 2025/08/22 15:01:20 by lfirmin ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#ifndef MESSAGE_H
|
|
||||||
#define MESSAGE_H
|
|
||||||
|
|
||||||
#define ERROR_PREFIX "\033[1m[❌]\033[0m\033[1;31mError\033[0m: "
|
|
||||||
#define ERROR_EXT "Invalid file extension. Only .cub files are accepted."
|
|
||||||
#define ERROR_EMPT_PATH "Invalid map file path."
|
|
||||||
#define ERROR_INIT_DATA "Initialization of the data structure failed."
|
|
||||||
#define ERROR_INIT_TEX "Initialization of the textures structure failed."
|
|
||||||
#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
|
|
||||||
|
|
@ -6,29 +6,29 @@
|
||||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/08/22 14:08:04 by lfirmin #+# #+# */
|
/* Created: 2025/08/22 14:08:04 by lfirmin #+# #+# */
|
||||||
/* Updated: 2025/08/22 14:18:06 by lfirmin ### ########.fr */
|
/* Updated: 2025/10/07 12:16:07 by lfirmin ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#ifndef PARSING_H
|
#ifndef PARSING_H
|
||||||
#define PARSING_H
|
# define PARSING_H
|
||||||
|
|
||||||
#include <stdio.h>
|
# include <stdio.h>
|
||||||
#include <stdlib.h>
|
# include <stdlib.h>
|
||||||
#include <unistd.h>
|
# include <unistd.h>
|
||||||
#include <fcntl.h>
|
# include <fcntl.h>
|
||||||
|
|
||||||
struct s_data;
|
struct s_data;
|
||||||
typedef struct s_data t_data;
|
typedef struct s_data t_data;
|
||||||
|
|
||||||
typedef struct s_textures
|
typedef struct s_textures
|
||||||
{
|
{
|
||||||
char *north; //Path to texture.xmp
|
char *north;
|
||||||
char *south; //Path to texture.xmp
|
char *south;
|
||||||
char *east; //Path to texture.xmp
|
char *east;
|
||||||
char *west; //Path to texture.xmp
|
char *west;
|
||||||
int floor[3]; //RGB: [0] = R, [1] = G, [2] = B
|
int floor[3];
|
||||||
int ceiling[3]; //RGB: [0] = R, [1] = G, [2] = B
|
int ceiling[3];
|
||||||
} t_textures;
|
} t_textures;
|
||||||
|
|
||||||
typedef struct s_data_parsing
|
typedef struct s_data_parsing
|
||||||
|
|
@ -38,6 +38,7 @@ typedef struct s_data_parsing
|
||||||
int fd_map_dup;
|
int fd_map_dup;
|
||||||
int player[3];
|
int player[3];
|
||||||
} t_data_parsing;
|
} t_data_parsing;
|
||||||
|
//player -> 0 = x, 1 = y, 2 = head
|
||||||
|
|
||||||
//parsing
|
//parsing
|
||||||
int parsing(t_data *data);
|
int parsing(t_data *data);
|
||||||
|
|
@ -62,15 +63,27 @@ int is_config_line(char *line);
|
||||||
int is_empty_line(char *line);
|
int is_empty_line(char *line);
|
||||||
int is_texture_line(char *line);
|
int is_texture_line(char *line);
|
||||||
int is_color_line(char *line);
|
int is_color_line(char *line);
|
||||||
|
int check_extension_2(char *str);
|
||||||
|
|
||||||
//get_textures
|
//get_textures
|
||||||
int get_texture_path(char *line, t_textures *texture);
|
int get_texture_path(char *line, t_textures *texture, int *j);
|
||||||
|
int validate_and_convert_rgb(char **parts, int rgb[3]);
|
||||||
int get_rgb_values(char *line, int rgb[3]);
|
int get_rgb_values(char *line, int rgb[3]);
|
||||||
|
int is_valid_number(char *str);
|
||||||
|
|
||||||
//check_colors
|
//check_colors
|
||||||
int check_colors(t_textures *texture);
|
int check_colors(t_textures *texture);
|
||||||
int is_rgb(int color[3]);
|
int is_rgb(int color[3]);
|
||||||
|
|
||||||
// check_mao
|
// check_map
|
||||||
|
int check_map_char(char **map);
|
||||||
|
void find_player_pos(char **map, int *player);
|
||||||
|
int flood_fill(char **map_cp, int x, int y);
|
||||||
|
int rep_ex_wall(char **map_cp, int x, int y);
|
||||||
|
int check_char_and_count(char c, int *p);
|
||||||
|
|
||||||
|
//check_map_2
|
||||||
|
int hasivalidchar(char **map);
|
||||||
int validate_map(char **map, int *player);
|
int validate_map(char **map, int *player);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -23,7 +23,7 @@ SRC = ft_isalnum.c ft_isprint.c ft_memcmp.c ft_putchar_fd.c ft_split.c \
|
||||||
ft_lstnew_bonus.c ft_lstadd_front_bonus.c ft_lstsize_bonus.c \
|
ft_lstnew_bonus.c ft_lstadd_front_bonus.c ft_lstsize_bonus.c \
|
||||||
ft_lstlast_bonus.c ft_lstadd_back_bonus.c ft_lstdelone_bonus.c \
|
ft_lstlast_bonus.c ft_lstadd_back_bonus.c ft_lstdelone_bonus.c \
|
||||||
ft_lstclear_bonus.c ft_lstiter_bonus.c ft_lstmap_bonus.c ft_strcmp.c \
|
ft_lstclear_bonus.c ft_lstiter_bonus.c ft_lstmap_bonus.c ft_strcmp.c \
|
||||||
ft_atoll.c ft_straddchar.c ft_strcpy.c
|
ft_atoll.c ft_straddchar.c ft_strcpy.c ft_arrcpy.c
|
||||||
|
|
||||||
SRCS = $(addprefix $(SRCS_DIR), $(SRC))
|
SRCS = $(addprefix $(SRCS_DIR), $(SRC))
|
||||||
CC = cc
|
CC = cc
|
||||||
|
|
|
||||||
|
|
@ -83,6 +83,7 @@ char *ft_strmapi(char const *s, char (*f)(unsigned int, char));
|
||||||
char *ft_itoa(int n);
|
char *ft_itoa(int n);
|
||||||
char *ft_straddchar(char *str, char c);
|
char *ft_straddchar(char *str, char c);
|
||||||
char *ft_strcpy(char *dest, char *src);
|
char *ft_strcpy(char *dest, char *src);
|
||||||
|
char **ft_arrcpy(char **array);
|
||||||
|
|
||||||
t_list *ft_lstnew(void *content);
|
t_list *ft_lstnew(void *content);
|
||||||
t_list *ft_lstlast(t_list *lst);
|
t_list *ft_lstlast(t_list *lst);
|
||||||
|
|
|
||||||
BIN
libft/libft.a
BIN
libft/libft.a
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -0,0 +1,41 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_arrcpy.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: lfirmin <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2024/05/21 02:18:17 by lfirmin #+# #+# */
|
||||||
|
/* Updated: 2025/10/06 14:06:37 by lfirmin ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
char **ft_arrcpy(char **array)
|
||||||
|
{
|
||||||
|
char **copy;
|
||||||
|
int i;
|
||||||
|
int len;
|
||||||
|
|
||||||
|
len = 0;
|
||||||
|
while (array[len])
|
||||||
|
len++;
|
||||||
|
copy = malloc(sizeof(char *) * (len + 1));
|
||||||
|
if (!copy)
|
||||||
|
return (NULL);
|
||||||
|
i = 0;
|
||||||
|
while (i < len)
|
||||||
|
{
|
||||||
|
copy[i] = strdup(array[i]);
|
||||||
|
if (!copy[i])
|
||||||
|
{
|
||||||
|
while (i > 0)
|
||||||
|
free(copy[--i]);
|
||||||
|
free(copy);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
copy[i] = NULL;
|
||||||
|
return (copy);
|
||||||
|
}
|
||||||
52
srcs/main.c
52
srcs/main.c
|
|
@ -1,10 +1,60 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* main.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/08/22 14:56:25 by lfirmin #+# #+# */
|
||||||
|
/* Updated: 2025/10/08 16:25:42 by lfirmin ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
#include "cub.h"
|
#include "cub.h"
|
||||||
|
|
||||||
|
void print_int_array(int *array, int size)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (!array)
|
||||||
|
return ;
|
||||||
|
i = 0;
|
||||||
|
while (i < size)
|
||||||
|
{
|
||||||
|
ft_putnbr_fd(array[i], 1);
|
||||||
|
if (i < size - 1)
|
||||||
|
write(1, ", ", 2);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
write(1, "\n", 1);
|
||||||
|
}
|
||||||
|
void debug(t_data data)
|
||||||
|
{
|
||||||
|
printf("map:\n\n");
|
||||||
|
print_array(data.map);
|
||||||
|
printf("\n");
|
||||||
|
printf("c: ");
|
||||||
|
fflush(stdout);
|
||||||
|
print_int_array(data.texture->ceiling, 3);
|
||||||
|
printf("f: ");
|
||||||
|
fflush(stdout);
|
||||||
|
print_int_array(data.texture->floor, 3);
|
||||||
|
printf("p: ");
|
||||||
|
fflush(stdout);
|
||||||
|
print_int_array(data.parsing.player, 3);
|
||||||
|
printf("\n");
|
||||||
|
printf("\ntexture:\n\n");
|
||||||
|
printf("%s\n", data.texture->east);
|
||||||
|
printf("%s\n", data.texture->north);
|
||||||
|
printf("%s\n", data.texture->west);
|
||||||
|
printf("%s\n", data.texture->south);
|
||||||
|
}
|
||||||
int main(int ac, char **av)
|
int main(int ac, char **av)
|
||||||
{
|
{
|
||||||
t_data data;
|
t_data data;
|
||||||
|
|
||||||
init_data(&data, av[1]);
|
init_data(&data, av[1]);
|
||||||
parsing(&data);
|
if (parsing(&data));
|
||||||
|
debug(data);
|
||||||
free_char_array(data.parsing.raw_map);
|
free_char_array(data.parsing.raw_map);
|
||||||
free_textures(data.texture);
|
free_textures(data.texture);
|
||||||
free_data(&data);
|
free_data(&data);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/08/25 18:41:26 by lfirmin #+# #+# */
|
/* Created: 2025/08/25 18:41:26 by lfirmin #+# #+# */
|
||||||
/* Updated: 2025/08/25 18:41:26 by lfirmin ### ########.fr */
|
/* Updated: 2025/10/07 10:06:32 by lfirmin ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
#include "cub.h"
|
#include "cub.h"
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/08/22 15:07:29 by lfirmin #+# #+# */
|
/* Created: 2025/08/22 15:07:29 by lfirmin #+# #+# */
|
||||||
/* Updated: 2025/08/22 15:07:33 by lfirmin ### ########.fr */
|
/* Updated: 2025/10/07 10:11:50 by lfirmin ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -20,10 +20,10 @@ int check_file(char *map_path, t_data_parsing *parsing)
|
||||||
return (1);
|
return (1);
|
||||||
parsing->fd_map = open(map_path, O_RDONLY);
|
parsing->fd_map = open(map_path, O_RDONLY);
|
||||||
if (parsing->fd_map < 0)
|
if (parsing->fd_map < 0)
|
||||||
return (perror("\033[1m[❌]\033[0m\033[1;31mError\033[0m"), 1);
|
return (perror("Error\n"), 1);
|
||||||
parsing->fd_map_dup = open(map_path, O_RDONLY);
|
parsing->fd_map_dup = open(map_path, O_RDONLY);
|
||||||
if (parsing->fd_map_dup < 0)
|
if (parsing->fd_map_dup < 0)
|
||||||
return (perror("\033[1m[❌]\033[0m\033[1;31mError\033[0m"), 1);
|
return (perror("Error\n"), 1);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,74 +1,47 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* check_map.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/08/22 15:07:29 by lfirmin #+# #+# */
|
||||||
|
/* Updated: 2025/10/07 10:11:50 by lfirmin ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
#include "cub.h"
|
#include "cub.h"
|
||||||
|
|
||||||
int has_playable_neighbor(int x, int y, char **map)
|
int check_char_and_count(char c, int *p)
|
||||||
{
|
{
|
||||||
if (map[y] && map[y][x + 1] &&
|
if (c == '1' || c == '0' || c == ' ' || c == '\n')
|
||||||
(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);
|
return (0);
|
||||||
}
|
else if (c == 'S' || c == 'N' || c == 'E' || c == 'W')
|
||||||
|
|
||||||
int check_isolated_walls(char **map)
|
|
||||||
{
|
|
||||||
int i = 0;
|
|
||||||
int j;
|
|
||||||
|
|
||||||
while (map[i])
|
|
||||||
{
|
{
|
||||||
j = 0;
|
(*p)++;
|
||||||
while (map[i][j])
|
return (0);
|
||||||
{
|
|
||||||
if (map[i][j] == '1')
|
|
||||||
{
|
|
||||||
if (!has_playable_neighbor(j, i, map))
|
|
||||||
return (0); // '1' isolé détecté
|
|
||||||
}
|
}
|
||||||
j++;
|
else
|
||||||
}
|
return (2);
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (1); // Pas de '1' isolé
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int check_map_char(char **map)
|
int check_map_char(char **map)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i;
|
||||||
int j;
|
int j;
|
||||||
int p = 0;
|
int p;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
p = 0;
|
||||||
while (map[i])
|
while (map[i])
|
||||||
{
|
{
|
||||||
j = 0;
|
j = 0;
|
||||||
while (map[i][j])
|
while (map[i][j])
|
||||||
{
|
{
|
||||||
if (map[i][j] == '1' || map[i][j] == '0' ||
|
ret = check_char_and_count(map[i][j], &p);
|
||||||
map[i][j] == ' ' || map[i][j] == '\n')
|
if (ret != 0)
|
||||||
|
return (ret);
|
||||||
j++;
|
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++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
@ -79,9 +52,10 @@ int check_map_char(char **map)
|
||||||
|
|
||||||
void find_player_pos(char **map, int *player)
|
void find_player_pos(char **map, int *player)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i;
|
||||||
int j;
|
int j;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
while (map[i])
|
while (map[i])
|
||||||
{
|
{
|
||||||
j = 0;
|
j = 0;
|
||||||
|
|
@ -93,7 +67,7 @@ void find_player_pos(char **map, int *player)
|
||||||
player[0] = j;
|
player[0] = j;
|
||||||
player[1] = i;
|
player[1] = i;
|
||||||
player[2] = map[i][j];
|
player[2] = map[i][j];
|
||||||
return;
|
return ;
|
||||||
}
|
}
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
|
|
@ -101,57 +75,49 @@ void find_player_pos(char **map, int *player)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int is_closed_at(int x, int y, char **map)
|
int flood_fill(char **map_cp, int x, int y)
|
||||||
{
|
{
|
||||||
if (!map[y] || !map[y][x] || map[y][x] == '\0')
|
if (!map_cp[y] || !map_cp[y][x])
|
||||||
return (0);
|
|
||||||
if (map[y][x] == ' ')
|
|
||||||
return (0);
|
|
||||||
return (1);
|
return (1);
|
||||||
}
|
if (map_cp[y][x] == 'v')
|
||||||
|
return (0);
|
||||||
int check_walls(char **map)
|
if (map_cp[y][x] == '1')
|
||||||
{
|
|
||||||
int i = 0;
|
|
||||||
int j;
|
|
||||||
|
|
||||||
while (map[i])
|
|
||||||
{
|
{
|
||||||
j = 0;
|
map_cp[y][x] = 'v';
|
||||||
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);
|
return (0);
|
||||||
}
|
}
|
||||||
j++;
|
if (map_cp[y][x] == '0' || map_cp[y][x] == 'N' || map_cp[y][x] == 'S'
|
||||||
}
|
|| map_cp[y][x] == 'E' || map_cp[y][x] == 'W')
|
||||||
i++;
|
{
|
||||||
|
map_cp[y][x] = 'v';
|
||||||
|
if (flood_fill(map_cp, x + 1, y))
|
||||||
|
return (1);
|
||||||
|
if (flood_fill(map_cp, x - 1, y))
|
||||||
|
return (1);
|
||||||
|
if (flood_fill(map_cp, x, y + 1))
|
||||||
|
return (1);
|
||||||
|
if (flood_fill(map_cp, x, y - 1))
|
||||||
|
return (1);
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int validate_map(char **map, int *player)
|
int rep_ex_wall(char **map_cp, int x, int y)
|
||||||
{
|
{
|
||||||
int result;
|
if (y < 0 || x < 0)
|
||||||
|
return (0);
|
||||||
result = check_map_char(map);
|
if (!map_cp[y] || !map_cp[y][x])
|
||||||
if (result == 1)
|
return (0);
|
||||||
return (ft_error(ERROR_PLAYER), 1);
|
if (map_cp[y][x] == '1')
|
||||||
if (result == 2)
|
map_cp[y][x] = 'v';
|
||||||
return (ft_error(ERROR_CHAR), 1);
|
if (map_cp[y][x] == 'v')
|
||||||
|
{
|
||||||
find_player_pos(map, player);
|
map_cp[y][x] = 'c';
|
||||||
|
rep_ex_wall(map_cp, x + 1, y);
|
||||||
if (!check_walls(map))
|
rep_ex_wall(map_cp, x - 1, y);
|
||||||
return (ft_error(ERROR_NOT_CLOSE), 1);
|
rep_ex_wall(map_cp, x, y + 1);
|
||||||
// if (!check_isolated_walls(map))
|
rep_ex_wall(map_cp, x, y - 1);
|
||||||
// return (ft_error("Isolated wall detected"), 1);
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,54 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* check_map_2.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/08/22 15:07:29 by lfirmin #+# #+# */
|
||||||
|
/* Updated: 2025/10/07 12:09:03 by lfirmin ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
#include "cub.h"
|
||||||
|
|
||||||
|
int hasinvalidchar(char **map)
|
||||||
|
{
|
||||||
|
int y;
|
||||||
|
int x;
|
||||||
|
|
||||||
|
y = 0;
|
||||||
|
while (map[y])
|
||||||
|
{
|
||||||
|
x = 0;
|
||||||
|
while (map[y][x])
|
||||||
|
{
|
||||||
|
if (map[y][x] != 'c' && map[y][x] != ' ' && map[y][x] != ' '
|
||||||
|
&& map[y][x] != '\n')
|
||||||
|
return (1);
|
||||||
|
x++;
|
||||||
|
}
|
||||||
|
y++;
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int validate_map(char **map, int *player)
|
||||||
|
{
|
||||||
|
int result;
|
||||||
|
char **map_cp;
|
||||||
|
|
||||||
|
map_cp = ft_arrcpy(map);
|
||||||
|
result = check_map_char(map);
|
||||||
|
if (result == 1)
|
||||||
|
return (free_char_array(map_cp), ft_error(ERROR_PLAYER), 1);
|
||||||
|
if (result == 2)
|
||||||
|
return (free_char_array(map_cp), ft_error(ERROR_CHAR), 1);
|
||||||
|
find_player_pos(map, player);
|
||||||
|
if (flood_fill(map_cp, player[0], player[1]))
|
||||||
|
return (free_char_array(map_cp), ft_error(ERROR_NOT_CLOSE), 1);
|
||||||
|
rep_ex_wall(map_cp, player[0], player[1]);
|
||||||
|
if (hasinvalidchar(map_cp))
|
||||||
|
return (free_char_array(map_cp), ft_error(ERROR_CHAR), 1);
|
||||||
|
free_char_array(map_cp);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/08/23 13:29:28 by lfirmin #+# #+# */
|
/* Created: 2025/08/23 13:29:28 by lfirmin #+# #+# */
|
||||||
/* Updated: 2025/08/23 13:29:28 by lfirmin ### ########.fr */
|
/* Updated: 2025/10/07 10:13:07 by lfirmin ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -19,12 +19,9 @@ int get_map(t_data *data)
|
||||||
nb_line = line_counter(data->parsing.fd_map);
|
nb_line = line_counter(data->parsing.fd_map);
|
||||||
if (nb_line <= 0)
|
if (nb_line <= 0)
|
||||||
return (ft_error(ERROR_EMPTY), 1);
|
return (ft_error(ERROR_EMPTY), 1);
|
||||||
data->parsing.raw_map = ft_calloc(nb_line + 1, sizeof(char*));
|
data->parsing.raw_map = ft_calloc(nb_line + 1, sizeof(char *));
|
||||||
put_map_on_array(data);
|
if (put_map_on_array(data))
|
||||||
//print_char_array_debug(data->parsing.raw_map, "debug");
|
return (1);
|
||||||
//printf("---deb_texture---\n%s\n%s\n%s\n%s\n", data->texture->north, data->texture->south, data->texture->west, data->texture->east);
|
|
||||||
// printf("---deb_colors_f---\n%d,%d,%d\n", data->texture->floor[0], data->texture->floor[1], data->texture->floor[2]);
|
|
||||||
// printf("---deb_colors_c---\n%d,%d,%d\n", data->texture->ceiling[0], data->texture->ceiling[1], data->texture->ceiling[2]);
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -35,13 +32,15 @@ int line_counter(int fd)
|
||||||
|
|
||||||
line = NULL;
|
line = NULL;
|
||||||
nb_line = 0;
|
nb_line = 0;
|
||||||
while ((line = get_next_line(fd)) != NULL)
|
line = get_next_line(fd);
|
||||||
|
while (line != NULL)
|
||||||
{
|
{
|
||||||
nb_line++;
|
nb_line++;
|
||||||
free(line);
|
free(line);
|
||||||
|
line = get_next_line(fd);
|
||||||
}
|
}
|
||||||
free(line);
|
free(line);
|
||||||
line = get_next_line(-1); // force cleanup
|
line = get_next_line(-1);
|
||||||
free(line);
|
free(line);
|
||||||
return (nb_line);
|
return (nb_line);
|
||||||
}
|
}
|
||||||
|
|
@ -51,18 +50,28 @@ int put_map_on_array(t_data *data)
|
||||||
char *line;
|
char *line;
|
||||||
char *cleaned;
|
char *cleaned;
|
||||||
int i;
|
int i;
|
||||||
|
int j[6];
|
||||||
|
|
||||||
|
ft_memset(j, 0, sizeof(j));
|
||||||
i = 0;
|
i = 0;
|
||||||
while ((line = get_next_line(data->parsing.fd_map_dup)) != NULL)
|
while ((line = get_next_line(data->parsing.fd_map_dup)) != NULL)
|
||||||
{
|
{
|
||||||
if (is_config_line(line))
|
if (is_config_line(line))
|
||||||
{
|
{
|
||||||
cleaned = clean_line(line);
|
cleaned = clean_line(line);
|
||||||
get_texture_path(cleaned, data->texture);
|
if (get_texture_path(cleaned, data->texture, j))
|
||||||
|
{
|
||||||
|
free(line);
|
||||||
|
free(cleaned);
|
||||||
|
line = get_next_line(-1);
|
||||||
|
if (line)
|
||||||
|
free(line);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
free(line);
|
free(line);
|
||||||
free(cleaned);
|
free(cleaned);
|
||||||
}
|
}
|
||||||
else if (is_empty_line(line))
|
else if (is_empty_line(line) && i == 0)
|
||||||
free(line);
|
free(line);
|
||||||
else
|
else
|
||||||
data->parsing.raw_map[i++] = line;
|
data->parsing.raw_map[i++] = line;
|
||||||
|
|
@ -77,9 +86,9 @@ int put_map_on_array(t_data *data)
|
||||||
char *clean_line(char *raw_line)
|
char *clean_line(char *raw_line)
|
||||||
{
|
{
|
||||||
char *cleaned;
|
char *cleaned;
|
||||||
|
|
||||||
if (!raw_line)
|
if (!raw_line)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
|
||||||
cleaned = ft_strtrim(raw_line, " \t\n\r");
|
cleaned = ft_strtrim(raw_line, " \t\n\r");
|
||||||
return (cleaned);
|
return (cleaned);
|
||||||
}
|
}
|
||||||
|
|
@ -6,28 +6,68 @@
|
||||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/08/24 12:37:11 by lfirmin #+# #+# */
|
/* Created: 2025/08/24 12:37:11 by lfirmin #+# #+# */
|
||||||
/* Updated: 2025/08/24 12:37:11 by lfirmin ### ########.fr */
|
/* Updated: 2025/10/07 10:13:41 by lfirmin ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
#include "cub.h"
|
#include "cub.h"
|
||||||
|
|
||||||
int get_texture_path(char *line, t_textures *texture)
|
int get_texture_path(char *line, t_textures *texture, int *j)
|
||||||
{
|
{
|
||||||
if (is_texture_line(line) == 1)
|
if (check_extension_2(line) && !is_color_line(line))
|
||||||
|
return (ft_error(ERROR_NOT_XMP), 1);
|
||||||
|
else if (is_texture_line(line) == 1 && j[0]++ == 0)
|
||||||
texture->north = ft_strtrim(line + 2, " \t\n\r");
|
texture->north = ft_strtrim(line + 2, " \t\n\r");
|
||||||
else if (is_texture_line(line) == 2)
|
else if (is_texture_line(line) == 2 && j[1]++ == 0)
|
||||||
texture->south = ft_strtrim(line + 2, " \t\n\r");
|
texture->south = ft_strtrim(line + 2, " \t\n\r");
|
||||||
else if (is_texture_line(line) == 3)
|
else if (is_texture_line(line) == 3 && j[2]++ == 0)
|
||||||
texture->west = ft_strtrim(line + 2, " \t\n\r");
|
texture->west = ft_strtrim(line + 2, " \t\n\r");
|
||||||
else if (is_texture_line(line) == 4)
|
else if (is_texture_line(line) == 4 && j[3]++ == 0)
|
||||||
texture->east = ft_strtrim(line + 2, " \t\n\r");
|
texture->east = ft_strtrim(line + 2, " \t\n\r");
|
||||||
else if (is_color_line(line) == 1) // F
|
else if (is_color_line(line) == 1 && j[4]++ == 0)
|
||||||
get_rgb_values(line, texture->floor);
|
get_rgb_values(line, texture->floor);
|
||||||
else if (is_color_line(line) == 2) // C
|
else if (is_color_line(line) == 2 && j[5]++ == 0)
|
||||||
get_rgb_values(line, texture->ceiling);
|
get_rgb_values(line, texture->ceiling);
|
||||||
|
else
|
||||||
|
return (ft_error(ERROR_DOUBLE), 2);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int is_valid_number(char *str)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (!str || !*str)
|
||||||
|
return (0);
|
||||||
|
i = 0;
|
||||||
|
while (str[i] == ' ' || str[i] == '\t')
|
||||||
|
i++;
|
||||||
|
if (!str[i] || !(str[i] >= '0' && str[i] <= '9'))
|
||||||
|
return (0);
|
||||||
|
while (str[i] >= '0' && str[i] <= '9')
|
||||||
|
i++;
|
||||||
|
while (str[i] == ' ' || str[i] == '\t')
|
||||||
|
i++;
|
||||||
|
if (str[i] != '\0')
|
||||||
|
return (0);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int validate_and_convert_rgb(char **parts, int rgb[3])
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = -1;
|
||||||
|
while (++i < 3)
|
||||||
|
{
|
||||||
|
if (!is_valid_number(parts[i]))
|
||||||
|
return (free_char_array(parts), 1);
|
||||||
|
rgb[i] = ft_atoi(parts[i]);
|
||||||
|
if (rgb[i] < 0 || rgb[i] > 255)
|
||||||
|
return (free_char_array(parts), 1);
|
||||||
|
}
|
||||||
|
return (free_char_array(parts), 0);
|
||||||
|
}
|
||||||
|
|
||||||
int get_rgb_values(char *line, int rgb[3])
|
int get_rgb_values(char *line, int rgb[3])
|
||||||
{
|
{
|
||||||
char *start;
|
char *start;
|
||||||
|
|
@ -43,11 +83,9 @@ int get_rgb_values(char *line, int rgb[3])
|
||||||
if (!parts)
|
if (!parts)
|
||||||
return (1);
|
return (1);
|
||||||
i = 0;
|
i = 0;
|
||||||
while (parts[i] && i < 3)
|
while (parts[i])
|
||||||
{
|
|
||||||
rgb[i] = ft_atoi(parts[i]);
|
|
||||||
i++;
|
i++;
|
||||||
}
|
if (i != 3)
|
||||||
free_char_array(parts);
|
return (free_char_array(parts), 1);
|
||||||
return (i == 3 ? 0 : 1);
|
return (validate_and_convert_rgb(parts, rgb));
|
||||||
}
|
}
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/08/23 13:33:00 by lfirmin #+# #+# */
|
/* Created: 2025/08/23 13:33:00 by lfirmin #+# #+# */
|
||||||
/* Updated: 2025/08/23 13:33:00 by lfirmin ### ########.fr */
|
/* Updated: 2025/10/07 10:14:37 by lfirmin ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
#include "cub.h"
|
#include "cub.h"
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,22 @@
|
||||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/08/24 11:58:39 by lfirmin #+# #+# */
|
/* Created: 2025/08/24 11:58:39 by lfirmin #+# #+# */
|
||||||
/* Updated: 2025/08/24 11:58:39 by lfirmin ### ########.fr */
|
/* Updated: 2025/10/08 14:05:47 by lfirmin ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "cub.h"
|
#include "cub.h"
|
||||||
|
|
||||||
|
int check_extension_2(char *str)
|
||||||
|
{
|
||||||
|
size_t len;
|
||||||
|
|
||||||
|
len = strlen(str);
|
||||||
|
if (len < 4)
|
||||||
|
return (1);
|
||||||
|
return (ft_strcmp(str + len - 4, ".xpm"));
|
||||||
|
}
|
||||||
|
|
||||||
int is_config_line(char *line)
|
int is_config_line(char *line)
|
||||||
{
|
{
|
||||||
char *trimmed;
|
char *trimmed;
|
||||||
|
|
@ -23,12 +33,12 @@ int is_config_line(char *line)
|
||||||
trimmed = ft_strtrim(line, " \t\n\r");
|
trimmed = ft_strtrim(line, " \t\n\r");
|
||||||
if (!trimmed)
|
if (!trimmed)
|
||||||
return (0);
|
return (0);
|
||||||
if (ft_strncmp(trimmed, "NO ", 3) == 0 ||
|
if (ft_strncmp(trimmed, "NO ", 3) == 0
|
||||||
ft_strncmp(trimmed, "SO ", 3) == 0 ||
|
|| ft_strncmp(trimmed, "SO ", 3) == 0
|
||||||
ft_strncmp(trimmed, "WE ", 3) == 0 ||
|
|| ft_strncmp(trimmed, "WE ", 3) == 0
|
||||||
ft_strncmp(trimmed, "EA ", 3) == 0 ||
|
|| ft_strncmp(trimmed, "EA ", 3) == 0
|
||||||
ft_strncmp(trimmed, "F ", 2) == 0 ||
|
|| ft_strncmp(trimmed, "F ", 2) == 0
|
||||||
ft_strncmp(trimmed, "C ", 2) == 0)
|
|| ft_strncmp(trimmed, "C ", 2) == 0)
|
||||||
result = 1;
|
result = 1;
|
||||||
free(trimmed);
|
free(trimmed);
|
||||||
return (result);
|
return (result);
|
||||||
|
|
@ -40,15 +50,15 @@ int is_empty_line(char *line)
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
if (!line)
|
if (!line)
|
||||||
return (1); // NULL = vide
|
return (1);
|
||||||
while (line[i])
|
while (line[i])
|
||||||
{
|
{
|
||||||
if (line[i] != ' ' && line[i] != '\t' &&
|
if (line[i] != ' ' && line[i] != '\t'
|
||||||
line[i] != '\n' && line[i] != '\r')
|
&& line[i] != '\n' && line[i] != '\r')
|
||||||
return (0);
|
return (0);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
return (1); // Que des whitespaces
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int is_color_line(char *line)
|
int is_color_line(char *line)
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/08/22 14:17:58 by lfirmin #+# #+# */
|
/* Created: 2025/08/22 14:17:58 by lfirmin #+# #+# */
|
||||||
/* Updated: 2025/08/22 14:17:58 by lfirmin ### ########.fr */
|
/* Updated: 2025/10/07 10:15:24 by lfirmin ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
#include "cub.h"
|
#include "cub.h"
|
||||||
|
|
@ -15,12 +15,19 @@ int parsing(t_data *data)
|
||||||
{
|
{
|
||||||
if (check_file(data->map_path, &data->parsing) == 1)
|
if (check_file(data->map_path, &data->parsing) == 1)
|
||||||
return (1);
|
return (1);
|
||||||
get_map(data);
|
if (get_map(data))
|
||||||
|
{
|
||||||
|
close(data->parsing.fd_map);
|
||||||
|
close(data->parsing.fd_map_dup);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
close(data->parsing.fd_map);
|
close(data->parsing.fd_map);
|
||||||
close(data->parsing.fd_map_dup);
|
close(data->parsing.fd_map_dup);
|
||||||
if (check_colors(data->texture) == 1)
|
if (check_colors(data->texture) == 1)
|
||||||
return (1);
|
return (1);
|
||||||
if (validate_map(data->parsing.raw_map, data->parsing.player) == 0)
|
if (validate_map(data->parsing.raw_map, data->parsing.player))
|
||||||
return (1);
|
return (1);
|
||||||
|
data->map = data->parsing.raw_map;
|
||||||
|
data->parsing.raw_map = NULL;
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,34 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* debug.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2025/08/23 13:23:51 by lfirmin #+# #+# */
|
|
||||||
/* Updated: 2025/08/23 13:23:51 by lfirmin ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "cub.h"
|
|
||||||
|
|
||||||
void print_char_array_debug(char **arr, char *name)
|
|
||||||
{
|
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
printf("=== %s ===\n", name ? name : "CHAR ARRAY");
|
|
||||||
|
|
||||||
if (!arr)
|
|
||||||
{
|
|
||||||
printf("Array is NULL\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (arr[i])
|
|
||||||
{
|
|
||||||
printf("[%d] (%zu chars): '%s'\n", i, strlen(arr[i]), arr[i]);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
printf("Total lines: %d\n", i);
|
|
||||||
printf("==============\n");
|
|
||||||
}
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/08/22 18:57:21 by lfirmin #+# #+# */
|
/* Created: 2025/08/22 18:57:21 by lfirmin #+# #+# */
|
||||||
/* Updated: 2025/08/22 18:57:21 by lfirmin ### ########.fr */
|
/* Updated: 2025/10/08 16:21:46 by lfirmin ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
#include "cub.h"
|
#include "cub.h"
|
||||||
|
|
@ -28,7 +28,8 @@ int init_data(t_data *data, char *path)
|
||||||
void free_data(t_data *data)
|
void free_data(t_data *data)
|
||||||
{
|
{
|
||||||
if (!data)
|
if (!data)
|
||||||
return;
|
return ;
|
||||||
if (data->texture)
|
if (data->texture)
|
||||||
free(data->texture);
|
free(data->texture);
|
||||||
|
free_char_array(data->map);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/08/22 14:56:25 by lfirmin #+# #+# */
|
/* Created: 2025/08/22 14:56:25 by lfirmin #+# #+# */
|
||||||
/* Updated: 2025/08/22 14:56:25 by lfirmin ### ########.fr */
|
/* Updated: 2025/10/07 12:14:42 by lfirmin ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -19,7 +19,7 @@ void ft_error(char *message)
|
||||||
len = 0;
|
len = 0;
|
||||||
while (message[len])
|
while (message[len])
|
||||||
len++;
|
len++;
|
||||||
write(2, ERROR_PREFIX, 31);
|
write(2, ERROR_PREFIX, 6);
|
||||||
write(2, message, len);
|
write(2, message, len);
|
||||||
write(2, "\n", 1);
|
write(2, "\n", 1);
|
||||||
}
|
}
|
||||||
|
|
@ -29,7 +29,7 @@ void free_char_array(char **array)
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (!array)
|
if (!array)
|
||||||
return;
|
return ;
|
||||||
i = 0;
|
i = 0;
|
||||||
while (array[i])
|
while (array[i])
|
||||||
free(array[i++]);
|
free(array[i++]);
|
||||||
|
|
@ -39,7 +39,22 @@ void free_char_array(char **array)
|
||||||
int ft_arrlen(char **arr)
|
int ft_arrlen(char **arr)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
while(arr[i])
|
|
||||||
|
while (arr[i])
|
||||||
i++;
|
i++;
|
||||||
return (i);
|
return (i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void print_array(char **array)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
if (!array)
|
||||||
|
return ;
|
||||||
|
while (array[i])
|
||||||
|
{
|
||||||
|
printf("%s", array[i]);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
29
test.cub
29
test.cub
|
|
@ -1,34 +1,29 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
NO textures/test/north.xpm
|
NO textures/test/north.xpm
|
||||||
|
EA textures/test/east.xpm
|
||||||
|
WE textures/test/west.xpm
|
||||||
|
SO textures/test/sud.xpm
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
EA textures/test/east.xpm
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
WE textures/test/west.xpm
|
|
||||||
|
|
||||||
C 200,200,200
|
C 200,200,200
|
||||||
F 200,200,200
|
F 200,200,200
|
||||||
11
|
|
||||||
|
1111
|
||||||
1001
|
1001
|
||||||
10S01
|
10001
|
||||||
10001
|
10001
|
||||||
10101
|
10101
|
||||||
|
1S001
|
||||||
|
1001
|
||||||
10001
|
10001
|
||||||
10001
|
10001
|
||||||
|
100011
|
||||||
10001
|
10001
|
||||||
10001
|
10001
|
||||||
10001
|
111111
|
||||||
10001
|
1111
|
||||||
10001
|
|
||||||
11
|
11
|
||||||
|
1111
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue