5 Commits

Author SHA1 Message Date
Hugo LAMY
a602b3a78c a la norme et avec le dossier fillit de robin 2019-06-04 10:09:02 +02:00
Hugo LAMY
1aa695c85a mise a la racine des sous dossiers de libt 2019-06-03 22:01:27 +02:00
Hugo LAMY
700fb91632 a la norme et sans erreur 2019-06-03 13:00:46 +02:00
Hugo LAMY
d86dc433dc jsais pas ce qui a change 2019-06-03 09:54:19 +02:00
Hugo LAMY
9aa1acafe4 synchro maison ecole 2019-06-03 09:22:29 +02:00
127 changed files with 3602 additions and 317 deletions

View File

@@ -6,14 +6,10 @@
# By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ # # By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2019/03/01 13:24:35 by vmanzoni #+# #+# # # Created: 2019/03/01 13:24:35 by vmanzoni #+# #+# #
# Updated: 2019/06/01 16:57:51 by hulamy ### ########.fr # # Updated: 2019/06/03 21:55:31 by hulamy ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #
# - - - - - - - - - - - - - - - #
# VARIABLES #
# - - - - - - - - - - - - - - - #
NAME = fillit NAME = fillit
CC = gcc CC = gcc
@@ -23,13 +19,17 @@ CFLAGS += -Wall -Wextra -Werror
LDFLAGS = -L./libft/ LDFLAGS = -L./libft/
LDLIBS = -lft LDLIBS = -lft
SRCS = $(shell find . -depth 1 -type f -not -name '.*' -not -name 'test*' -name '*.c') SRCS = main.c \
f_bonus_opti.c \
f_bonus_print.c \
f_handle_errors.c \
f_parse_input.c \
f_print.c \
f_print_map_with_colors.c \
f_read_file.c \
f_search_map.c
TRASH = $(shell find . -depth 1 -name '*.dSYM') OBJS = $(SRCS:.c=.o)
TRASH += $(shell find . -depth 1 -type f -name '*.o')
TRASH += $(shell find . -depth 1 -type f -name '*.swp')
TRASH += $(shell find . -depth 1 -type f -name '*.swo')
TRASH += $(shell find . -depth 1 -type f -name '*.swn')
# - - - - - - - - - - - - - - - # # - - - - - - - - - - - - - - - #
# RULES # # RULES #
@@ -37,19 +37,16 @@ TRASH += $(shell find . -depth 1 -type f -name '*.swn')
all: $(NAME) all: $(NAME)
$(NAME): $(SRCS) $(NAME): $(OBJS)
make -C ./libft/
$(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) $(SRCS) -o $(NAME) $(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) $(SRCS) -o $(NAME)
debug: $(SRCS)
$(CC) -g $(CFLAGS) $(LDFLAGS) $(LDLIBS) $(SRCS) -o $(NAME)
lib:
make -C ./libft/
clean: clean:
/bin/rm -rf $(TRASH) make clean -C libft/
/bin/rm -rf $(OBJS)
fclean: clean fclean: clean
make fclean -C libft/
/bin/rm -rf $(NAME) /bin/rm -rf $(NAME)
re: fclean all re: fclean all

View File

@@ -6,7 +6,7 @@
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */ /* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2019/05/24 14:42:46 by hulamy #+# #+# */ /* Created: 2019/05/24 14:42:46 by hulamy #+# #+# */
/* Updated: 2019/06/01 14:11:32 by hulamy ### ########.fr */ /* Updated: 2019/06/03 12:51:22 by hulamy ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -23,14 +23,12 @@ int check_tetri_memory(t_fillist *list, int pos)
tetri = list; tetri = list;
mask = 1 << ((pos % 32) - 1); mask = 1 << ((pos % 32) - 1);
if (!tetri->same && !tetri->memory)
return(1);
if (tetri->same) if (tetri->same)
{ {
if (!(tetri->same->memory[pos / 32] & mask)) if (!(tetri->same->memory[pos / 32] & mask))
return (tetri->same->memory[pos / 32] |= mask); return (tetri->same->memory[pos / 32] |= mask);
} }
else if (tetri->memory) else
{ {
if (!(tetri->memory[pos / 32] & mask)) if (!(tetri->memory[pos / 32] & mask))
return (tetri->memory[pos / 32] |= mask); return (tetri->memory[pos / 32] |= mask);
@@ -44,8 +42,6 @@ int check_tetri_memory(t_fillist *list, int pos)
int compare_tetri(t_fillist *tetri_a, t_fillist *tetri_b) int compare_tetri(t_fillist *tetri_a, t_fillist *tetri_b)
{ {
if (tetri_a->same)
return (0);
if (tetri_a->tetribit != tetri_b->tetribit) if (tetri_a->tetribit != tetri_b->tetribit)
return (0); return (0);
if (tetri_a->width != tetri_b->width) if (tetri_a->width != tetri_b->width)
@@ -83,22 +79,20 @@ int check_same_tetri(t_fillist *list, int num)
curr_tetri = clean_list_memory(list, list); curr_tetri = clean_list_memory(list, list);
while (curr_tetri != NULL) while (curr_tetri != NULL)
{ {
i = 0;
if (!(curr_tetri->memory =
(unsigned int *)malloc(sizeof(*curr_tetri->memory) * num)))
return (0);
while (i < num)
curr_tetri->memory[i++] = 0;
next_tetri = curr_tetri->next; next_tetri = curr_tetri->next;
while (next_tetri != NULL) while (next_tetri != NULL)
{ {
if (compare_tetri(curr_tetri, next_tetri)) if (compare_tetri(curr_tetri, next_tetri))
{ if (next_tetri->same == NULL)
i = 0; next_tetri->same = curr_tetri;
if (!(curr_tetri->memory =
(unsigned int *)malloc(sizeof(*curr_tetri->memory) * num)))
return (0);
while (i < num)
curr_tetri->memory[i++] = 0;
next_tetri->same = curr_tetri;
}
next_tetri = next_tetri->next; next_tetri = next_tetri->next;
} }
curr_tetri->position = 0;
curr_tetri->total_num = num; curr_tetri->total_num = num;
curr_tetri = curr_tetri->next; curr_tetri = curr_tetri->next;
} }

View File

@@ -24,20 +24,20 @@ t_fillist *print_tetri(t_fillist *list)
tmp = list; tmp = list;
if (list->dope[2]) if (list->dope[2])
{ {
check_same_tetri(list, 1);
while (tmp) while (tmp)
{ {
check_same_tetri(list, 1);
print = tmp->tetribit; print = tmp->tetribit;
print <<= 16; print <<= 16;
print_sized_map(&print, tmp->width, tmp->height, tmp->letter); print_sized_map(&print, tmp->width, tmp->height, tmp->letter);
if (tmp->same && list->dope[1]) if (tmp->same && list->dope[1])
{ {
print = tmp->same->tetribit;
print <<= 16;
ft_putstr("same --> "); ft_putstr("same --> ");
ft_put_tetri_color(tmp->same->letter); ft_put_tetri_color(tmp->same->letter);
ft_putchar('\n'); ft_putchar('\n');
} }
if (list->dope[1] && tmp->memory)
ft_putendl("have a copy");
ft_putchar('\n'); ft_putchar('\n');
tmp = tmp->next; tmp = tmp->next;
} }

View File

@@ -6,7 +6,7 @@
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */ /* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/01 13:29:05 by vmanzoni #+# #+# */ /* Created: 2019/03/01 13:29:05 by vmanzoni #+# #+# */
/* Updated: 2019/06/01 15:53:31 by vmanzoni ### ########.fr */ /* Updated: 2019/06/01 19:44:08 by hulamy ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -77,7 +77,7 @@ void check_file_errors(char *file, int *dope)
} }
if (file[i - 1] == '\n') if (file[i - 1] == '\n')
print_error_extended(3, dope); print_error_extended(3, dope);
if (line_nbr < 4) if (line_nbr < 3)
print_error_extended(4, dope); print_error_extended(4, dope);
if (!dope[3] && line_nbr > 129) if (!dope[3] && line_nbr > 129)
print_error_extended(5, dope); print_error_extended(5, dope);

View File

@@ -121,7 +121,6 @@ int add_to_list(char *line, t_fillist **lst, char letter, int *dope)
tmp->letter = letter; tmp->letter = letter;
tmp->dope = dope; tmp->dope = dope;
tmp->start = *lst; tmp->start = *lst;
tmp->memory = NULL;
return (1); return (1);
} }

View File

@@ -6,7 +6,7 @@
/* By: hulamy <hulamy@student.42.fr> +#+ +:+ +#+ */ /* By: hulamy <hulamy@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/27 20:47:22 by hulamy #+# #+# */ /* Created: 2019/04/27 20:47:22 by hulamy #+# #+# */
/* Updated: 2019/06/01 15:12:08 by hulamy ### ########.fr */ /* Updated: 2019/06/03 13:00:28 by hulamy ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -52,7 +52,7 @@ unsigned int fit_in_place(unsigned int *map, t_fillist *lst, int sze, int i)
int find_place(unsigned int *map, t_fillist *list, int size) int find_place(unsigned int *map, t_fillist *list, int size)
{ {
int limit; int limit;
int pos; int pos;
pos = list->position; pos = list->position;
list->place = pos % size; list->place = pos % size;
@@ -103,44 +103,17 @@ void add_remove(unsigned int *map, t_fillist *list, int size)
} }
} }
void clean_memory(t_fillist *list, int pos, int mem)
{
t_fillist *tmp;
unsigned int mask;
tmp = list->start;
while (tmp)
{
if (tmp->memory)
{
pos = mem;
while (pos >= list->position)
{
mask = ~(1 << ((pos % 32) - 1));
tmp->memory[pos / 32] &= mask;
pos--;
}
}
tmp = tmp->next;
}
}
/* /*
** Function that recursively try to fill the map with the tetris ** Function that recursively try to fill the map with the tetris
*/ */
int fill_map(unsigned int *map, t_fillist *list, int size) int fill_map(unsigned int *map, t_fillist *list, int size)
{ {
int pos;
if (!list) if (!list)
return (1); return (1);
pos = list->position;
list->position = 0; list->position = 0;
while (find_place(map, list, size)) while (find_place(map, list, size))
{ {
// if (list->position < pos)
// clean_memory(list, pos, pos);
add_remove(map, list, size); add_remove(map, list, size);
list->test = 1; list->test = 1;
if (list->dope[0]) if (list->dope[0])
@@ -176,8 +149,7 @@ int search_map(t_fillist *list)
size = 2; size = 2;
tmp = print_tetri(list); tmp = print_tetri(list);
// init_num_and_size(1, &size, tmp); init_num_and_size(1, &size, tmp);
size = 10;
i = 0; i = 0;
while (!i) while (!i)
{ {

View File

@@ -1,20 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleIdentifier</key>
<string>com.apple.xcode.dsym.fillit</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>dSYM</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>

View File

@@ -6,7 +6,7 @@
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */ /* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/01 13:34:46 by vmanzoni #+# #+# */ /* Created: 2019/03/01 13:34:46 by vmanzoni #+# #+# */
/* Updated: 2019/06/01 15:12:00 by hulamy ### ########.fr */ /* Updated: 2019/06/03 21:53:09 by hulamy ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -18,7 +18,7 @@
# include <fcntl.h> # include <fcntl.h>
# include <stdbool.h> # include <stdbool.h>
# include "libft/includes/libft.h" # include "libft/libft.h"
/* /*
** DEFINE ** DEFINE
@@ -37,20 +37,19 @@
/* /*
** STRUCTURE ** STRUCTURE
** tetribit : tetri ecrit en binaire dans un short de 16 bits ** tetribit : tetri ecrit en binaire dans un short de 16 bits
** width : largeur du tetri ** width : largeur du tetri
** height : hauteur du tetri ** height : hauteur du tetri
** position : memorise la position d tetri bit a bit ** position : memorise la position d tetri bit a bit
** place : position sur l'axe des abscisses de la map (position % size) ** place : position sur l'axe des abscisses de la map (position % size)
** rank : position de 1 a 32 dans l'int du tableau d'int (position % 32) ** rank : position de 1 a 32 dans l'int du tableau d'int (position % 32)
** num : memorise dans quel int du tableau on se trouve (position / 32) ** num : memorise dans quel int du tableau on se trouve (position / 32)
** total_num: memorise le nombre d'int dans le tableau ** test :
** test : ** letter : letter of the tetrimino for printing final map
** letter : letter of the tetrimino for printing final map ** dope : flags for details, optimisation, printing and error
** dope : flags for details, optimisation, printing and error ** memory : positions already tested by a tetrimino in bitwise
** memory : positions already tested by a tetrimino in bitwise ** same : pointer to previous identical tetrimino
** same : pointer to previous identical tetrimino ** next : pointer to next tetrimino
** next : pointer to next tetrimino ** start : pointer to first tetrimino of input file
** start : pointer to first tetrimino of input file
*/ */
typedef struct s_fillist typedef struct s_fillist
{ {

34
fillit_roduquen/Makefile Executable file
View File

@@ -0,0 +1,34 @@
CC = gcc
CFLAGS = -Wall -Wextra -Werror
NAME = fillit
SRCDIR = ./
INCLDIR = ./
SRCS = $(SRCDIR)main.c $(SRCDIR)check_square.c $(SRCDIR)check_square2.c \
$(SRCDIR)fillit.c $(SRCDIR)full_square.c $(SRCDIR)check_hole.c\
$(SRCDIR)full_square2.c $(SRCDIR)remove_square.c $(SRCDIR)utilitys.c \
$(SRCDIR)do_i_fillit.c $(SRCDIR)count_island.c \
$(SRCDIR)check_count_island.c $(SRCDIR)init.c \
$(SRCDIR)check_count_island2.c
OBJS_ = $(SRCS:.c=.o)
OBJS = $(notdir $(OBJS_))
all : $(NAME)
$(NAME) : $(SRCS)
@make $(OBJS)
@$(CC) $(CFLAGS) -I $(INCLDIR) $^ -o $@
@echo "\n\033[36mCreation :\033[0m \033[35;4m$(NAME)\033[0m\n"
%.o : %.c
@$(CC) $(CFLAGS) -c -I $(INCLDIR) $^
@echo "\033[36mCompilation :\033[0m \033[32m$*\033[0m"
clean :
@rm -rf $(OBJS)
@echo "\n\033[36mDeletion :\033[0m \033[32mObjects\033[0m\n"
fclean : clean
@rm -rf $(NAME)
@echo "\033[36mDeletion :\033[0m \033[35;4m$(NAME)\033[0m\n"
re : fclean all

View File

@@ -0,0 +1,54 @@
..#.
###.
....
....
..##
.##.
....
....
.#..
###.
....
....
.#..
##..
.#..
....
.###
...#
....
....
....
....
....
####
....
.##.
.##.
....
.#..
.##.
.#..
....
.#..
.#..
.##.
....
.###
..#.
....
....
.#..
###.
....
....

View File

@@ -0,0 +1,64 @@
..#.
###.
....
....
..##
.##.
....
....
.#..
###.
....
....
.#..
##..
.#..
....
.###
...#
....
....
....
....
....
####
....
.##.
.##.
....
.#..
.##.
.#..
....
.#..
.#..
.##.
....
.###
..#.
....
....
.#..
###.
....
....
....
.#..
###.
....
..##
.##.
....
....

View File

@@ -0,0 +1,34 @@
..#.
###.
....
....
..##
.##.
....
....
.#..
###.
....
....
.#..
##..
.#..
....
.###
...#
....
....
....
....
....
####
....
.##.
.##.
....

View File

@@ -0,0 +1,44 @@
..#.
###.
....
....
..##
.##.
....
....
.#..
###.
....
....
.#..
##..
.#..
....
.###
...#
....
....
....
....
....
####
....
.##.
.##.
....
.#..
.##.
.#..
....
.#..
.#..
.##.
....

39
fillit_roduquen/TEST/test_I.txt Executable file
View File

@@ -0,0 +1,39 @@
####
....
....
....
....
####
....
....
....
....
####
....
....
....
....
####
#...
#...
#...
#...
.#..
.#..
.#..
.#..
..#.
..#.
..#.
..#.
...#
...#
...#
...#

119
fillit_roduquen/TEST/test_J.txt Executable file
View File

@@ -0,0 +1,119 @@
.#..
.#..
##..
....
..#.
..#.
.##.
....
...#
...#
..##
....
....
.#..
.#..
##..
....
..#.
..#.
.##.
....
...#
...#
..##
###.
..#.
....
....
.###
...#
....
....
....
###.
..#.
....
....
.###
...#
....
....
....
###.
..#.
....
....
.###
...#
##..
#...
#...
....
.##.
.#..
.#..
....
..##
..#.
..#.
....
....
##..
#...
#...
....
.##.
.#..
.#..
....
..##
..#.
..#.
#...
###.
....
....
.#..
.###
....
....
....
#...
###.
....
....
.#..
.###
....
....
....
#...
###.
....
....
.#..
.###

119
fillit_roduquen/TEST/test_J2.txt Executable file
View File

@@ -0,0 +1,119 @@
..##
..#.
..#.
....
....
##..
#...
#...
....
.##.
.#..
.#..
....
..##
..#.
..#.
.#..
.#..
##..
....
..#.
..#.
.##.
....
...#
...#
..##
....
....
.#..
.#..
##..
....
..#.
..#.
.##.
....
...#
...#
..##
###.
..#.
....
....
.###
...#
....
....
....
###.
..#.
....
....
.###
...#
....
....
....
###.
..#.
....
....
.###
...#
##..
#...
#...
....
.##.
.#..
.#..
....
#...
###.
....
....
.#..
.###
....
....
....
#...
###.
....
....
.#..
.###
....
....
....
#...
###.
....
....
.#..
.###

119
fillit_roduquen/TEST/test_L.txt Executable file
View File

@@ -0,0 +1,119 @@
#...
#...
##..
....
.#..
.#..
.##.
....
..#.
..#.
..##
....
....
#...
#...
##..
....
.#..
.#..
.##.
....
..#.
..#.
..##
###.
#...
....
....
.###
.#..
....
....
....
###.
#...
....
....
.###
.#..
....
....
....
###.
#...
....
....
.###
.#..
##..
.#..
.#..
....
.##.
..#.
..#.
....
..##
...#
...#
....
....
##..
.#..
.#..
....
.##.
..#.
..#.
....
..##
...#
...#
..#.
###.
....
....
...#
.###
....
....
....
..#.
###.
....
....
...#
.###
....
....
....
..#.
###.
....
....
...#
.###

44
fillit_roduquen/TEST/test_O.txt Executable file
View File

@@ -0,0 +1,44 @@
##..
##..
....
....
.##.
.##.
....
....
..##
..##
....
....
....
##..
##..
....
....
.##.
.##.
....
....
..##
..##
....
....
....
##..
##..
....
....
.##.
.##.
....
....
..##
..##

59
fillit_roduquen/TEST/test_S.txt Executable file
View File

@@ -0,0 +1,59 @@
.##.
##..
....
....
..##
.##.
....
....
....
.##.
##..
....
....
..##
.##.
....
....
....
.##.
##..
....
....
..##
.##.
#...
##..
.#..
....
.#..
.##.
..#.
....
..#.
..##
...#
....
....
#...
##..
.#..
....
.#..
.##.
..#.
....
..#.
..##
...#

119
fillit_roduquen/TEST/test_T.txt Executable file
View File

@@ -0,0 +1,119 @@
###.
.#..
....
....
.###
..#.
....
....
....
###.
.#..
....
....
.###
..#.
....
....
....
###.
.#..
....
....
.###
..#.
#...
##..
#...
....
.#..
.##.
.#..
....
..#.
..##
..#.
....
....
#...
##..
#...
....
.#..
.##.
.#..
....
..#.
..##
..#.
.#..
###.
....
....
..#.
.###
....
....
....
.#..
###.
....
....
..#.
.###
....
....
....
.#..
###.
....
....
..#.
.###
.#..
##..
.#..
....
..#.
.##.
..#.
....
...#
..##
...#
....
....
.#..
##..
.#..
....
..#.
.##.
..#.
....
...#
..##
...#

59
fillit_roduquen/TEST/test_Z.txt Executable file
View File

@@ -0,0 +1,59 @@
##..
.##.
....
....
.##.
..##
....
....
....
##..
.##.
....
....
.##.
..##
....
....
....
##..
.##.
....
....
.##.
..##
.#..
##..
#...
....
..#.
.##.
.#..
....
...#
..##
..#.
....
....
.#..
##..
#...
....
..#.
.##.
.#..
....
...#
..##
..#.

View File

@@ -0,0 +1,24 @@
..#.
###.
....
....
..##
.##.
....
....
.#..
###.
....
....
.#..
##..
.#..
....
.###
...#
....
....

View File

@@ -0,0 +1,129 @@
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....

View File

@@ -0,0 +1,39 @@
####
....
....
....
....
####
....
....
....
....
####
....
....
....
....
####
#...
#...
#...
#...
.#..
.#..
.#..
.#..
..#.
..#.
..#.
..#.
...#
...#
...#
...#.

View File

@@ -0,0 +1,40 @@
####
....
....
....
....
####
....
....
....
....
####
....
....
....
....
####
#...
#...
#...
#...
.#..
.#..
.#..
.#..
..#.
..#.
..#.
..#.
...#
...#
...#
...#

View File

@@ -0,0 +1,38 @@
####
....
....
....
....
####
....
....
....
....
####
....
....
....
....
####
#...
#...
#...
#...
.#..
.#..
.#..
.#..
..#.
..#.
..#.
..#.
...#
...#
...#
...#

View File

@@ -0,0 +1,39 @@
####
....
....
....
....
####
....
....
....
....
####
....
....
....
....
####
#...
#...
#...
#...
.#..
.#..
.#..
.#..
..#.
..#.
..#.
..#.
...#
..##
...#
...#

View File

@@ -0,0 +1,40 @@
####
....
....
....
....
####
....
....
....
....
####
....
....
....
....
####
#...
#...
#...
#...
.#..
.#..
.#..
.#..
..#.
..#.
..#.
..#.
...#
...#
...#
...#.

View File

@@ -0,0 +1,39 @@
####
....
....
....
....
####
....
....
....
....
####
....
....
....
....
####
#...
....
#...
#...
.#..
.#..
.#..
.#..
..#.
..#.
..#.
..#.
...#
...#
...#
...#.

View File

@@ -0,0 +1,39 @@
####
....
....
....
....
####
....
....
....
....
####
....
....
....
....
####
#...
#...
#...
#...
.#..
.#..
.#..
.#..
..#.
..#.
..#.
..#.
...#
...#
...#
...#.

View File

@@ -0,0 +1,64 @@
....
####
....
....
#...
#...
#...
#...
.#..
###.
....
....
.#..
.##.
.#..
....
.###
..#.
....
....
###.
..#.
....
....
.###
.#..
....
....
##..
##..
....
....
.#..
.#..
.##.
....
.#..
##..
.#..
....
.#..
.#..
##..
....
...#
.###
....
....
.#..
.###
....
....

View File

@@ -0,0 +1,79 @@
....
####
....
....
#...
#...
#...
#...
.#..
###.
....
....
.#..
.##.
.#..
....
.###
..#.
....
....
###.
..#.
....
....
.###
.#..
....
....
##..
##..
....
....
.#..
.#..
.##.
....
.#..
##..
.#..
....
.#..
.#..
##..
....
...#
.###
....
....
.#..
.###
....
....
##..
.#..
.#..
....
##..
#...
#...
....
.##.
##..
....
....

View File

@@ -0,0 +1,44 @@
....
####
....
....
#...
#...
#...
#...
.#..
###.
....
....
.#..
.##.
.#..
....
.###
..#.
....
....
###.
..#.
....
....
.###
.#..
....
....
##..
##..
....
....
.#..
.#..
.##.
....

1
fillit_roduquen/auteur Executable file
View File

@@ -0,0 +1 @@
roduquen;scarpent

View File

@@ -0,0 +1,121 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* check_count_island.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: roduquen <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/01 17:12:04 by roduquen #+# #+# */
/* Updated: 2019/04/01 19:16:13 by roduquen ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
int ft_check_square(int i, t_type *square, char nbr)
{
if (i < square->size)
{
if (i == 0)
{
if ((square->isl[i + 1] == nbr && (i + 1) % square->size != 0)
|| square->isl[i + square->size] == nbr)
{
square->isl[i] = nbr;
if (square->str[i + 1] == '.' && (i + 1) % square->size != 0)
square->isl[i + 1] = nbr;
if (square->str[i + square->size] == '.')
square->isl[i + square->size] = nbr;
return (SUCCESS);
}
return (ERROR);
}
else
return (ft_check_square2(i, square, nbr));
}
return (ft_check_square3(i, square, nbr));
}
int ft_check_square2(int i, t_type *square, char nbr)
{
if ((square->isl[i + 1] == nbr && (i + 1) % square->size != 0)
|| square->isl[i - 1] == nbr
|| square->isl[i + square->size] == nbr)
{
square->isl[i] = nbr;
if (square->str[i + 1] == '.' && (i + 1) % square->size != 0)
square->isl[i + 1] = nbr;
if (square->str[i - 1] == '.')
square->isl[i - 1] = nbr;
if (square->str[i + square->size] == '.')
square->isl[i + square->size] = nbr;
return (SUCCESS);
}
return (ERROR);
}
int ft_check_square3(int i, t_type *square, char nbr)
{
if (i < square->size * (square->size - 1))
{
if (i % square->size == 0)
{
if ((square->isl[i + 1] == nbr && (i + 1) % square->size != 0)
|| square->isl[i + square->size] == nbr
|| square->isl[i - square->size] == nbr)
{
square->isl[i] = nbr;
if (square->str[i + 1] == '.')
square->isl[i + 1] = nbr;
if (square->str[i + square->size] == '.')
square->isl[i + square->size] = nbr;
if (square->str[i - square->size] == '.')
square->isl[i - square->size] = nbr;
return (SUCCESS);
}
return (ERROR);
}
else
return (ft_check_square4(i, square, nbr));
}
return (ft_check_square5(i, square, nbr));
}
int ft_check_square4(int i, t_type *square, char nbr)
{
if ((square->isl[i + 1] == nbr && (i + 1) % square->size != 0)
|| square->isl[i + square->size] == nbr
|| square->isl[i - 1] == nbr || square->isl[i - square->size] == nbr)
{
square->isl[i] = nbr;
if (square->str[i + 1] == '.' && (i + 1) % square->size != 0)
square->isl[i + 1] = nbr;
if (square->str[i + square->size] == '.')
square->isl[i + square->size] = nbr;
if (square->str[i - 1] == '.')
square->isl[i - 1] = nbr;
if (square->str[i - square->size] == '.')
square->isl[i - square->size] = nbr;
return (SUCCESS);
}
return (ERROR);
}
int ft_check_square5(int i, t_type *square, char nbr)
{
if (i % square->size == 0)
{
if ((square->isl[i + 1] == nbr && (i + 1) % square->size != 0)
|| square->isl[i - square->size] == nbr)
{
square->isl[i] = nbr;
if (square->str[i + 1] == '.' && (i + 1) % square->size != 0)
square->isl[i + 1] = nbr;
if (square->str[i - square->size] == '.')
square->isl[i - square->size] = nbr;
return (SUCCESS);
}
return (ERROR);
}
return (ft_check_square6(i, square, nbr));
}

View File

@@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* check_count_island.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: roduquen <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/01 17:12:04 by roduquen #+# #+# */
/* Updated: 2019/04/01 19:15:21 by roduquen ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
int ft_check_square6(int i, t_type *square, char nbr)
{
if ((square->isl[i + 1] == nbr && (i + 1) % square->size != 0)
|| square->isl[i - square->size] == nbr
|| square->isl[i - 1] == nbr)
{
square->isl[i] = nbr;
if (square->str[i + 1] == '.' && (i + 1) % square->size != 0)
square->isl[i + 1] = nbr;
if (square->str[i - square->size] == '.')
square->isl[i - square->size] = nbr;
if (square->str[i - 1] == '.')
square->isl[i - 1] = nbr;
return (SUCCESS);
}
return (ERROR);
}

41
fillit_roduquen/check_hole.c Executable file
View File

@@ -0,0 +1,41 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* check_hole.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: roduquen <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/01 17:12:10 by roduquen #+# #+# */
/* Updated: 2019/04/01 17:12:11 by roduquen ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
int check_hole(t_type *square, char tetri[], int to_test)
{
if (count_island(square, 0, tetri, to_test) > square->hole)
return (ERROR);
return (SUCCESS);
}
int i_fillit_the_power(t_type *square, char tetri[], int pos)
{
int i;
int j;
i = 0;
j = -1;
while (i < pos)
{
if (tetri[i] == tetri[pos])
j = i;
i++;
}
if (j == -1)
return (0);
i = 0;
while (square->str[i] != j + 'A')
i++;
return (i);
}

158
fillit_roduquen/check_square.c Executable file
View File

@@ -0,0 +1,158 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* check_square.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: roduquen <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/01 17:12:12 by roduquen #+# #+# */
/* Updated: 2019/04/01 19:14:13 by roduquen ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
#include <stdio.h>
#include <unistd.h>
int check_square(t_type *square, char tetri, int pos)
{
if (tetri == -9
&& square->str[pos] == '.' && (pos + 1) % square->size != 0
&& pos + 2 * square->size + 1 < square->size * square->size
&& square->str[pos + 1] == '.'
&& square->str[pos + square->size + 1] == '.'
&& square->str[pos + 2 * square->size + 1] == '.')
return (SUCCESS);
if (tetri == -8
&& (pos + 1) % square->size != 0
&& pos + 2 * square->size + 1 < square->size * square->size
&& square->str[pos + 1] == '.'
&& square->str[pos + 2 * square->size] == '.'
&& square->str[pos + square->size + 1] == '.'
&& square->str[pos + 2 * square->size + 1] == '.')
return (SUCCESS);
if (tetri == -7
&& (pos + 1) % square->size != 0
&& pos + 2 * square->size < square->size * square->size
&& square->str[pos] == '.'
&& square->str[pos + 1] == '.'
&& square->str[pos + square->size] == '.'
&& square->str[pos + 2 * square->size] == '.')
return (SUCCESS);
return (check_square2(square, tetri, pos));
}
int check_square2(t_type *square, char tetri, int pos)
{
if (tetri == -6
&& (pos + 1) % square->size != 0
&& pos + 2 * square->size + 1 < square->size * square->size
&& square->str[pos] == '.'
&& square->str[pos + 2 * square->size + 1] == '.'
&& square->str[pos + square->size] == '.'
&& square->str[pos + 2 * square->size] == '.')
return (SUCCESS);
if (tetri == -5
&& (pos + 1) % square->size != 0 && (pos + 2) % square->size != 0
&& pos + square->size + 1 < square->size * square->size
&& square->str[pos + 1] == '.'
&& square->str[pos + 2] == '.'
&& square->str[pos + square->size] == '.'
&& square->str[pos + 1 + square->size] == '.')
return (SUCCESS);
if (tetri == -4
&& (pos + 1) % square->size != 0 && (pos + 2) % square->size != 0
&& pos + 2 + square->size < square->size * square->size
&& square->str[pos] == '.'
&& square->str[pos + 1] == '.'
&& square->str[pos + square->size + 1] == '.'
&& square->str[pos + 2 + square->size] == '.')
return (SUCCESS);
return (check_square3(square, tetri, pos));
}
int check_square3(t_type *square, char tetri, int pos)
{
if (tetri == -3
&& (pos + 1) % square->size != 0
&& pos + 2 * square->size < square->size * square->size
&& square->str[pos] == '.'
&& square->str[pos + 1 + square->size] == '.'
&& square->str[pos + square->size] == '.'
&& square->str[pos + 2 * square->size] == '.')
return (SUCCESS);
if (tetri == -2
&& (pos + 1) % square->size != 0
&& pos + 2 * square->size + 1 < square->size * square->size
&& square->str[pos + 1] == '.'
&& square->str[pos + 1 + square->size] == '.'
&& square->str[pos + square->size] == '.'
&& square->str[pos + 2 * square->size + 1] == '.')
return (SUCCESS);
if (tetri == -1
&& (pos + 1) % square->size != 0 && (pos + 2) % square->size != 0
&& (pos + 3) % square->size != 0
&& pos + 3 < square->size * square->size
&& square->str[pos] == '.' && square->str[pos + 1] == '.'
&& square->str[pos + 3] == '.'
&& square->str[pos + 2] == '.')
return (SUCCESS);
return (check_square4(square, tetri, pos));
}
int check_square4(t_type *square, char tetri, int pos)
{
if (tetri == 0
&& (pos + 1) % square->size != 0
&& pos + square->size + 1 < square->size * square->size
&& square->str[pos] == '.'
&& square->str[pos + 1] == '.'
&& square->str[pos + square->size] == '.'
&& square->str[pos + 1 + square->size] == '.')
return (SUCCESS);
if (tetri == 1
&& pos + 3 * square->size < square->size * square->size
&& square->str[pos] == '.'
&& square->str[pos + 3 * square->size] == '.'
&& square->str[pos + square->size] == '.'
&& square->str[pos + 2 * square->size] == '.')
return (SUCCESS);
if (tetri == 2
&& (pos + 1) % square->size != 0 && (pos + 2) % square->size != 0
&& pos + 2 + square->size < square->size * square->size
&& square->str[pos + 1] == '.'
&& square->str[pos + 1 + square->size] == '.'
&& square->str[pos + square->size] == '.'
&& square->str[pos + 2 + square->size] == '.')
return (SUCCESS);
return (check_square5(square, tetri, pos));
}
int check_square5(t_type *square, char tetri, int pos)
{
if (tetri == 3
&& (pos + 1) % square->size != 0 && (pos + 2) % square->size != 0
&& pos + 1 + square->size < square->size * square->size
&& square->str[pos] == '.'
&& square->str[pos + 1] == '.'
&& square->str[pos + square->size + 1] == '.'
&& square->str[pos + 2] == '.')
return (SUCCESS);
if (tetri == 4
&& (pos + 1) % square->size != 0
&& pos + 2 * square->size < square->size * square->size
&& square->str[pos + 1] == '.'
&& square->str[pos + 1 + square->size] == '.'
&& square->str[pos + square->size] == '.'
&& square->str[pos + 2 * square->size] == '.')
return (SUCCESS);
if (tetri == 5
&& (pos + 1) % square->size != 0
&& pos + 2 * square->size + 1 < square->size * square->size
&& square->str[pos] == '.'
&& square->str[pos + 1 + square->size] == '.'
&& square->str[pos + square->size] == '.'
&& square->str[pos + 2 * square->size + 1] == '.')
return (SUCCESS);
return (check_square6(square, tetri, pos));
}

55
fillit_roduquen/check_square2.c Executable file
View File

@@ -0,0 +1,55 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* check_square2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: roduquen <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/01 17:12:15 by roduquen #+# #+# */
/* Updated: 2019/04/01 17:26:45 by roduquen ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
int check_square6(t_type *square, char tetri, int pos)
{
if (tetri == 6
&& (pos + 1) % square->size != 0 && (pos + 2) % square->size != 0
&& pos + square->size < square->size * square->size
&& square->str[pos] == '.'
&& square->str[pos + 1] == '.'
&& square->str[pos + square->size] == '.'
&& square->str[pos + 2] == '.')
return (SUCCESS);
if (tetri == 7
&& (pos + 1) % square->size != 0 && (pos + 2) % square->size != 0
&& pos + 2 + square->size < square->size * square->size
&& square->str[pos] == '.'
&& square->str[pos + 1] == '.'
&& square->str[pos + 2] == '.'
&& square->str[pos + 2 + square->size] == '.')
return (SUCCESS);
if (tetri == 8
&& (pos + 1) % square->size != 0 && (pos + 2) % square->size != 0
&& pos + 2 + square->size < square->size * square->size
&& square->str[pos] == '.'
&& square->str[pos + 1 + square->size] == '.'
&& square->str[pos + square->size] == '.'
&& square->str[pos + 2 + square->size] == '.')
return (SUCCESS);
return (check_square7(square, tetri, pos));
}
int check_square7(t_type *square, char tetri, int pos)
{
if (tetri == 9
&& (pos + 1) % square->size != 0 && (pos + 2) % square->size != 0
&& pos + 2 + square->size < square->size * square->size
&& square->str[pos + 2] == '.'
&& square->str[pos + 1 + square->size] == '.'
&& square->str[pos + square->size] == '.'
&& square->str[pos + 2 + square->size] == '.')
return (SUCCESS);
return (ERROR);
}

126
fillit_roduquen/count_island.c Executable file
View File

@@ -0,0 +1,126 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* count_island.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: roduquen <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/01 17:12:17 by roduquen #+# #+# */
/* Updated: 2019/04/01 19:13:25 by roduquen ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
#include <stdio.h>
#include <unistd.h>
int count_island(t_type *square, int i, char tetri[], int to_test)
{
char nbr;
ft_memset(square->isl, '.', 170);
nbr = 'a';
while (1)
{
i = 0;
while (square->str[i])
{
if (square->isl[i] == '.' && square->str[i] == '.')
break ;
i++;
}
if (square->str[i])
square->isl[i] = nbr;
else
return (count_hole(square, nbr, tetri, to_test));
full_count_island_square(square, nbr);
nbr++;
}
return (ERROR);
}
void full_count_island_square(t_type *square, char nbr)
{
int i;
int j;
i = 0;
while (i < square->size * 2)
{
j = 0;
while (square->str[j])
{
if (square->str[j] == '.' && square->isl[j] == '.')
ft_check_square(j, square, nbr);
j++;
}
i++;
}
}
int count_hole(t_type *square, char nbr, char tetri[], int to_test)
{
int i;
int nbr_hole;
int total;
total = 0;
while (nbr >= 'a')
{
i = 0;
nbr_hole = 0;
while (i < square->size * square->size)
{
if (square->isl[i] == nbr)
nbr_hole++;
i++;
}
if (nbr_hole == 4)
total += check_new_possibility(square, nbr, tetri, to_test);
else
total += nbr_hole % 4;
nbr--;
}
return (total);
}
int check_if_placing_tetri_is_possible(t_type *square, char tetri[],
int to_test, int i)
{
while (tetri[to_test] != 42)
{
if (tetri[to_test] == -9 || tetri[to_test] == -7
|| tetri[to_test] == -6 || tetri[to_test] == -4
|| tetri[to_test] == -3 || tetri[to_test] == -1
|| tetri[to_test] == 0 || tetri[to_test] == 1
|| tetri[to_test] == 3 || tetri[to_test] == 5
|| tetri[to_test] == 6 || tetri[to_test] == 7
|| tetri[to_test] == 8)
{
if (check_square(square, tetri[to_test], i) == SUCCESS)
return (0);
}
else if (tetri[to_test] == -8 || tetri[to_test] == -5
|| tetri[to_test] == -2 || tetri[to_test] == 2
|| tetri[to_test] == 4)
{
if (check_square(square, tetri[to_test], i - 1) == SUCCESS)
return (0);
}
else if (check_square(square, tetri[to_test], i - 2) == SUCCESS)
return (0);
to_test++;
}
return (4);
}
int check_new_possibility(t_type *square, char nbr, char tetri[],
int to_test)
{
int i;
i = 0;
while (square->isl[i] != nbr)
i++;
return (check_if_placing_tetri_is_possible(square, tetri, to_test, i));
}

103
fillit_roduquen/do_i_fillit.c Executable file
View File

@@ -0,0 +1,103 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* do_i_fillit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: roduquen <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/01 17:12:19 by roduquen #+# #+# */
/* Updated: 2019/04/01 17:27:29 by roduquen ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
#include "fillit.h"
#include <unistd.h>
int do_i_fillit(char tetri[], int nbr)
{
int i;
t_type *square;
i = 0;
if (!(square = (t_type*)malloc(sizeof(t_type))))
return (ERROR);
while (i * i < nbr * 4)
i++;
if (!(square->str = (char*)malloc(sizeof(char) * (i * i + 1))))
return (free_error(square));
square->size = i;
full_square_hole(square, nbr);
i = 0;
while (i < square->size * square->size)
square->str[i++] = '.';
square->str[i] = 0;
return (do_i_fillit2(tetri, square));
}
int do_i_fillit2(char tetri[], t_type *square)
{
int i;
while (fillit(tetri, square) == ERROR)
{
free(square->str);
square->size++;
square->hole += square->size * 2 - 1;
if (!(square->str = (char*)malloc(sizeof(char) * (square->size
* square->size + 1))))
return (free_error(square));
i = 0;
while (i < square->size * square->size)
square->str[i++] = '.';
square->str[i] = 0;
}
free(square->str);
free(square);
return (SUCCESS);
}
int free_error(void *ptr)
{
free(ptr);
return (ERROR);
}
void print_tab(t_type *square)
{
int i;
i = 0;
while (i < square->size * square->size)
{
if (i != 0 && i % square->size == 0)
write(1, "\n", 1);
write(1, &square->str[i], 1);
i++;
}
write(1, "\n", 1);
}
void full_square_hole(t_type *square, int nbr)
{
if (nbr == 1 || nbr == 4 || nbr == 9 || nbr == 16 || nbr == 25)
square->hole = 0;
else if (nbr == 2 || nbr == 6 || nbr == 12 || nbr == 20)
square->hole = 1;
else if (nbr == 3 || nbr == 8 || nbr == 15 || nbr == 24)
square->hole = 4;
else if (nbr == 5 || nbr == 11 || nbr == 19)
square->hole = 5;
else if (nbr == 7 || nbr == 14 || nbr == 23)
square->hole = 8;
else if (nbr == 10 || nbr == 18)
square->hole = 9;
else if (nbr == 13 || nbr == 22)
square->hole = 12;
else if (nbr == 17)
square->hole = 13;
else if (nbr == 21)
square->hole = 16;
else
square->hole = 17;
}

564
fillit_roduquen/external_file.txt Executable file
View File

@@ -0,0 +1,564 @@
####
....
....
....
....
####
....
....
....
....
####
....
....
....
....
####
#...
#...
#...
#...
.#..
.#..
.#..
.#..
..#.
..#.
..#.
..#.
...#
...#
...#
...#
.#..
.#..
##..
....
..#.
..#.
.##.
....
...#
...#
..##
....
....
.#..
.#..
##..
....
..#.
..#.
.##.
....
...#
...#
..##
###.
..#.
....
....
.###
...#
....
....
....
###.
..#.
....
....
.###
...#
....
....
....
###.
..#.
....
....
.###
...#
##..
#...
#...
....
.##.
.#..
.#..
....
..##
..#.
..#.
....
....
##..
#...
#...
....
.##.
.#..
.#..
....
..##
..#.
..#.
#...
###.
....
....
.#..
.###
....
....
....
#...
###.
....
....
.#..
.###
....
....
....
#...
###.
....
....
.#..
.###
#...
#...
##..
....
.#..
.#..
.##.
....
..#.
..#.
..##
....
....
#...
#...
##..
....
.#..
.#..
.##.
....
..#.
..#.
..##
###.
#...
....
....
.###
.#..
....
....
....
###.
#...
....
....
.###
.#..
....
....
....
###.
#...
....
....
.###
.#..
##..
.#..
.#..
....
.##.
..#.
..#.
....
..##
...#
...#
....
....
##..
.#..
.#..
....
.##.
..#.
..#.
....
..##
...#
...#
..#.
###.
....
....
...#
.###
....
....
....
..#.
###.
....
....
...#
.###
....
....
....
..#.
###.
....
....
...#
.###
##..
##..
....
....
.##.
.##.
....
....
..##
..##
....
....
....
##..
##..
....
....
.##.
.##.
....
....
..##
..##
....
....
....
##..
##..
....
....
.##.
.##.
....
....
..##
..##
.##.
##..
....
....
..##
.##.
....
....
....
.##.
##..
....
....
..##
.##.
....
....
....
.##.
##..
....
....
..##
.##.
#...
##..
.#..
....
.#..
.##.
..#.
....
..#.
..##
...#
....
....
#...
##..
.#..
....
.#..
.##.
..#.
....
..#.
..##
...#
###.
.#..
....
....
.###
..#.
....
....
....
###.
.#..
....
....
.###
..#.
....
....
....
###.
.#..
....
....
.###
..#.
#...
##..
#...
....
.#..
.##.
.#..
....
..#.
..##
..#.
....
....
#...
##..
#...
....
.#..
.##.
.#..
....
..#.
..##
..#.
.#..
###.
....
....
..#.
.###
....
....
....
.#..
###.
....
....
..#.
.###
....
....
....
.#..
###.
....
....
..#.
.###
.#..
##..
.#..
....
..#.
.##.
..#.
....
...#
..##
...#
....
....
.#..
##..
.#..
....
..#.
.##.
..#.
....
...#
..##
...#
##..
.##.
....
....
.##.
..##
....
....
....
##..
.##.
....
....
.##.
..##
....
....
....
##..
.##.
....
....
.##.
..##
.#..
##..
#...
....
..#.
.##.
.#..
....
...#
..##
..#.
....
....
.#..
##..
#...
....
..#.
.##.
.#..
....
...#
..##
..#.

127
fillit_roduquen/fillit.c Executable file
View File

@@ -0,0 +1,127 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* fillit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: roduquen <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/01 17:12:23 by roduquen #+# #+# */
/* Updated: 2019/04/01 17:28:16 by roduquen ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
int full_tetri(char tetri[], char buffer[], char bufftest[], int fd)
{
int i;
if (fd == 26)
return (FILE_ERROR);
i = ft_strstr(buffer, bufftest);
if (i == 0 || i == 21 || i == 42 || i == 63)
tetri[fd] = -1;
if (i == 84 || i == 105 || i == 126 || i == 147)
tetri[fd] = 1;
if (i == 168 || i == 189 || i == 210 || i == 231 || i == 252 || i == 273)
tetri[fd] = -8;
if (i == 294 || i == 315 || i == 336 || i == 357 || i == 378 || i == 399)
tetri[fd] = 7;
if (i == 420 || i == 441 || i == 462 || i == 483 || i == 504 || i == 525)
tetri[fd] = -7;
if (i == 546 || i == 567 || i == 588 || i == 609 || i == 630 || i == 651)
tetri[fd] = 8;
if (i == 672 || i == 693 || i == 714 || i == 735 || i == 756 || i == 777)
tetri[fd] = -6;
if (i == 798 || i == 819 || i == 840 || i == 861 || i == 882 || i == 903)
tetri[fd] = 6;
if (i == 924 || i == 945 || i == 966 || i == 987 || i == 1008 || i == 1029)
tetri[fd] = -9;
return (full_tetri2(i, tetri, fd));
}
int full_tetri2(int i, char tetri[], int fd)
{
if (i == 1050 || i == 1071 || i == 1092 || i == 1113 || i == 1134
|| i == 1155)
tetri[fd] = 9;
if (i == 1176 || i == 1197 || i == 1218 || i == 1239 || i == 1260
|| i == 1281 || i == 1302 || i == 1323 || i == 1344)
tetri[fd] = 0;
if (i == 1365 || i == 1386 || i == 1407 || i == 1428 || i == 1449
|| i == 1470)
tetri[fd] = -5;
if (i == 1491 || i == 1512 || i == 1533 || i == 1554 || i == 1575
|| i == 1596)
tetri[fd] = 5;
if (i == 1617 || i == 1638 || i == 1659 || i == 1680 || i == 1701
|| i == 1722)
tetri[fd] = 3;
if (i == 1743 || i == 1764 || i == 1785 || i == 1806 || i == 1827
|| i == 1848)
tetri[fd] = -3;
if (i == 1869 || i == 1890 || i == 1911 || i == 1932 || i == 1953
|| i == 1974)
tetri[fd] = 2;
if (i == 1995 || i == 2016 || i == 2037 || i == 2058 || i == 2079
|| i == 2100)
tetri[fd] = -2;
return (full_tetri3(i, tetri, fd));
}
int full_tetri3(int i, char tetri[], int fd)
{
if (i == 2121 || i == 2142 || i == 2163 || i == 2184 || i == 2205
|| i == 2226)
tetri[fd] = -4;
if (i == 2247 || i == 2268 || i == 2289 || i == 2310 || i == 2331
|| i == 2352)
tetri[fd] = 4;
if (tetri[fd] == 42)
return (FILE_ERROR);
return (SUCCESS);
}
int fillit(char tetri[], t_type *square)
{
int i;
int j;
i = 0;
j = 0;
while (j >= 0)
{
if (check_square(square, tetri[j], i) == SUCCESS)
{
if (fillit2(square, tetri, &j, &i) == SUCCESS)
return (SUCCESS);
}
else if (square->str[i])
i++;
else
{
j--;
if (j >= 0)
i = remove_square(square, j + 'A', tetri[j]);
}
}
return (ERROR);
}
int fillit2(t_type *square, char tetri[], int *j, int *i)
{
full_square(square, tetri[*j], *j + 'A', *i);
if (tetri[*j + 1] != 42 && check_hole(square, tetri, *j + 1) != SUCCESS)
*i = remove_square(square, *j + 'A', tetri[*j]);
else
{
*i = i_fillit_the_power(square, tetri, *j + 1);
*j += 1;
}
if (tetri[*j] == 42)
{
print_tab(square);
return (SUCCESS);
}
return (CONTINUE);
}

91
fillit_roduquen/fillit.h Executable file
View File

@@ -0,0 +1,91 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* fillit.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: roduquen <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/01 17:28:32 by roduquen #+# #+# */
/* Updated: 2019/04/01 19:01:09 by roduquen ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FILLIT_H
# define FILLIT_H
/*
** MACROS
*/
# define SUCCESS 0
# define ERROR -1
# define READ_ERROR -2
# define OPEN_ERROR -3
# define FILE_ERROR -4
# define CONTINUE 1
# define BUFF_SIZE 2372
/*
** TYPEDEF && STRUCTURES
*/
typedef struct s_type
{
int size;
int hole;
char *str;
char isl[170];
} t_type;
/*
** PROTOTYPES
*/
int fillit(char tetri[], t_type *square);
int fillit2(t_type *square, char tetri[], int *j, int *i);
void full_square(t_type *square, char tetri, char nbr, int pos);
void full_square2(t_type *square, char tetri, char nbr, int pos);
void full_square3(t_type *square, char tetri, char nbr, int pos);
void full_square4(t_type *square, char tetri, char nbr, int pos);
void full_square5(t_type *square, char tetri, char nbr, int pos);
void full_square6(t_type *square, char tetri, char nbr, int pos);
int check_square(t_type *square, char tetri, int pos);
int check_square2(t_type *square, char tetri, int pos);
int check_square3(t_type *square, char tetri, int pos);
int check_square4(t_type *square, char tetri, int pos);
int check_square5(t_type *square, char tetri, int pos);
int check_square6(t_type *square, char tetri, int pos);
int check_square7(t_type *square, char tetri, int pos);
int remove_square(t_type *square, char nbr, char type);
int i_fillit_the_power(t_type *square, char tetri[], int pos);
int i_got_a_fillit(int check_fd);
int check_file(char bufftest[], char tetri[], char buffer[],
int fd);
int free_error(void *ptr);
int do_i_fillit(char tetri[], int nbr);
int do_i_fillit2(char tetri[], t_type *square);
void print_tab(t_type *square);
int full_tetri(char tetri[], char buffer[], char bufftest[],
int fd);
int full_tetri2(int i, char tetri[], int fd);
int full_tetri3(int i, char tetri[], int fd);
int ft_strstr(char haystack[], char needle[]);
int chose_type(char type, int ret);
int check_hole(t_type *square, char tetri[], int to_test);
void full_square_hole(t_type *square, int nbr);
int ft_check_square(int i, t_type *square, char nbr);
int ft_check_square2(int i, t_type *square, char nbr);
int ft_check_square3(int i, t_type *square, char nbr);
int ft_check_square4(int i, t_type *square, char nbr);
int ft_check_square5(int i, t_type *square, char nbr);
int ft_check_square6(int i, t_type *square, char nbr);
int count_island(t_type *square, int i, char tetri[],
int to_test);
void full_count_island_square(t_type *square, char nbr);
int count_hole(t_type *square, char nbr, char tetri[],
int to_test);
void ft_memset(void *ptr, char c, int len);
int check_new_possibility(t_type *square, char nbr,
char tetri[], int to_test);
#endif

148
fillit_roduquen/full_square.c Executable file
View File

@@ -0,0 +1,148 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* full_square.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: roduquen <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/01 17:12:25 by roduquen #+# #+# */
/* Updated: 2019/04/01 17:29:03 by roduquen ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
void full_square(t_type *square, char tetri, char nbr, int pos)
{
if (tetri == -9)
{
square->str[pos] = nbr;
square->str[pos + 1] = nbr;
square->str[pos + square->size + 1] = nbr;
square->str[pos + 2 * square->size + 1] = nbr;
}
else if (tetri == -8)
{
square->str[pos + 1] = nbr;
square->str[pos + 1 + square->size] = nbr;
square->str[pos + 2 * square->size] = nbr;
square->str[pos + 2 * square->size + 1] = nbr;
}
else if (tetri == -7)
{
square->str[pos] = nbr;
square->str[pos + 1] = nbr;
square->str[pos + square->size] = nbr;
square->str[pos + 2 * square->size] = nbr;
}
else
full_square2(square, tetri, nbr, pos);
}
void full_square2(t_type *square, char tetri, char nbr, int pos)
{
if (tetri == -6)
{
square->str[pos] = nbr;
square->str[pos + square->size] = nbr;
square->str[pos + 2 * square->size] = nbr;
square->str[pos + 2 * square->size + 1] = nbr;
}
else if (tetri == -5)
{
square->str[pos + 1] = nbr;
square->str[pos + 2] = nbr;
square->str[pos + square->size] = nbr;
square->str[pos + square->size + 1] = nbr;
}
else if (tetri == -4)
{
square->str[pos] = nbr;
square->str[pos + 1] = nbr;
square->str[pos + square->size + 1] = nbr;
square->str[pos + square->size + 2] = nbr;
}
else
full_square3(square, tetri, nbr, pos);
}
void full_square3(t_type *square, char tetri, char nbr, int pos)
{
if (tetri == -3)
{
square->str[pos] = nbr;
square->str[pos + square->size] = nbr;
square->str[pos + square->size + 1] = nbr;
square->str[pos + 2 * square->size] = nbr;
}
else if (tetri == -2)
{
square->str[pos + 1] = nbr;
square->str[pos + 1 + square->size] = nbr;
square->str[pos + square->size] = nbr;
square->str[pos + 2 * square->size + 1] = nbr;
}
else if (tetri == -1)
{
square->str[pos] = nbr;
square->str[pos + 1] = nbr;
square->str[pos + 2] = nbr;
square->str[pos + 3] = nbr;
}
else
full_square4(square, tetri, nbr, pos);
}
void full_square4(t_type *square, char tetri, char nbr, int pos)
{
if (tetri == 0)
{
square->str[pos] = nbr;
square->str[pos + 1] = nbr;
square->str[pos + square->size] = nbr;
square->str[pos + square->size + 1] = nbr;
}
else if (tetri == 1)
{
square->str[pos] = nbr;
square->str[pos + square->size] = nbr;
square->str[pos + square->size * 2] = nbr;
square->str[pos + 3 * square->size] = nbr;
}
else if (tetri == 2)
{
square->str[pos + 1] = nbr;
square->str[pos + 1 + square->size] = nbr;
square->str[pos + square->size] = nbr;
square->str[pos + square->size + 2] = nbr;
}
else
full_square5(square, tetri, nbr, pos);
}
void full_square5(t_type *square, char tetri, char nbr, int pos)
{
if (tetri == 3)
{
square->str[pos] = nbr;
square->str[pos + 1] = nbr;
square->str[pos + 2] = nbr;
square->str[pos + square->size + 1] = nbr;
}
else if (tetri == 4)
{
square->str[pos + 1] = nbr;
square->str[pos + 1 + square->size] = nbr;
square->str[pos + square->size] = nbr;
square->str[pos + 2 * square->size] = nbr;
}
else if (tetri == 5)
{
square->str[pos] = nbr;
square->str[pos + square->size] = nbr;
square->str[pos + square->size + 1] = nbr;
square->str[pos + 2 * square->size + 1] = nbr;
}
else
full_square6(square, tetri, nbr, pos);
}

38
fillit_roduquen/full_square2.c Executable file
View File

@@ -0,0 +1,38 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* full_square2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: roduquen <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/01 17:12:29 by roduquen #+# #+# */
/* Updated: 2019/04/01 17:12:30 by roduquen ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
void full_square6(t_type *square, char tetri, char nbr, int pos)
{
if (tetri == 6)
{
square->str[pos + 1] = nbr;
square->str[pos + 2] = nbr;
square->str[pos] = nbr;
square->str[pos + square->size] = nbr;
}
else if (tetri == 7)
{
square->str[pos] = nbr;
square->str[pos + 1] = nbr;
square->str[pos + 2] = nbr;
square->str[pos + square->size + 2] = nbr;
}
else if (tetri == 8 || tetri == 9)
{
square->str[(tetri == 8 ? pos : pos + 2)] = nbr;
square->str[pos + square->size] = nbr;
square->str[pos + 1 + square->size] = nbr;
square->str[pos + square->size + 2] = nbr;
}
}

53
fillit_roduquen/init.c Executable file
View File

@@ -0,0 +1,53 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* init.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: roduquen <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/01 17:12:31 by roduquen #+# #+# */
/* Updated: 2019/04/01 17:12:32 by roduquen ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
#include <fcntl.h>
#include <unistd.h>
int i_got_a_fillit(int check_fd)
{
int fd;
char buffer[BUFF_SIZE];
char bufftest[21];
char tetri[27];
int ret;
ft_memset(bufftest, 42, 21);
ft_memset(tetri, 42, 27);
bufftest[20] = 0;
if ((fd = open("external_file.txt", O_RDONLY)) < 0)
return (OPEN_ERROR);
if (read(fd, buffer, BUFF_SIZE) <= 0)
return (READ_ERROR);
fd = 0;
while ((ret = read(check_fd, bufftest, 20)) > 0)
{
if (ret != 20 || check_file(bufftest, tetri, buffer, fd) != SUCCESS)
return (FILE_ERROR);
if (read(check_fd, bufftest, 1) > 0 && bufftest[0] != '\n')
return (FILE_ERROR);
tetri[++fd] = 42;
}
if (ret < 0 || fd == 0 || bufftest[0] == '\n')
return (FILE_ERROR);
return (do_i_fillit(tetri, fd));
}
int check_file(char bufftest[], char tetri[], char buffer[], int fd)
{
if (bufftest[0] != '.' && bufftest[0] != '#')
return (FILE_ERROR);
if (full_tetri(tetri, buffer, bufftest, fd) != SUCCESS)
return (FILE_ERROR);
return (SUCCESS);
}

42
fillit_roduquen/main.c Executable file
View File

@@ -0,0 +1,42 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: roduquen <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/01 17:12:34 by roduquen #+# #+# */
/* Updated: 2019/04/01 17:12:35 by roduquen ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
#include <unistd.h>
#include <fcntl.h>
int main(int ac, char **av)
{
int fd;
if (ac != 2 || (fd = open(av[1], O_DIRECTORY | O_RDONLY)) >= 0)
{
write(2, "fillit: usage : fillit [PATH/FILE]\n", 35);
return (-1);
}
if ((fd = open(av[1], O_RDONLY)) == -1)
{
write(2, "fillit: usage : fillit [PATH/FILE]\n", 35);
return (-1);
}
else
{
if ((fd = i_got_a_fillit(fd)) < 0)
{
if (fd == FILE_ERROR || fd == ERROR)
write(1, "error\n", 6);
if (fd == OPEN_ERROR || fd == READ_ERROR)
write(2, "Something went wrong, please try again\n", 39);
}
}
return (fd);
}

46
fillit_roduquen/remove_square.c Executable file
View File

@@ -0,0 +1,46 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* remove_square.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: roduquen <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/01 17:12:36 by roduquen #+# #+# */
/* Updated: 2019/04/01 17:12:38 by roduquen ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
int remove_square(t_type *square, char nbr, char type)
{
int i;
int ret;
i = 0;
ret = -1;
while (square->str[i])
{
if (square->str[i] == nbr)
{
if (ret == -1)
ret = i;
square->str[i] = '.';
}
i++;
}
return (chose_type(type, ret));
}
int chose_type(char type, int ret)
{
if (type == -9 || type == -7 || type == -6 || type == -4
|| type == -3 || type == -1 || type == 0 || type == 1
|| type == 3 || type == 5 || type == 6 || type == 7
|| type == 8)
return (ret + 1);
else if (type == 9)
return (ret - 1);
else
return (ret);
}

42
fillit_roduquen/utilitys.c Executable file
View File

@@ -0,0 +1,42 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utilitys.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: roduquen <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/01 17:12:39 by roduquen #+# #+# */
/* Updated: 2019/04/01 17:12:50 by roduquen ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
int ft_strstr(char haystack[], char needle[])
{
int i;
int j;
i = 0;
while (i < BUFF_SIZE)
{
j = 0;
while (i + j < BUFF_SIZE && needle[j] && needle[j] == haystack[i + j])
j++;
if (!needle[j])
return (i);
i++;
}
return (ERROR);
}
void ft_memset(void *ptr, char c, int len)
{
int i;
unsigned char *str;
i = 0;
str = (unsigned char*)ptr;
while (i < len)
str[i++] = c;
}

View File

@@ -1,223 +1,46 @@
## # **************************************************************************** #
# # ------------------------------------------------------ # #
# # utiliser le makefile pour creer une librairie statique # ::: :::::::: #
# # ------------------------------------------------------ # Makefile :+: :+: :+: #
## # +:+ +:+ +:+ #
## # By: hulamy <marvin@42.fr> +#+ +:+ +#+ #
## - - - - - - - - # +#+#+#+#+#+ +#+ #
## compiler des .o # Created: 2019/06/03 21:52:28 by hulamy #+# #+# #
## - - - - - - - - # Updated: 2019/06/03 21:52:33 by hulamy ### ########.fr #
## # #
## # **************************************************************************** #
## quand on ecrit un programme il contient un main et les
## fonctions dont le main a besoin (ex ft_putchar) :
##
### #include <unistd.h>
###
### void ft_putchar(char c)
### {
### write(1, &c, 1);
### }
###
### int main()
### {
### ft_putchar('0');
### return (0);
### }
##
## on peut compiler ce fichier avec gcc en faisant :
## gcc file.c
## et ca sort un executable a.out
## si on l'execute "./a.out" ca ecrit 0 dans la console
##
## mais pour ne pas reecrire a chaque fois ft_putchar
## on peut la mettre dans une librairie qu'on inclue dans
## le fichier qui l'utilise...
## si on sort ft_putchar du fichier :
##
### int main()
### {
### ft_putchar('0');
### return (0);
### }
##
## et qu'on l'execute "gcc file.c" on va avoir une erreur
## car file.c utilise ft_putchar mais gcc ne sait pas ce
## que c'est, donc il faut qu'on le rajoute a la compilation
## on peut par exemple l'ecrire dans un fichier ft_putchar.c
##
### #include <unistd.h>
###
### void ft_putchar(char c)
### {
### write(1, &c, 1);
### }
##
## et compiler les deux :
## gcc file.c ft_putchar.c
##
## ca fonctionne mais gcc doit a chaque fois recompiler
## ft_putchar.c alors qu'il n'est pas modifie, donc on peut
## le compiler une bonne fois pour toute et le rajouter a la
## compilation finale quand on en a besoin sans que l'ordi
## ait a tout retraduire dans son langage
##
## mais si on essaye de compiler ft_putchar seul
## gcc ft_putchar.c
## ca nous donne une erreur car pour compiler, gcc a besoin
## de trouver un main !
##
## on va donc utiliser l'option -c pour
## creer une fichier objet .o qui est deja traduit en langue
## d'ordinateur et pret a etre rajoute a la compilation :
## gcc -c ft_putchar.c --> donne ft_putchar.o
## qu'on peut compiler avec le fichier qui contient le main :
##
## gcc file.c ft_putchar.o
##
## on a nos bouts de codes comme ft_putchar.o dans des fichiers
## objets prets a etre ajoutes a la compilation du main
##
## on va maintenant voir comment faire une libraire qui contien
## tous nos fichiers objets
##
##
## - - - - - - - -
## creer une lib.a
## - - - - - - - -
##
##
## pour mettre tous les fichiers .o dans un seul fichier .a
## on utilise un programme d'archive ar avec les options rc
## r indique d'inserer les .o en remplacant si necessaire
## c de creer une nouvelle archive
## le nom de l'archive doit commencer par lib et finir en .a :
## ar rc nom_de_l'archive fichier_1.o fichier_2.o etc
##
## ar rc libtest.a ft_putchar.o
##
## on obtient un fichier libtest.a qui contient les fichiers
## objets .o
##
## on peut l'utiliser a la compilation de cette manniere :
##
## gcc file.c -L. -ltest
##
## -L indique ou est la librairie (ici elle est dans le
## dossier courant .)
## -l indique son nom ("test" car on n'indique pas lib et .a)
##
##
# # -----------------------------------------------
# # ecrire un make file pour aider a la compilation
# # -----------------------------------------------
##
##
## exemple d'un makefilede basic
##
### NAME = libtest.h
### CC = gcc
### CFLAGS = -I. -c
### SRCS = example01.c \
### example02.c
### OBJ = $(SRCS:.c=.o) |ecrit les fichiers .c en .o
###
### all: $(NAME) |make execute sa premiere regle NAME
### $(NAME): $(OBJ) |NAME execute d'abord OBJ
### ar -rc $@ $< |
##
## Make a des built-in pattern rules :
## https://www.gnu.org/software/make/manual/html_node/Catalogue-of-Rules.html
## par exemple pour construire des .o a partir de .c
## qui sont utilisees par défaut si les variables
## sont bien nomee (genre CC ou CFLAGS)
##
## cependant si on veut mettre les fichiers .o dans un
## sous-fichier BUILDS il n'y a pas de built-in pattern
## il faut donc l'ecrire nous-meme :
##
### NAME = libtest.h
### CC = gcc
### CFLAGS = -I.
### SRCS = example01.c \
### example02.c
### ODIR = ./builds
### OBJS = $(addprefix $(ODIR)/, $(SRCS:.c=.o))
###
### all: $(NAME)
### $(NAME): $(OBJS)
### ar -rc $@ $<
###
### $(ODIR)/%.o : %.c
### $(COMPILE.c) -o $@ $<
##
## cette regle est appellee par $(OBJS) puisque
## cette variable appelle la regle $(ODIR/file.o)
##
## COMPILE est une built-in variable qui execute
## les regles CC et CFLAGS avec l'option -c
##
## % = "tout"
## $@ = "la valeur a gauche de :"
## $< = "la premiere valeur a droite de :"
## $^ = "toutes les valeurs a droite de :"
##
##
# ----------------------------------------------------------- #
# #
# variables modifiables #
# #
# ----------------------------------------------------------- #
NAME = libft.a NAME = libft.a
DEPS = libft.h CFLAGS = -Wall -Wextra -Werror -I.
SDIR = ./src SRCS = ft_isdigit.c ft_memccpy.c ft_putnbr.c ft_strcpy.c ft_strmapi.c ft_strsub.c \
ODIR = ./build ft_any.c ft_isprint.c ft_memchr.c ft_putnbr_fd.c ft_strdel.c ft_strmultisplit.c ft_strtrim.c \
IDIR = ./includes ft_arraymap.c ft_issort.c ft_memcmp.c ft_putnbrbase.c ft_strdup.c ft_strncat.c ft_tolower.c \
ft_atoi.c ft_itoa.c ft_memcpy.c ft_putnbrendl.c ft_strequ.c ft_strncmp.c ft_toupper.c \
CC = gcc ft_atoibase.c ft_lstadd.c ft_memdel.c ft_putnbrendl_fd.c ft_striter.c ft_strncpy.c \
CFLAGS = -Wall -Wextra -Werror -I$(IDIR) ft_bzero.c ft_lstdel.c ft_memmove.c ft_putstr.c ft_striteri.c ft_strnequ.c \
ft_convertbase.c ft_lstdelone.c ft_memset.c ft_putstr_fd.c ft_strjoin.c ft_strnew.c \
ft_foreach.c ft_lstiter.c ft_putchar.c ft_strcat.c ft_strjoinfree.c ft_strnstr.c \
ft_isalnum.c ft_lstmap.c ft_putchar_fd.c ft_strchr.c ft_strlcat.c ft_strrchr.c \
ft_isalpha.c ft_lstnew.c ft_putendl.c ft_strclr.c ft_strlen.c ft_strsplit.c \
ft_isascii.c ft_memalloc.c ft_putendl_fd.c ft_strcmp.c ft_strmap.c ft_strstr.c
# ----------------------------------------------------------- # OBJS = $(SRCS:.c=.o)
# #
# ne pas modifier en dessous #
# #
# ----------------------------------------------------------- #
## SUB_SDIR sera utilise pour creer les sous dossiers : all: $(NAME)
## avec mkdir -p ODIR/subdir1 ODIR/subdir2 ODIR/subdir3 etc...
## find $(SDIR) cherche recursivement tous le contenu de SDIR
## -type d ne trouve que les dossiers, pas les fichiers
## -mindepth 1 ne liste pas le dossier SDIR
## subst transform arg1 en arg2 dans arg3
SUB_SDIR = $(shell find $(SDIR) -mindepth 1 -type d) $(NAME): $(SRCS)
SRC = $(shell find $(SDIR) -type f -not -name '.*' -name '*.c') @gcc $(CFLAGS) -c $(SRCS)
OBJ = $(subst $(SDIR), $(ODIR), $(SRC:.c=.o)) @ar -rc $(NAME) $(OBJS)
@ranlib $(NAME)
all: $(ODIR) $(NAME)
$(ODIR):
mkdir -p $(subst $(SDIR), $(ODIR), $(SUB_SDIR))
$(ODIR)/%.o: $(SDIR)/%.c
$(COMPILE.c) -o $@ $<
$(NAME): $(OBJ)
ar -rc $@ $^
@ranlib $@
clean: clean:
/bin/rm -rf $(ODIR) @/bin/rm -f $(OBJS)
fclean: clean fclean: clean
/bin/rm -f $(NAME) @/bin/rm -f $(NAME)
re: fclean all re: fclean all
.PHONY: clean

Some files were not shown because too many files have changed in this diff Show More