From 8423652fb09ced916a1266aa8a79b42310b03892 Mon Sep 17 00:00:00 2001 From: Hugo LAMY Date: Mon, 15 Apr 2019 16:07:19 +0200 Subject: [PATCH] add_to_list fonctionne et creer une liste chainee coherente, mais encore quelques bugs si la liste comporte une erreur --- .add_to_list.c.swp | Bin 16384 -> 16384 bytes .fillit.h.swp | Bin 0 -> 12288 bytes a.out | Bin 12968 -> 8776 bytes add_to_list.c | 112 ++++++++++++++++----------------------------- fillit.h | 4 +- 5 files changed, 42 insertions(+), 74 deletions(-) create mode 100644 .fillit.h.swp diff --git a/.add_to_list.c.swp b/.add_to_list.c.swp index f0261a8a79f0a5d1a2793db5a7b40ea1b8c1e49f..d2f047a851eb0d1de0f77546419cd8dda56984e7 100644 GIT binary patch delta 1753 zcma*nUuaWT9Ki9@v}?U~T`Ouk_Tp_<%1zoxTK{ym>&?_T9WN;0yKFMYC<>x|&?o;q2v)_4!axy0MN#)XH*K264m{zLd++)4 zJNKO5Nrr|BhK33%zYKJK9@3kauN0IDA;ypV(Y@`#SmpEbf3l^;4H@RCnUbXW_$t@ zZ74%23gN+HO*mpoV=_$O3~X#f5Y6~^0fBJ}qu7Ba_)v{2B|`j+A8;JQh~q1S(TNZ~ zMJrmc1dob^xKr$~N^UOTG=^~i9axNF6rm8e-VtIFmv9lsaTpGE!$JqvVHH-O2?DR! z^E->T}?eqx{^0^pBmMZzj5X< zF#VW*UDxfAJq=SOt6KuATUIouH~IhZIBVV$Vhrkkwu*}?ugZmZiCdV&IDW?%e!`D9 zgh6zo70q}b4~aF237o@OoIx6Do>BaY5m3^fRopBqJusUmX`6v9vyVnV-Orf*39ADj zG%8*0ubd^T4bEhfrL()!r?NXyqt1)`-t@_n=Ca6s8o%BZi(9&TV)VK?-H5q6My?na z>Fre~$~}XTLA{=xZP4r7!=>V?a~IjEx3%eORQKH8_4ScKy2{&Tm0TOFEg`5nInoN& F{s$uwleGW< delta 1531 zcmbW%U1(Eh7{Ku-nYNy)ZQMthO6##M?Mc$EI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05e3Giun zo4-XHAJY;i67g&%fw%8NH2m3gW@sv-v4aV`HfKK`O|nx%BO_X7QcES%8TLEh_)v0! z{oY5X7i?21Igw!Bk58tu;}h(MU97beM;FyyR?Bg-CELYjzJZqWyQw9Ge+I}*4UH!! zCe!RqALfyB4xxrw*<1LxhSPh|z4a|*bNgvvpA@^bbJ4fxYf;)%y>HPz6L}NO4+a>M(_5_1ou~4Mo{{nC`m}dY0 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