From f4c954829ecc4aae847f5903dba990d875f079fd Mon Sep 17 00:00:00 2001 From: Hugo LAMY Date: Mon, 15 Apr 2019 13:41:39 +0200 Subject: [PATCH] fonctionne avec une fonction nais aussi quatre fonctions pour les coordonnees --- .add_to_list.c.swp | Bin 0 -> 16384 bytes a.out | Bin 0 -> 12968 bytes add_to_list.c | 133 +++++++++++++++++++++++++++++++++------------ fillit.h | 5 +- 4 files changed, 101 insertions(+), 37 deletions(-) create mode 100644 .add_to_list.c.swp create mode 100755 a.out diff --git a/.add_to_list.c.swp b/.add_to_list.c.swp new file mode 100644 index 0000000000000000000000000000000000000000..f0261a8a79f0a5d1a2793db5a7b40ea1b8c1e49f GIT binary patch literal 16384 zcmeI2TZ|J`7{?E&;D{(eV*~@9-3@Hp*|syYU4-s-qmY;wk?;a0?ACSYh0fY-mv*{z z*{D&u#Kf2o6B81MF)==fkq3D2f-&&{V~h`qmqbD|#u$_*4G$P!{D0@nwA0dEEASx6 z8Tc`CZr}ON|6IzPGrNtQk3GR3iX|AX6^wm7b$Wd3PfOT^7-NN6(Vm*6goUr1RoOIc zZipqUSiZ7A*5{${p8WNEJ~EC0fr24}%1;0!ngj)47OI~WBcU>Ga|8dwAvxU>X1gHOSG;BBxA zM8P_+27GlJV{d_D;5G0lxF4(lOTmY?GWH5M0A2(yfbC!#*aDKk1R?MsSPQOT!{=M@ z8TbI40LMWURKQNK5v&D^!7ms;G=|;>hrmJ5{iV@&AJNgOvp+Xxrg@6jEgt1{lk40Z zX2Dd0QfDn5j5E`%p>E1Y`K)I>9@k(m#dD?XM5bJM%7WspitgHW29>~p3pSU^8vmdnaDJ5C=r4uk?@pVES57NlE0j%s4$Q4 z1adJA0eFG@;(%g*oZ_P?Zt(T%xhyv3q{r%L8DvQFo)quz>kl(OvzO2);_y_8M@=dX zLn%HO4j39tk42*)uShsxjB-Y)G5_j|C~T$EaH_K}R=PW1d`GNwm|E5}7W75eTXY%W zi9l<7SUu4Gp(K^q$mqI5)p;bjQKRdwC%;&Dt9FAk#nadkgVtR(1Ek^URVlhLUSav39lKKN!*C!!PF<08- z7MjCa*B!(ba?YNDE5`Dq7@=Y0Xp9efk-mqnilxgYZ>RA{a<*Mp05G^Vh&&CUzwv(6c4U~|D^@u7q$!k7hJ?JIqQKX$Lpnf zSNe+;G+3Iv7r!Ue0qBVN^l$n9!}Ydcz7FVa>FqFrx^F?p9_VvQnPM%Q<0Dl!>y%@K zQPzm+l^_1b3cZZQBUn*y)WsulGI#?o-{6kvtnKEqNp2bDrnr%an?u|jOeV~vv4QWN zc&rIKqinBeA6(lU}mgB=a>KAkN3H_sfuwkGQ^=KX;o zJT=TU4Q`%I`pp`dvMV!A>0$Ae_h=w*;87USlfI>ZO~1*3%-ubbwWdY*=~?#;2L7)Z z%XDWlsV8Md??K*tgWcI^%au&}Ch`s$$4)%#U^~xsGR;#iO`LKy4#uWzr$py#+|CSeZ@15$Y29lT{>X+kTMw_= fx1;?NwX07JWnr9P+9)Oi;$#*3!;xT^4i5hTBX=dq literal 0 HcmV?d00001 diff --git a/a.out b/a.out new file mode 100755 index 0000000000000000000000000000000000000000..a9a06a7efbc32002ef5bba8d6cd1b1b1f28ee79d GIT binary patch literal 12968 zcmeHOUu;`f89#2^&K=&ag9dcaQEMY(rI5DJjX@XWOg-K0HZRRuqcK!2iQ^DUPEy4- zw3Uo1c}BUubyW!=@i1)#?O|vWM17&WL`e&CK$hl773xDDg5)%IYg#`<<5Fh?;aCJMBa@EuF~@r)^Rvzp)*XU(oDf;nskF$#08Eko>fIOv-ECMWUp$?eN>2R5?9j>Y*CxMivz>4!xOk&M)3OskOHPbv$%)ZP zfxG?juE~#lPC$4k57{Df^6S&WuLt^%_B&d_(rzqd(tryvaq=tHoJd61w273KJ~=)- znbMADrhsqE&tgaGgT`Ax_IJvuX{n)q$1fC?@>%={ck(0ooa;u@hSO`SgyeP07dH6? zFwO!eKbXh`Yy0ZOLodC+4;-@g#GVej0VjCdRF33w@_H2eR&+r|a|cjvqX8y_frn9# z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iMs{aUDa)$kmN&sP&A5t-t$OPa2nD@=k6$RRGSC?z`xodml#UeP%*D#hkoHa{ln^*TN;90=4fM)^E0-gmt3wRdrEZ|wdvw&v-&jOwW zKAjfmel$e)C9FF_k8{Oicx@Q(!|`~1aEhH{Q=#sNHa?U}O~wh^2JASVqi05e3Giun 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 literal 0 HcmV?d00001 diff --git a/add_to_list.c b/add_to_list.c index 371646a..8eb040b 100644 --- a/add_to_list.c +++ b/add_to_list.c @@ -6,34 +6,63 @@ /* By: hulamy +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/14 15:20:53 by hulamy #+# #+# */ -/* Updated: 2019/04/15 00:24:25 by hulamy ### ########.fr */ +/* Updated: 2019/04/15 13:41:06 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ #include "fillit.h" #include - -void find_start_and_end(char **square, int *x1, int *x2, int *y1, int *y2) +int start_line(char **square) { int i; + int x; i = 4; - while (*x1 < 4 && i == 4 && !(i = 0) && square[++(*x1)][0] != '#') - while (i < 4 && square[*x1][i] != '#') + 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; - while (*y1 < 4 && i == 4 && !(i = 0) && square[0][++(*y1)] != '#') - while (i < 4 && square[i][*y1] != '#') + 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; - while (*x2 >= 0 && i == -1 && (i = 3) && square[--(*x2)][3] != '#') - while (i >= 0 && square[*x2][i] != '#') + 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; - while (*y2 >= 0 && i == -1 && (i = 3) && square[3][--(*y2)] != '#') - while (i >= 0 && square[i][*y2] != '#') - i--; + 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) @@ -63,39 +92,73 @@ char **fill_tetraminos(char **square, int x1, int y1, int x2, int y2) return (result); } -int add_to_list(char **square) +void find_start_and_end(char **square, int **x) { - t_fillist *list; + int i; + + x[0][0] = -1; // x1 + x[0][1] = -1; // y1 + x[0][2] = 4; // x2 + x[0][3] = 4; // y2 + i = 4; + while (x[0][0] < 4 && i == 4 && !(i = 0) && square[++(x[0][0])][0] != '#') + while (i < 4 && square[*(x[0])][i] != '#') + i++; + i = 4; + while (x[0][1] < 4 && i == 4 && !(i = 0) && square[0][++(x[0][1])] != '#') + while (i < 4 && square[i][x[0][1]] != '#') + i++; + i = -1; + while (x[0][2] >= 0 && i == -1 && (i = 3) && square[--(x[0][2])][3] != '#') + while (i >= 0 && square[x[0][2]][i] != '#') + i--; + i = -1; + while (x[0][3] >= 0 && i == -1 && (i = 3) && square[3][--(x[0][3])] != '#') + while (i >= 0 && square[i][x[0][3]] != '#') + i--; +} + +int add_to_list(char **square, t_fillist *list) +{ + int *tab; int x1; int x2; int y1; int y2; - x1 = -1; - y1 = -1; - x2 = 4; - y2 = 4; - if (!(list = (t_fillist*)malloc(sizeof(*list)))) - return (0); - find_start_and_end(square, &x1, &x2, &y1, &y2); + tab = (int*)malloc(sizeof(int) * 4); + find_start_and_end(square, &tab); + x1 = tab[0]; + 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); - -// int i; // pour imprimer -// i = -1; // -// while (++i < list->size[1]) // -// printf("%s\n", list->tetraminos[i]); // - return (0); } -// int main(int ac, char **av) -// { -// if (ac == 5) -// { -// add_to_list(++av); -// } -// return (0); -// } +int main(int ac, char **av) +{ + static t_fillist *list; + 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]); + } + + return (0); +} diff --git a/fillit.h b/fillit.h index e674e97..78e28c6 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 00:26:08 by hulamy ### ########.fr */ +/* Updated: 2019/04/15 10:43:51 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -37,7 +37,6 @@ void print_error(char *s); int check_file_errors(char *file); int check_tetri_errors(char *tetri); int check_tetri_errors2(char *tetri); -int add_to_list(char **square); typedef struct s_fillist { @@ -49,4 +48,6 @@ typedef struct s_fillist struct s_fillist *next; } t_fillist; +int add_to_list(char **square, t_fillist *list); + #endif