resolu les deux problemes de add_remove et find_place mais bcp bcp plus lent

This commit is contained in:
Hugo LAMY
2019-05-08 18:45:21 +02:00
4 changed files with 16 additions and 9 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

View File

@@ -6,7 +6,7 @@
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/01 13:34:46 by vmanzoni #+# #+# */
/* Updated: 2019/05/06 16:31:11 by hulamy ### ########.fr */
/* Updated: 2019/05/08 17:52:19 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */

View File

@@ -6,7 +6,7 @@
/* By: hulamy <hulamy@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/30 13:24:28 by hulamy #+# #+# */
/* Updated: 2019/05/06 23:28:36 by hulamy ### ########.fr */
/* Updated: 2019/05/08 17:52:14 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */

View File

@@ -6,7 +6,7 @@
/* By: hulamy <hulamy@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/27 20:47:22 by hulamy #+# #+# */
/* Updated: 2019/05/06 23:28:01 by hulamy ### ########.fr */
/* Updated: 2019/05/08 18:38:47 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
@@ -32,7 +32,7 @@ int find_place(unsigned int *tab, t_fillist *list, int size, int pos)
{
// pour ne pas deborder a droite de la map
if (i % size == size - list->width + 1)
i += list->width;
i += list->width - 1;
else
{
tmp = 0;
@@ -71,8 +71,9 @@ 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)
{
map[j / 32] ^= (mask & tetri << (16 + i)) >> (j - 1);
map[(j + size) / 32] ^= (mask & tetri << (16 + i)) << (32 - j);
map[(j - 1) / 32] ^= (mask & tetri << (16 + i)) >> (j - 1);
if (j % 32 != 1)
map[(j + size) / 32] ^= (mask & tetri << (16 + i)) << (32 - j + 1);
j -= size;
i -= list->width;
}
@@ -82,20 +83,26 @@ void add_remove(unsigned int *map, t_fillist *list, int size, int pos)
** function that recursively try to fill the map with the tetris
*/
int fill_map(unsigned int *map, t_fillist *list, int size, t_fillist *link)
int fill_map(unsigned int *map, t_fillist *list, int size, t_fillist *link) // DEBUG "link"
{
int pos;
pos = 0;
if (!list)
return (1);
// unsigned int tmp = list->tetribit << 16; print_map(&tmp, list->width, list->height, list->letter); // DEBUG
while ((pos = find_place(map, list, size, pos)))
{
add_remove(map, list, size, pos);
list->position = pos;
// print_final_map(link, size); // DEBUG
// ft_putnbrendl(pos);
// print_map(map, size, size, '#'); // DEBUG
// ft_putchar('\n');
if (fill_map(map, list->next, size, link))
return (1);
add_remove(map, list, size, pos);
// list->position = -1; // DEBUG
}
return (0);
}
@@ -157,6 +164,6 @@ void search_map(t_fillist *list)
// lance la recursive fill_map en augmentant la taille de la map tant qu'il n'y a pas de solution
while (!fill_map(map, list, size, list))
map = init_map(size++);
print_final_map(list, size); // DEBUG
print_map(map, size, size, '#');
print_final_map(list, size); // DEBUG
print_map(map, size, size, '#'); // DEBUG
}