From c50f971f50b0054deb43202a74aa29abbe440e80 Mon Sep 17 00:00:00 2001 From: Hugo LAMY Date: Tue, 30 Apr 2019 20:59:01 +0200 Subject: [PATCH 1/4] continue de tenter d'ecrire le add_remove mask --- samples/3tetribis | 14 ++++++++++++++ search_map.c | 34 +++++++++++++++++++++++++--------- 2 files changed, 39 insertions(+), 9 deletions(-) create mode 100644 samples/3tetribis 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 From c40da94786f13033cdbbece8571e34bfd0ebd834 Mon Sep 17 00:00:00 2001 From: Hugo LAMY Date: Wed, 1 May 2019 12:34:58 +0200 Subject: [PATCH 2/4] add_remove fonctionne pour adding --- search_map.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/search_map.c b/search_map.c index 7523585..fb47c21 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 20:58:29 by hulamy ### ########.fr */ +/* Updated: 2019/05/01 12:34:29 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -72,19 +72,21 @@ void add_remove(unsigned int *map, t_fillist *list, int size, int pos) // ft_putnbrendl(pos); while (j >= pos) { + /* tests pour trouver l'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 >> i, 32); -// print_bits((mask >> i & 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 + print_bits((mask >> i & list->tetribit << 16) << (list->width * (list->height - 1) + ((33 - (j % 32)) % 32)), 32); + */ + map[j / 32] |= (mask >> i & list->tetribit << 16) >> (j - i - 1); + map[(j + size) / 32] |= (mask >> i & list->tetribit << 16) << (list->width * (list->height - 1) + ((33 - (j % 32)) % 32)); // cette deuxieme ligne est la au cas ou on serait a cheval sur deux int du tab j -= size; i -= list->width; } @@ -180,7 +182,9 @@ 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)); + 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->next, 10, find_place(tab, list->next->next, 10)); print_map(tab, 10, 10); From 646d611381f096dcabe858c486c474a785cd2cd2 Mon Sep 17 00:00:00 2001 From: Hugo LAMY Date: Wed, 1 May 2019 13:49:19 +0200 Subject: [PATCH 3/4] add_remove fonctionne --- search_map.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/search_map.c b/search_map.c index fb47c21..9df8f5d 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 12:34:29 by hulamy ### ########.fr */ +/* Updated: 2019/05/01 13:48:35 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -84,9 +84,10 @@ void add_remove(unsigned int *map, t_fillist *list, int size, int pos) print_bits(map[(j + list->width) / 32], 32); print_bits((mask >> i & list->tetribit << 16), 32); print_bits((mask >> i & list->tetribit << 16) << (list->width * (list->height - 1) + ((33 - (j % 32)) % 32)), 32); + print_bits(map[(j + list->width) / 32] | (mask >> i & list->tetribit << 16) << (list->width * (list->height - 1) + ((33 - (j % 32)) % 32)), 32); */ - map[j / 32] |= (mask >> i & list->tetribit << 16) >> (j - i - 1); - map[(j + size) / 32] |= (mask >> i & list->tetribit << 16) << (list->width * (list->height - 1) + ((33 - (j % 32)) % 32)); // cette deuxieme ligne est la au cas ou on serait a cheval sur deux int du tab + map[j / 32] ^= (mask >> i & list->tetribit << 16) >> (j - i - 1); + map[(j + size) / 32] ^= (mask >> i & list->tetribit << 16) << (list->width * (list->height - 1) + ((33 - (j % 32)) % 32)); // cette deuxieme ligne est la au cas ou on serait a cheval sur deux int du tab j -= size; i -= list->width; } @@ -183,10 +184,18 @@ void search_map(t_fillist *list) // 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); // lance la recursive fill_map en augmentant la taille de la map tant qu'il n'y a pas de solution // ft_putstr("test "); From c118eac450309930002b9ae692932e3a71d80c0e Mon Sep 17 00:00:00 2001 From: Hugo LAMY Date: Wed, 1 May 2019 14:22:18 +0200 Subject: [PATCH 4/4] debug de la recursive et add_remove qui foire certains bits --- samples/3tetribis | 10 +++--- search_map.c | 86 +++++++---------------------------------------- 2 files changed, 17 insertions(+), 79 deletions(-) diff --git a/samples/3tetribis b/samples/3tetribis index c324e08..f08eccd 100644 --- a/samples/3tetribis +++ b/samples/3tetribis @@ -1,13 +1,13 @@ -...# -...# -...# -...# - .... ##.. .##. .... +...# +...# +...# +...# + .... ###. ..#. diff --git a/search_map.c b/search_map.c index 9df8f5d..cfb4c0d 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 13:48:35 by hulamy ### ########.fr */ +/* Updated: 2019/05/01 14:21:49 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -37,12 +37,9 @@ int find_place(unsigned int *tab, t_fillist *list, int size) { tmp >>= list->width; tmp |= (mask & (tab[j / 32] << j)); - 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 + tmp |= (mask & (tab[(j + list->width) / 32] >> (32 - j))); j -= size; } -// print_map(&tmp, list->width, list->height); // test pour imprimer la photo en map -// write(1, "\n", 1); -// print_bits(tmp >> 16, 32); // test pour imprimer la photo en bits if (!((tmp >> 16) & list->tetribit)) return ((list->position = i + 1)); if (i % size == size - list->width) @@ -67,30 +64,17 @@ void add_remove(unsigned int *map, t_fillist *list, int size, int pos) tmp = 0; 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); + // change les bits du tetri sur la map a la position donnee while (j >= pos) { - /* tests pour trouver l'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 >> 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) << (list->width * (list->height - 1) + ((33 - (j % 32)) % 32)), 32); - print_bits(map[(j + list->width) / 32] | (mask >> i & list->tetribit << 16) << (list->width * (list->height - 1) + ((33 - (j % 32)) % 32)), 32); - */ + print_map(map, size, size); // POUR DEBUG map[j / 32] ^= (mask >> i & list->tetribit << 16) >> (j - i - 1); - map[(j + size) / 32] ^= (mask >> i & list->tetribit << 16) << (list->width * (list->height - 1) + ((33 - (j % 32)) % 32)); // cette deuxieme ligne est la au cas ou on serait a cheval sur deux int du tab + map[(j + size) / 32] ^= (mask >> i & list->tetribit << 16) + << (list->width * (list->height - 1) + ((33 - (j % 32)) % 32)); j -= size; i -= list->width; } + print_map(map, size, size); // POUR DEBUG ft_putchar('\n'); } @@ -105,7 +89,8 @@ 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); + // print_map(map, size, size); // POUR DEBUG + ft_putendl("add_remove"); // POUR DEBUG if (fill_map(map, list->next, size)) return (1); add_remove(map, list, size, list->position); @@ -138,33 +123,6 @@ void search_map(t_fillist *list) { t_fillist *tmp; - //////////////////////////// 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; - } - //////////////////////////// TEST //////////////////////////// - - ////////////////////////// en cours ////////////////////////// unsigned int *map; int size; int i; @@ -179,29 +137,9 @@ void search_map(t_fillist *list) while (size * size < i * 4) size++; map = init_map(size); - - // 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)); - 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); - // 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); -// while (!fill_map(map, list, size)) -// map = init_map(size++); - ////////////////////////// en cours ////////////////////////// + ft_putstr("test "); ft_putnbrendl(size); // POUR DEBUG + while (!fill_map(map, list, size)) + map = init_map(size++); }