From f035f37607f5bb88e4a4ea022eba2d2c2a8d456f Mon Sep 17 00:00:00 2001 From: Hugo LAMY Date: Wed, 1 May 2019 23:13:24 +0200 Subject: [PATCH] this time add_remove really fucking works --- search_map.c | 87 ++++++++-------------------------------------------- 1 file changed, 12 insertions(+), 75 deletions(-) diff --git a/search_map.c b/search_map.c index b01d30e..bed0874 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/01 22:50:17 by hulamy ### ########.fr */ +/* Updated: 2019/05/01 23:12:57 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -67,42 +67,21 @@ void add_remove(unsigned int *map, t_fillist *list, int size, int pos) // change les bits du tetri sur la map a la position donnee while (j >= pos) { -// /* tests pour trouver la nouvelle equation - 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, 32); - print_bits(list->tetribit << (16 + i), 32); - print_bits((mask & list->tetribit << (16 + i)), 32); - print_bits((mask & list->tetribit << (16 + i)) >> (j - 1), 32); - print_bits((map[j / 32] | (mask & list->tetribit << (16 + i)) >> (j - 1)), 32); - - print_bits(map[(j + list->width) / 32], 32); - print_bits((mask & list->tetribit << (16 + i)), 32); - print_bits((mask & list->tetribit << (16 + i)) << ((33 - j % 32) % 32), 32); - print_bits(map[(j + list->width) / 32] | (mask & list->tetribit << (16 + i)) << ((33 - j % 32) % 32), 32); -// */ - -// ancienne version avec ancienne equation - /* print_map(map, size, size); // POUR DEBUG ft_putstr("map[j / 32] : "); print_bits(map[j / 32], 32); // POUR DEBUG - ft_putstr("mask : "); print_bits((mask >> i & list->tetribit << 16) >> (j - i - 1), 32); // POUR DEBUG - */ -// map[j / 32] ^= (mask >> i & list->tetribit << 16) >> (j - i - 1); - /* + ft_putstr("mask : "); print_bits((mask & list->tetribit << (16 + i)) >> (j - 1), 32); // POUR DEBUG + map[j / 32] ^= (mask & list->tetribit << (16 + i)) >> (j - 1); ft_putstr("map[j / 32] : "); print_bits(map[j / 32], 32); // POUR DEBUG ft_putstr("map[(j+s) / 32]: "); print_bits(map[(j + size) / 32], 32); // POUR DEBUG - ft_putstr("mask 2 : "); print_bits((mask >> i & list->tetribit << 16) << (list->width * (list->height - 1) + ((33 - (j % 32)) % 32)), 32); // POUR DEBUG - */ -// map[(j + size) / 32] ^= (mask >> i & list->tetribit << 16) << (list->width * (list->height - 1) + ((33 - (j % 32)) % 32)); - /* + ft_putstr("mask 2 : "); print_bits((mask & list->tetribit << (16 + i)) << ((j % 32) + 1), 32); // POUR DEBUG + ft_putstr("(j % 32) + 1 : "); ft_putnbrendl((j % 32) + 1); // POUR DEBUG + ft_putstr("j : "); ft_putnbrendl(j); // POUR DEBUG + map[(j + size) / 32] ^= (mask & list->tetribit << (16 + i)) << ((j % 32) + 1); ft_putstr("map[(j+s) / 32]: "); print_bits(map[(j + size) / 32], 32); // POUR DEBUG - */ j -= size; i -= list->width; } -// print_map(map, size, size); // POUR DEBUG + print_map(map, size, size); // POUR DEBUG ft_putchar('\n'); } @@ -117,7 +96,7 @@ int fill_map(unsigned int *map, t_fillist *list, int size) while (find_place(map, list, size)) { add_remove(map, list, size, list->position); - // print_map(map, size, size); // POUR DEBUG + print_map(map, size, size); // POUR DEBUG ft_putendl("add_remove"); // POUR DEBUG if (fill_map(map, list->next, size)) return (1); @@ -166,51 +145,9 @@ void search_map(t_fillist *list) size++; map = init_map(size); - //////////////////////////// TEST //////////////////////////// - // ce tableau permet de monter jusqu'a une map de 16*16 - unsigned int print; - unsigned int tab[8]; - tab[0] = 2656554334; - tab[1] = 1394456818 ^ (1 << 11 | 1 << 22); - tab[2] = 1494256918; - tab[3] = 2656554334; - tab[4] = 1592453883; - tab[5] = 1444352908; - tab[6] = 2154339230; - tab[7] = 1576493154; - print_map(tab, 10, 10); - tmp = list; - while (tmp) - { - // imression pour tests - print = tmp->tetribit; - print <<= 16; - print_map(&print, tmp->width, tmp->height); // test, imprime le tetri - ft_putnbrendl(find_place(tab, tmp, 10)); - ft_putchar('\n'); - tmp = tmp->next; - } - - // 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)); -// print_map(tab, 10, 10); -// add_remove(tab, list, 10, list->position); -// print_map(tab, 10, 10); - - add_remove(tab, list->next, 10, find_place(tab, list->next, 10)); -// print_map(tab, 10, 10); -// add_remove(tab, list->next, 10, list->next->position); -// print_map(tab, 10, 10); - - add_remove(tab, list->next->next, 10, find_place(tab, list->next->next, 10)); -// print_map(tab, 10, 10); -// add_remove(tab, list->next->next, 10, list->next->next->position); -// print_map(tab, 10, 10); - //////////////////////////// TEST //////////////////////////// - // lance la recursive fill_map en augmentant la taille de la map tant qu'il n'y a pas de solution -// ft_putstr("test "); ft_putnbrendl(size); // POUR DEBUG -// while (!fill_map(map, list, size)) -// map = init_map(size++); + ft_putstr("test "); ft_putnbrendl(size); // POUR DEBUG + while (!fill_map(map, list, size)) + map = init_map(size++); }