diff --git a/.add_to_list.c.swp b/.add_to_list.c.swp index f0261a8..d2f047a 100644 Binary files a/.add_to_list.c.swp and b/.add_to_list.c.swp differ diff --git a/.fillit.h.swp b/.fillit.h.swp new file mode 100644 index 0000000..ed2f8e4 Binary files /dev/null and b/.fillit.h.swp differ diff --git a/a.out b/a.out index a9a06a7..d80bc10 100755 Binary files a/a.out and b/a.out differ diff --git a/add_to_list.c b/add_to_list.c index 8eb040b..ed777f7 100644 --- a/add_to_list.c +++ b/add_to_list.c @@ -6,65 +6,13 @@ /* By: hulamy +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/14 15:20:53 by hulamy #+# #+# */ -/* Updated: 2019/04/15 13:41:06 by hulamy ### ########.fr */ +/* Updated: 2019/04/15 16:06:37 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ #include "fillit.h" #include -int start_line(char **square) -{ - int i; - int x; - - i = 4; - x = -1; - while (x < 4 && i == 4 && !(i = 0) && square[++x][0] != '#') - while (i < 4 && square[x][i] != '#') - i++; - return (x); -} - -int start_column(char **square) -{ - int i; - int x; - - i = 4; - x = -1; - while (x < 4 && i == 4 && !(i = 0) && square[0][++x] != '#') - while (i < 4 && square[i][x] != '#') - i++; - return (x); -} - -int end_line(char **square) -{ - int i; - int x; - - i = -1; - x = 4; - while (x >= 0 && i == -1 && (i = 3) && square[--x][3] != '#') - while (i >= 0 && square[x][i] != '#') - i--; - return (x); -} - -int end_column(char **square) -{ - int i; - int x; - - i = -1; - x = 4; - while (x < 4 && i == 4 && !(i = 0) && square[++x][0] != '#') - while (i < 4 && square[x][i] != '#') - i++; - return (x); -} - char **fill_tetraminos(char **square, int x1, int y1, int x2, int y2) { char **result; @@ -96,10 +44,10 @@ void find_start_and_end(char **square, int **x) { int i; - x[0][0] = -1; // x1 - x[0][1] = -1; // y1 - x[0][2] = 4; // x2 - x[0][3] = 4; // y2 + x[0][0] = -1; + x[0][1] = -1; + x[0][2] = 4; + x[0][3] = 4; i = 4; while (x[0][0] < 4 && i == 4 && !(i = 0) && square[++(x[0][0])][0] != '#') while (i < 4 && square[*(x[0])][i] != '#') @@ -118,7 +66,7 @@ void find_start_and_end(char **square, int **x) i--; } -int add_to_list(char **square, t_fillist *list) +int fill_list(char **square, t_fillist *list) { int *tab; int x1; @@ -132,32 +80,52 @@ int add_to_list(char **square, t_fillist *list) y1 = tab[1]; x2 = tab[2]; y2 = tab[3]; - printf("%d %d %d %d\n", x1, y1, x2, y2); - -// x1 = start_line(square); -// y1 = start_column(square); -// x2 = end_line(square); -// y2 = end_column(square); list->size[0] = y2 - y1 + 1; list->size[1] = x2 - x1 + 1; list->area = list->size[0] * list->size[1]; list->tetraminos = fill_tetraminos(square, x1, y1, x2, y2); - return (0); + return (1); +} + +int push_to_end(t_fillist **list) +{ + t_fillist *tmp; + + if (!(tmp = (t_fillist*)malloc(sizeof(*tmp)))) + return (0); + if (!(*list)) + tmp->next = NULL; + else + tmp->next = *list; + *list = tmp; + return (1); +} + +int add_to_list(char **square, t_fillist **list) +{ + if (!(push_to_end(list))) + return (0); + fill_list(square, *list); + return (1); } int main(int ac, char **av) { - static t_fillist *list; + static t_fillist *list = NULL; int i; - i = -1; - if (!(list = (t_fillist*)malloc(sizeof(*list)))) - return (0); if (ac > 4) { - add_to_list(++av, list); - while (++i < list->size[1]) - printf("%s\n", list->tetraminos[i]); + add_to_list(++av, &list); + if (ac == 9) + add_to_list(av += 4, &list); + while (list && (i = -1)) + { + while (++i < list->size[1]) + printf("%s\n", list->tetraminos[i]); + printf("\n"); + list = list->next; + } } return (0); diff --git a/fillit.h b/fillit.h index 78e28c6..f4e6a06 100644 --- a/fillit.h +++ b/fillit.h @@ -6,7 +6,7 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/03/01 13:34:46 by vmanzoni #+# #+# */ -/* Updated: 2019/04/15 10:43:51 by hulamy ### ########.fr */ +/* Updated: 2019/04/15 15:51:03 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -48,6 +48,6 @@ typedef struct s_fillist struct s_fillist *next; } t_fillist; -int add_to_list(char **square, t_fillist *list); +int add_to_list(char **square, t_fillist **list); #endif