diff --git a/samples/3tetribis b/samples/3tetribis new file mode 100644 index 0000000..c324e08 --- /dev/null +++ b/samples/3tetribis @@ -0,0 +1,14 @@ +...# +...# +...# +...# + +.... +##.. +.##. +.... + +.... +###. +..#. +.... diff --git a/search_map.c b/search_map.c index 0effc76..7523585 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/04/30 14:07:47 by hulamy ### ########.fr */ +/* Updated: 2019/04/30 20:58:29 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -31,13 +31,13 @@ int find_place(unsigned int *tab, t_fillist *list, int size) while (i < (size - list->height + 1) * size) { tmp = 0; - j = list->height * size + i; // construit un tmp qui est une photo de la map de la taille du tetri a un emplacement donne + j = (list->height - 1) * size + i; while (j >= i) { tmp >>= list->width; tmp |= (mask & (tab[j / 32] << j)); - tmp |= (mask & (tab[(j + size) / 32] >> (32 - j))); // cette deuxieme ligne est la au cas ou on serait a cheval sur deux int du tab + tmp |= (mask & (tab[(j + list->width) / 32] >> (32 - j))); // cette deuxieme ligne est la au cas ou on serait a cheval sur deux int du tab j -= size; } // print_map(&tmp, list->width, list->height); // test pour imprimer la photo en map @@ -61,19 +61,34 @@ void add_remove(unsigned int *map, t_fillist *list, int size, int pos) unsigned int mask; unsigned int tmp; int j; + int i; mask = ~0u << (32 - list->width); tmp = 0; - j = list->height * size + pos; + i = (list->height - 1) * list->width; + j = (list->height - 1) * size + pos; // (void)map; // construit un tmp qui est une photo de la map de la taille du tetri a un emplacement donne // ft_putnbrendl(pos); while (j >= pos) { - map[j / 32] |= ((mask >> (32 - j)) ^ map[j / 32]); - map[(j + size) / 32] |= ((mask << j) ^ map[(j + size) / 32]); // cette deuxieme ligne est la au cas ou on serait a cheval sur deux int du tab + ft_putstr("j:"); ft_putnbr(j); ft_putstr(" (32 - j):"); ft_putnbr(32 - j); ft_putstr(" i:"); ft_putnbr(i); ft_putstr(" pos:"); ft_putnbrendl(pos); + print_bits(map[j / 32], 32); + print_bits(list->tetribit << 16, 32); +// print_bits(mask >> i, 32); +// print_bits((mask >> i & list->tetribit << 16), 32); + print_bits((mask >> i & list->tetribit << 16) >> (j - i - 1), 32); + print_bits((map[j / 32] | (mask >> i & list->tetribit << 16) >> (j - i - 1)), 32); + + print_bits(map[(j + list->width) / 32], 32); + print_bits((mask >> i & list->tetribit << 16), 32); + print_bits((mask >> i & list->tetribit << 16) << (i + (j + list->width) % 32), 32); +// map[j / 32] |= ((list->tetribit >> (32 - j)) | map[j / 32]); +// map[(j + size) / 32] |= ((list->tetribit << j) | map[(j + size) / 32]); // cette deuxieme ligne est la au cas ou on serait a cheval sur deux int du tab j -= size; + i -= list->width; } + ft_putchar('\n'); } /* @@ -125,7 +140,7 @@ void search_map(t_fillist *list) unsigned int print; unsigned int tab[8]; tab[0] = 2656554334; - tab[1] = 1394456818; + tab[1] = 1394456818 ^ (1 << 11 | 1 << 22); tab[2] = 1494256918; tab[3] = 2656554334; tab[4] = 1592453883; @@ -139,8 +154,7 @@ void search_map(t_fillist *list) // imression pour tests print = tmp->tetribit; print <<= 16; -// print_map(&print, tmp->width, tmp->height); // test, imprime le tetri -// ft_putchar('\n'); + print_map(&print, tmp->width, tmp->height); // test, imprime le tetri ft_putnbrendl(find_place(tab, tmp, 10)); ft_putchar('\n'); tmp = tmp->next; @@ -166,6 +180,8 @@ void search_map(t_fillist *list) // en cours de test : // quand add_remove_marchera la ligne d'apres imprimera la map avec les pixels du tetri rajoutes a la bonne place add_remove(tab, list, 10, find_place(tab, list, 10)); + add_remove(tab, list->next, 10, find_place(tab, list->next, 10)); + add_remove(tab, list->next->next, 10, find_place(tab, list->next->next, 10)); print_map(tab, 10, 10); // lance la recursive fill_map en augmentant la taille de la map tant qu'il n'y a pas de solution