From 730964a8173d448ed87e1b35d972f1100f5f18e3 Mon Sep 17 00:00:00 2001 From: Hugo LAMY Date: Fri, 19 Apr 2019 15:34:05 +0200 Subject: [PATCH] modifie add_to_list pour fonctionner avec du binaire --- .parse_input.c.swo | Bin 0 -> 12288 bytes add_to_list.c | 172 +++++++++++++++------------------------------ fillit.h | 12 ++-- parse_input.c | 4 +- read_file.c | 2 +- 5 files changed, 67 insertions(+), 123 deletions(-) create mode 100644 .parse_input.c.swo diff --git a/.parse_input.c.swo b/.parse_input.c.swo new file mode 100644 index 0000000000000000000000000000000000000000..90e58e08fc209bacee8a6c959b7789c93f1f66e1 GIT binary patch literal 12288 zcmeI2Piz!b9LFCTg;7wWBpSrz*EY1<-O|}9i_oQifLdZr1;m!bw78kh&a$t&ompny zw3G@&q9J-UBpygi^dJ}ihJz>v6A#8jjVCl7B_2I+^T5IHdo#1UMM4@RF(hxwhnacr z_kQzx-{0@Op<(9oM<-sUUHt`y;|aztU%E1TsBGW8 zX?n+im6xNtIy>m8C#UbikshKI&h{ig07QsJ|OkgQF zue;@(-0G87Kr5gX&D#xgy8Z2|LO1l zpFPgl>tGYO`WRz1um$|EiLsNQ2VC38*xTSO&;UNDgE6odjDk);;2H2VFu>oBGWH#~ z488?vlVBsbv4OGQ!8PzT_!xWyE`oQ!IdB%#00&j@5_l10 zz-F)k++2@Xz%}qQ_!L|O?}GE-3|IiKfMKu|{Pi$nKZ2{^5;zYyI0z1aF)#|QBY)q5 ztKdWM0eBO<1|~oOSU~0ZKCDw6vR2^#SK#z%X5f!e=b@lslBew>o_kX4L1QD}o~UFx zXT8o|dEac<7NV&yu@;>-m;S4{f?3Sv$?ouX~<1~~Qh5VE|V;$>d#tJi%e)Y`m zZpv^xdArq%&a4Tt)WG*tRCed0<9%e4TdCNN8;~7Q;CkgqnK&+;h&Y827ZkdIp!p~i zF0AcJg*#Q4BLv6ygzH6cMZ%9lG=n7VSDO_s1#Z70N&zr&dzF z;&Jl%GAKDGbv0uRVxpL5zDMOfZk*5MWNV@XZrbFTN2aYo>0llvdGxF_^PEbD-n62S z#-ymy7G+eN^^($3w^9*V8*s;ru<8c_HHZj9v4>3ah4IPpsd3sre&EoNaT-6mZxYs? zGBM`m$mE*i8rcovv6$z~KwgF(3R`f8MEt>CD2%Ks$YDA-Jvq6Dt*}L(myNd1_#m7e zP&N*YF)W+F6;a?(EFbbB1D2~PDV&O+O29xW_^$@ft zvFVky2PqTX%#adXsvW0Fjlcw?lyOV45YmoBPj%b7O3!$y+*Zw1i!!Umwl7H|9*TuJ zQ?+b;b(gn?0VgIGIE3SE17II ziJh{PDNv5Et;uzT>?IFRVwU?}4PN4XFY&8lh|AAt7FQaAOl2BD^YQt5%*wF=U&Y%t8JHIvsH;tcY*Xxlkpuqi@J&T(kLwjT(}vlk2)>Xx7AC@3x5b;UDo#>QL>b0&>*(m9WP>?;Wa8jd zY5&C3tL=LY!9s=K#XYAU;Z@QZfB4&9?ZiJyvy{DO2O%UlyoX2XaJo^(o2gu+fxI +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/14 15:20:53 by hulamy #+# #+# */ -/* Updated: 2019/04/18 10:56:38 by hulamy ### ########.fr */ +/* Updated: 2019/04/19 15:33:04 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ #include "fillit.h" #include +#include "libft/includes/libft.h" /* -** Function that fills the char **tetraminos section of the structure -** with the most little rectangle that fit the tetraminos +** this function prints a 16 bites short */ -char **fill_tetraminos(char **square, int *tab) +void print_bits(short line) { - char **result; - int height; - int length; - int i; - int j; + int mask; - i = 0; - height = tab[2] - tab[0] + 1; - length = tab[3] - tab[1] + 1; - if (!(result = (char**)malloc(sizeof(*result) * (height + 1)))) - return (NULL); - result[height] = NULL; - while (i < height) + mask = 1 << 16; + while (mask >>= 1) + (line & mask) ? ft_putnbr(1) : ft_putnbr(0); + ft_putchar('\n'); +} + +/* +** this function transforme a tetrminos char* into a short of 16 bites +** then it fills it and its reverse into the list +*/ + +int fill_list(char *line, t_fillist *list) +{ + short tmp; + + while (*line) { - if (!(result[i] = (char*)malloc(sizeof(**result) * (length + 1)))) - return (NULL); - result[i][length] = '\0'; - i++; + list->tetribit <<= 1; + if (*line == '\n') + line++; + if (*(line++) == '#') + list->tetribit |= 1; } - i = -1; - while (++i < height && (j = -1)) - while (++j < length) - result[i][j] = square[tab[0] + i][tab[1] + j]; - return (result); + tmp = list->tetribit; + while (tmp) + { + if (tmp & 1) + list->tibirtet |= 1; + list->tibirtet <<= 1; + tmp >>= 1; + } + return (0); } /* -** This function calculate the line and columns where the tetraminos -** start and end, by skipping the empty lines -** -** ! it has a little bug so far, i need to fix it +** this function create the linked list and add a new structure linked each time needed */ -void find_start_and_end(char **square, int **x) -{ - int i; - - 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] != '#') - 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--; -} - -/* -** this function first call find_start_and_end to find the coordinates -** of start en end of the most little rectangle that fit the tetraminos -** -** it allows it to fill the structure with the size information -** (for instance : -** "##" ".#" ".#" -** is a tatraminos of 2 by 3) -** then it fills also the area information (2 * 3 = 6) -** -** and finally it calls fill_tetraminos to fill the char **tetraminos -*/ - -int fill_list(char **square, t_fillist *list) -{ - int *tab; - - tab = (int*)malloc(sizeof(int) * 4); - find_start_and_end(square, &tab); - list->size[0] = tab[3] - tab[1] + 1; - list->size[1] = tab[2] - tab[0] + 1; - list->area = list->size[0] * list->size[1]; - list->tetraminos = fill_tetraminos(square, tab); - return (1); -} - -/* -** this function first checks if the structure has been created -** if not, it creates the first element, else it adds an element -** and modifies the initial pointer to link to the new first element -** -** then it calls fill_list to fill the data of the structure -*/ - -int add_to_list(char **square, t_fillist **list) +int add_to_list(char *line, t_fillist **list) { t_fillist *tmp; @@ -124,30 +71,27 @@ int add_to_list(char **square, t_fillist **list) else tmp->next = *list; *list = tmp; - fill_list(square, *list); + fill_list(line, *list); return (1); } -/* -**int main(int ac, char **av) -**{ -** static t_fillist *list = NULL; // avant d'appeller add_to_list il faut declarer un pointeur static vers la structure -** int i; -** -** if (ac > 1) -** { -** add_to_list(++av, &list); // l'appel de la fonction se fait avec un carre valide de 4*4 et l'adresse du pointeur vers la liste -** 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); -**} -*/ +int main(int ac, char **av) +{ + static t_fillist *list = NULL; // avant d'appeller add_to_list il faut declarer un pointeur static vers la structure + int i; + + if (ac > 1) + { + add_to_list(*(++av), &list); + while (list && (i = -1)) + { + printf("%d\n", list->tetribit); + print_bits(list->tetribit); + print_bits(list->tibirtet); + list = list->next; + } + } + + return (0); +} + diff --git a/fillit.h b/fillit.h index 8e6efcf..94895c2 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/18 11:46:51 by vmanzoni ### ########.fr */ +/* Updated: 2019/04/19 14:52:10 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -28,11 +28,9 @@ typedef struct s_fillist { - int id; - char **tetraminos; - int position[2]; - int size[2]; - int area; + short tetribit; + short tibirtet; + int position; struct s_fillist *next; } t_fillist; @@ -46,6 +44,6 @@ void parse_input(char *input); int check_file_errors(char *file); int check_tetri_errors(char *tetri); int check_tetri_errors2(char *tetri); -int add_to_list(char **square, t_fillist **list); +int add_to_list(char *square, t_fillist **list); #endif diff --git a/parse_input.c b/parse_input.c index b52d673..e129eb3 100644 --- a/parse_input.c +++ b/parse_input.c @@ -6,7 +6,7 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/15 14:48:14 by vmanzoni #+# #+# */ -/* Updated: 2019/04/18 13:07:56 by vmanzoni ### ########.fr */ +/* Updated: 2019/04/19 12:53:40 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -87,6 +87,8 @@ void parse_input(char *input) short test; //DELETE BEFORE EVAL i = 0; + printf("input: %s\n", input); + printf("end\n"); while (input[i]) { j = 0; diff --git a/read_file.c b/read_file.c index a53e571..0afb78c 100644 --- a/read_file.c +++ b/read_file.c @@ -6,7 +6,7 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/13 12:09:46 by vmanzoni #+# #+# */ -/* Updated: 2019/04/15 14:48:36 by vmanzoni ### ########.fr */ +/* Updated: 2019/04/19 12:50:32 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */