diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..36c14c4 --- /dev/null +++ b/Makefile @@ -0,0 +1,49 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: vmanzoni +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2019/03/01 13:24:35 by vmanzoni #+# #+# # +# Updated: 2019/04/12 21:58:27 by vmanzoni ### ########.fr # +# # +# **************************************************************************** # + +NAME = fillit + +SRC_DIR = srcs + +SRCS = *.c + +OBJ_DIR = objs + +OBJS = $(SRCS:.c=.o) + +HEADER = includes/ + +LIB = fillit.h + +CC = gcc + +CFLAGS = -Wall -Werror -Wextra + +RM = rm -f + +all: $(NAME) + +$(NAME) + $(CC) $(CFLAGS) -I$(HEADER) -c $(addprefix $(SRC_DIR)/, $(SRCS)) + $(CC) $(OBJS) -o $(NAME) + mkdir $(OBJ_DIR) + mv *.o $(OBJ_DIR) + +clean: + $(RM) $(OBJS) + +fclean: clean + $(RM) $(NAME) + +re: fclean all + +.PHONY: all clean fclean re diff --git a/README.md b/README.md index d02439f..3fd1176 100644 --- a/README.md +++ b/README.md @@ -1 +1,12 @@ -42-fillit +#Fillit + +##To do +[x] Check if we have a file +[x] Read file +[] Check if there are errors in file +[] Transform file into tetriminos +[] Check if every tetrimino is valid +[] Backtracking for smallest square +[] Print result + +[] Transform tetriminos with letters (?) diff --git a/author b/author new file mode 100644 index 0000000..5317771 --- /dev/null +++ b/author @@ -0,0 +1 @@ +vmanzoni diff --git a/includes/fillit.h b/includes/fillit.h new file mode 100644 index 0000000..fadfa52 --- /dev/null +++ b/includes/fillit.h @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* fillit.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: vmanzoni +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/03/01 13:34:46 by vmanzoni #+# #+# */ +/* Updated: 2019/03/01 13:35:08 by vmanzoni ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include // for system call write +#include // for system call open +#include // for memmove and strlen +#include // for debug printf +#include // to use bool type + +# define BUFFER_SIZE 1024 diff --git a/srcs/handle_errors.c b/srcs/handle_errors.c new file mode 100644 index 0000000..0a15002 --- /dev/null +++ b/srcs/handle_errors.c @@ -0,0 +1,61 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* handle_errors.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: vmanzoni +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/03/01 13:29:05 by vmanzoni #+# #+# */ +/* Updated: 2019/03/01 13:39:00 by vmanzoni ### ########.fr */ +/* */ +/* ************************************************************************** */ + +void ft_display_error(char *s, int fd) +{ + write(fd, s, strlen(s)); +} + +static bool ft_tetri_errors(char tetri[16]) +{ + short i; + short links_nb; + short tetri_blocks; + bool all_blocks_connected; + + i = 0; + tetri_blocks = 0; + while (i < 16) + { + if (tetri[i] == '#') + { + links_nb = 0; // reset links_nb to 0 + links_nb += (i % 4 != 0 && (tetri[i - 1] == '#')); // if not first column + links_nb += (i % 4 != 3 && (tetri[i + 1] == '#')); // if not last column + links_nb += (i / 4 != 0 && (tetri[i - 4] == '#')); // if not first row + links_nb += (i / 4 != 3 && (tetri[i + 4] == '#')); // if not last row + if (links_nb == 0) + return false; + if (links_nb > 1) + all_blocks_connected = true; + ++tetri_blocks; + } + ++i; + } + return (tetri_blocks == 4 && all_blocks_connected); +} + +bool ft_check_tetri(short tetri_nb, char tetri[tetri_nb][16]) +{ + short count; + + count = 0; + while (count < tetri_nb) + { + if (ft_tetri_errors(tetri[count++]) == false) + { + ft_display_error("Tetriminos is invalid.\n", 2); + return false; + } + } + return true; +} diff --git a/srcs/main.c b/srcs/main.c new file mode 100644 index 0000000..2c5bec2 --- /dev/null +++ b/srcs/main.c @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: vmanzoni +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/02/12 13:20:48 by vmanzoni #+# #+# */ +/* Updated: 2019/04/12 22:00:34 by vmanzoni ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int main(int argc, char **argv) +{ + char *input; + short i; + + if (argc == 2) + { + if (!(input = read_file(argv[1]))) + ft_display_error("Error: Could not read file.\n", 2); + else if (/*Elements in file not valid*/) + ft_display_error("Error: Invalid file.\n", 2); + /* + Transform input to tetriminos + Check if every tetrimino is valid + Backtracking for smallest square + Transform tetriminos with letters + Print result + */ + } + else + ft_display_error("Error: Please submit a file.\n", 2); + return 0; +} diff --git a/srcs/print_fillit.c b/srcs/print_fillit.c new file mode 100644 index 0000000..0cb5140 --- /dev/null +++ b/srcs/print_fillit.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* print_fillit.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: vmanzoni +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/03/01 13:35:48 by vmanzoni #+# #+# */ +/* Updated: 2019/03/01 13:37:45 by vmanzoni ### ########.fr */ +/* */ +/* ************************************************************************** */ + +void ft_print_fillit(short tetri_nb, char tetri[tetri_nb][16]) +{ + short count; + short i; + + count = 0; + while (count < tetri_nb) + { + i = 0; + while (i < 16) + { + write(1, &tetri[count][i], 1); + if (i++ % 4 == 3) + write(1, "\n", 1); + } + write(1, "\n", 1); + ++count; + } +}