diff --git a/search_map.c b/search_map.c index afe5908..0effc76 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 13:25:42 by hulamy ### ########.fr */ +/* Updated: 2019/04/30 14:07:47 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -56,38 +56,45 @@ int find_place(unsigned int *tab, t_fillist *list, int size) ** function that add or remove a tetri on the map */ -//void add_remove(unsigned int *map, t_fillist *list) -//{ -// unsigned int mask; -// unsigned int tmp; -// int i; -// -// mask = ~0u << (32 - list->width); -// tmp = 0; -// /* -// * trouver comment faire ;) -// */ -//} +void add_remove(unsigned int *map, t_fillist *list, int size, int pos) +{ + unsigned int mask; + unsigned int tmp; + int j; + + mask = ~0u << (32 - list->width); + tmp = 0; + j = list->height * 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 + j -= size; + } +} /* ** function that recursively try to fill the map with the tetris */ -//int fill_map(unsigned int *map, t_fillist *list, int size) -//{ -// if (!list) -// return (1); -// while (find_place(map, list, size)) -// { -// add_remove(map, list, size); -// print_map(map, size, size); -// if (fill_map(map, size, list->next) -// return (1); -// add_remove(map, list, size); -// list->position++; -// } -// return (0); -//} +int fill_map(unsigned int *map, t_fillist *list, int size) +{ + if (!list) + return (1); + while (find_place(map, list, size)) + { + add_remove(map, list, size, list->position); + print_map(map, size, size); + if (fill_map(map, list->next, size)) + return (1); + add_remove(map, list, size, list->position); + list->position++; + } + return (0); +} /* ** function that init the map to the right size fill with int equal to zeros @@ -155,6 +162,12 @@ 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); + // 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);