continue de tenter d'ecrire le add_remove mask
This commit is contained in:
14
samples/3tetribis
Normal file
14
samples/3tetribis
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
...#
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
|
||||||
|
....
|
||||||
|
##..
|
||||||
|
.##.
|
||||||
|
....
|
||||||
|
|
||||||
|
....
|
||||||
|
###.
|
||||||
|
..#.
|
||||||
|
....
|
||||||
34
search_map.c
34
search_map.c
@@ -6,7 +6,7 @@
|
|||||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/04/27 20:47:22 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)
|
while (i < (size - list->height + 1) * size)
|
||||||
{
|
{
|
||||||
tmp = 0;
|
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
|
// 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)
|
while (j >= i)
|
||||||
{
|
{
|
||||||
tmp >>= list->width;
|
tmp >>= list->width;
|
||||||
tmp |= (mask & (tab[j / 32] << j));
|
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;
|
j -= size;
|
||||||
}
|
}
|
||||||
// print_map(&tmp, list->width, list->height); // test pour imprimer la photo en map
|
// 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 mask;
|
||||||
unsigned int tmp;
|
unsigned int tmp;
|
||||||
int j;
|
int j;
|
||||||
|
int i;
|
||||||
|
|
||||||
mask = ~0u << (32 - list->width);
|
mask = ~0u << (32 - list->width);
|
||||||
tmp = 0;
|
tmp = 0;
|
||||||
j = list->height * size + pos;
|
i = (list->height - 1) * list->width;
|
||||||
|
j = (list->height - 1) * size + pos;
|
||||||
// (void)map;
|
// (void)map;
|
||||||
// construit un tmp qui est une photo de la map de la taille du tetri a un emplacement donne
|
// construit un tmp qui est une photo de la map de la taille du tetri a un emplacement donne
|
||||||
// ft_putnbrendl(pos);
|
// ft_putnbrendl(pos);
|
||||||
while (j >= pos)
|
while (j >= pos)
|
||||||
{
|
{
|
||||||
map[j / 32] |= ((mask >> (32 - j)) ^ map[j / 32]);
|
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);
|
||||||
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
|
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;
|
j -= size;
|
||||||
|
i -= list->width;
|
||||||
}
|
}
|
||||||
|
ft_putchar('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -125,7 +140,7 @@ void search_map(t_fillist *list)
|
|||||||
unsigned int print;
|
unsigned int print;
|
||||||
unsigned int tab[8];
|
unsigned int tab[8];
|
||||||
tab[0] = 2656554334;
|
tab[0] = 2656554334;
|
||||||
tab[1] = 1394456818;
|
tab[1] = 1394456818 ^ (1 << 11 | 1 << 22);
|
||||||
tab[2] = 1494256918;
|
tab[2] = 1494256918;
|
||||||
tab[3] = 2656554334;
|
tab[3] = 2656554334;
|
||||||
tab[4] = 1592453883;
|
tab[4] = 1592453883;
|
||||||
@@ -139,8 +154,7 @@ void search_map(t_fillist *list)
|
|||||||
// imression pour tests
|
// imression pour tests
|
||||||
print = tmp->tetribit;
|
print = tmp->tetribit;
|
||||||
print <<= 16;
|
print <<= 16;
|
||||||
// print_map(&print, tmp->width, tmp->height); // test, imprime le tetri
|
print_map(&print, tmp->width, tmp->height); // test, imprime le tetri
|
||||||
// ft_putchar('\n');
|
|
||||||
ft_putnbrendl(find_place(tab, tmp, 10));
|
ft_putnbrendl(find_place(tab, tmp, 10));
|
||||||
ft_putchar('\n');
|
ft_putchar('\n');
|
||||||
tmp = tmp->next;
|
tmp = tmp->next;
|
||||||
@@ -166,6 +180,8 @@ void search_map(t_fillist *list)
|
|||||||
// en cours de test :
|
// 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
|
// 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, 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);
|
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
|
// lance la recursive fill_map en augmentant la taille de la map tant qu'il n'y a pas de solution
|
||||||
|
|||||||
Reference in New Issue
Block a user