From aa8ec6fe66e3eff2273593bcec75412845734e43 Mon Sep 17 00:00:00 2001 From: Hugo LAMY Date: Fri, 10 May 2019 20:40:16 +0200 Subject: [PATCH] tentative echouee d'oter les modulo et division dans le fit_in_place --- .search_map.c.swn | Bin 16384 -> 0 bytes search_map.c | 116 ++++++++++++++++++++-------------------------- 2 files changed, 50 insertions(+), 66 deletions(-) delete mode 100644 .search_map.c.swn diff --git a/.search_map.c.swn b/.search_map.c.swn deleted file mode 100644 index 0dee589a44d9a36b7a9fac698715f4b83b33cbd6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 16384 zcmeI3ON<;x8ONId!4sSq*#aRBQQ0fJ^YD81g&mK*D+qZg5-18Hkx=ZcdS`k(wcFD@ z?#HejI}gZ95S%Cq2gE}n2@*m9aUhC(KnMlJBya%{@rnfD0*FJz4H0qR_f>WG^sd*& zm>fXrw*K3Xs`|R>UtfJS^{@8w^j)`oQXSks?{K`&ah7j??dbCB*Em1?gyRfS-yNQk zgi9aZTr@X2uz!Abe?PiZ&ik#wc0Wv`U`)YrbRlXmR6QFpL3bVvKUm$Ff% zRSZ-NTqy(BI&-r#(^7h3&u+DA=bcw-s47=6P%%(3P%%(3P%%(3P%%(3P%-d-$Uri> z%6Wi#UzOGUOm=?9rt>?q`#ZApeVfv=+v-#?P%%(3P%%(3P%%(3P%%(3P%%(3P%%(3 zP%-d7$bj2(oGI#cNCW`(|MT_#_jWkWJ>XjKgXR=MQ@m|OIJ@_Sf1-t;B0p9?(fC=ycupPW`jpIBD9s+lPeP9>Z4z_`R)*R<+ zU=8%Z61W9i5B{*taefYd2A%^?g2%u^;6V_B6JP{};4ruW90Y%RkK?=veg}RG&VlcO z?|`Sl2;2rHz@M&moY%lFz|-JCa0u)J9|Z3QyTDHH>bo81C*Vc!ZSYm_6nG3g3eJES z48W(rUN8Z6fUChD-{m;J1?Ry_;3&8b`~xxON8owz9QZQ$5_lXu2<`)O;Lr5wPr&;=y$GK=)OBcV7p+rI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fQ+Ydf<3Z?Ud@oOQ6Q|MUI*uk2u537!CF!9!pjXz&&~z$@To@C^7o5N+TkG=cAf zCqW2&ump~Qqu?`OJE(ze;IHTde*v$7^WbIhJXi-B+y!n0H-nqN$H4381it~l1}}(3&=>SLtMpISuR^O8)JhIc6`5}Ei zM9d${BUGCrMitKNU1X~uw}to|4wsS8S+H6)i*82I?;>qv-7F0=YBahuTH%J)O8u;? zZ0fzBW=kR-iL@(QwoCeEdPK67{KfjbR*1bu#T&1D>O~f->oy#RpY|8*&afrXlPwvu z^cJVxgA)q#VV{ex7vZw(R0zc`Ia#SA<%wJ*a;bTovN6JTj!q_d5c+FgZ?mQsc@?VZYuKW4Y>s1ycnIX`Zp~AbPXNO(jkx z#|1QEMU;>YuGcK$0UaRQAzKnAnF=KX;zZ|&%pQlSirLySTUuhoJCU+0K(2c|HjOs( zQfQr4)5o&F{^H^)|ieOu6 xUwN0)D%z5lv0$sr7_s5NG`mplvbkwPRWEllhsa;n_UP8a)6^bc2djIWe*t1)b-@4t diff --git a/search_map.c b/search_map.c index b69c5dd..262131a 100644 --- a/search_map.c +++ b/search_map.c @@ -6,7 +6,7 @@ /* By: hulamy +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/27 20:47:22 by hulamy #+# #+# */ -/* Updated: 2019/05/10 17:00:08 by hulamy ### ########.fr */ +/* Updated: 2019/05/10 20:39:19 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,25 +16,42 @@ ** function that look if a tretri fit in a place */ -unsigned int fit_in_place(unsigned int *map, t_fillist *list, int size, int pos) +unsigned int fit_in_place(unsigned int *map, t_fillist *list, int size, int pos, int number, int place) { unsigned int tmp; unsigned int mask; - int j; + int i; - mask = ~0u << (32 - list->width); // creer un mask avec les size bits de gauche a 1 (ex: 11111110000000000000000000000000) - j = (list->height - 1) * size + pos; +// (void)number; +// (void)place; + (void)pos; + + i = -1; tmp = 0; - while (j >= pos) + mask = ~0u << (32 - list->width); // creer un mask avec les size bits de gauche a 1 (ex: 11111110000000000000000000000000) + while (++i < list->height) { - tmp >>= list->width; - tmp |= (mask & (map[j / 32] << j)); - tmp |= (mask & (map[(j + list->width) / 32] >> (32 - j))); - j -= size; + if (place >= 32) + { + place -= 32; + number++; + } + tmp <<= list->width; + tmp |= ((mask & (map[number] << place)) | (mask & (map[number + 1] >> (32 - place)))) >> (32 - list->width); + place += size; } - if (!((tmp >> 16) & list->tetribit)) - return (pos + 1); - return (0); + +// mask = ~0u << (32 - list->width); +// i = (list->height - 1) * size + pos; +// tmp = 0; +// while (i >= pos) +// { +// tmp >>= list->width; +// tmp |= (mask & (map[i / 32] << i)) | (mask & (map[(i / 32) + 1] >> (32 - i))); +// i -= size; +// } + + return (!((tmp >> 16) & list->tetribit)); } /* @@ -43,15 +60,27 @@ unsigned int fit_in_place(unsigned int *map, t_fillist *list, int size, int pos) int find_place(unsigned int *tab, t_fillist *list, int size, int pos) { - // boucle jusqu'a la dernier place pour le tetri dans la map ou qu'il fit dans un trou + int row; + int number; + int place; + + row = pos % size; + place = pos % 32; + number = pos / 32; + // boucle jusqu'a la dernier place pour le tetri dans la map ou qu'il entre dans un trou while (pos < (size - list->height + 1) * size) { // pour ne pas deborder a droite de la map - if (pos % size == size - list->width + 1) +// if (pos % size > size - list->width) + if (place >= 32 && ++number) + place -= 32; + if (row > size - list->width && (row = -1)) pos += list->width - 2; - else if (fit_in_place(tab, list, size, pos)) + else if (fit_in_place(tab, list, size, pos, number, place)) return (pos + 1); pos++; + row++; + place++; } return (0); } @@ -75,62 +104,17 @@ void add_remove(unsigned int *map, t_fillist *list, int size, int pos) while (j >= pos) { map[(j - 1) / 32] ^= (mask & tetri << (16 + i)) >> (j - 1); - if (j % 32 != 1) - map[(j + size) / 32] ^= (mask & tetri << (16 + i)) << (32 - j + 1); + map[(j - 1) / 32 + 1] ^= (mask & tetri << (16 + i)) << (32 - j) << 1; j -= size; i -= list->width; } } -/* -** function that try to optimize the speed -** TOTAL FAILURE :p -*/ - -int check_others(unsigned int *map, t_fillist *list, int size, int num) -{ - t_fillist *tmp; - int dots; - int total; - int i; - int j; - - dots = 0; - i = -1; - num *= 4; - total = size * size; - while (++i < total && dots <= total - num) - { - tmp = list->next; - j = 1; - // saute les position pas vides - while (1 << (i % 32) & map[i % 32]) - i++; - // pour chaque position vide regarde si chaque tetri non encode places peuvent y rentrer - while (j && tmp) - { - // si le tetri est trop a droite ou trop en bas il ne rentre pas ce n'est pas la peine de chercher donc on passe au tetri suivant - if (tmp->width > (size - i % size) || (total - i) <= (tmp->height * size)) - tmp = tmp->next; - // sinon verifier si on peut le mettre a cette position et si on ne peut pas passer au tetri suivant - else if (!fit_in_place(map, list, size, i)) - tmp = tmp->next; - // si le tetri peut rentrer on arrete la boucle en mettant j = 0 - else - j = 0; - } - // si j existe c que le tetri ne pouvait pas etre place donc on rajoute 1 au compteur de point isoles - if (j) - dots++; - } - return (dots > total - num); -} - /* ** function that recursively try to fill the map with the tetris */ -int fill_map(unsigned int *map, t_fillist *list, int size, int num, t_fillist *link) // DEBUG "link" +int fill_map(unsigned int *map, t_fillist *list, int size, t_fillist *link) // DEBUG "link" { int pos; @@ -143,10 +127,10 @@ int fill_map(unsigned int *map, t_fillist *list, int size, int num, t_fillist * add_remove(map, list, size, pos); list->position = pos; // print_final_map(link, size); ft_putnbrendl(pos); print_map(map, size, size, '#'); ft_putchar('\n'); // DEBUG - if (check_others(map, list, size, num) && fill_map(map, list->next, size, num, link)) + if (fill_map(map, list->next, size, link)) return (1); add_remove(map, list, size, pos); - list->position = -1; // DEBUG +// list->position = -1; // DEBUG } return (0); } @@ -206,7 +190,7 @@ void search_map(t_fillist *list) // lance la recursive fill_map en augmentant la taille de la map tant qu'il n'y a pas de solution - while (!fill_map(map, list, size, num, list)) + while (!fill_map(map, list, size, list)) map = init_map(size++); print_final_map(list, size); // DEBUG print_map(map, size, size, '#'); // DEBUG