New samples added + First Try Optimisation
This commit is contained in:
84
search_map.c
84
search_map.c
@@ -6,7 +6,7 @@
|
||||
/* By: hulamy <hulamy@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/27 20:47:22 by hulamy #+# #+# */
|
||||
/* Updated: 2019/05/08 19:38:23 by vmanzoni ### ########.fr */
|
||||
/* Updated: 2019/05/13 18:24:56 by vmanzoni ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -49,6 +49,7 @@ int find_place(unsigned int *tab, t_fillist *list, int size, int pos)
|
||||
return (i + 1);
|
||||
i++;
|
||||
}
|
||||
// print_final_map(list, size);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
@@ -80,12 +81,64 @@ void add_remove(unsigned int *map, t_fillist *list, int size, int pos)
|
||||
}
|
||||
|
||||
/*
|
||||
** function that recursively try to fill the map with the tetris
|
||||
** Test optimisation for not testing wrong maps when tetri are identical
|
||||
*/
|
||||
|
||||
int check_same_tetri(t_fillist *list)
|
||||
{
|
||||
t_fillist *curr_tetri;
|
||||
t_fillist *next_tetri;
|
||||
|
||||
curr_tetri = list;
|
||||
|
||||
while (curr_tetri != NULL)
|
||||
{
|
||||
next_tetri = curr_tetri->next;
|
||||
while (next_tetri != NULL)
|
||||
{
|
||||
if (curr_tetri->tetribit == next_tetri->tetribit)
|
||||
{
|
||||
if (next_tetri->same == NULL)
|
||||
next_tetri->same = curr_tetri;
|
||||
printf("%c->%c\n", next_tetri->letter, next_tetri->same->letter);
|
||||
}
|
||||
next_tetri = next_tetri->next;
|
||||
}
|
||||
curr_tetri = curr_tetri->next;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
** Test optimisation for not testing wrong maps when tetri are identical
|
||||
*/
|
||||
|
||||
int check_tetri_memory(t_fillist *list, int pos)
|
||||
{
|
||||
t_fillist *tetri;
|
||||
uint64_t mask;
|
||||
|
||||
tetri = list;
|
||||
if (tetri->same != NULL)
|
||||
{
|
||||
mask = 1 << (pos - 1);
|
||||
print_bits(mask, 64);
|
||||
if (tetri->same->memory & mask)
|
||||
{
|
||||
ft_putstr("test\n");
|
||||
return (pos + 1);
|
||||
}
|
||||
}
|
||||
return (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) // DEBUG "link"
|
||||
{
|
||||
int pos;
|
||||
int pos;
|
||||
|
||||
pos = 0;
|
||||
if (!list)
|
||||
@@ -93,16 +146,24 @@ int fill_map(unsigned int *map, t_fillist *list, int size, t_fillist *link) //
|
||||
// unsigned int tmp = list->tetribit << 16; print_map(&tmp, list->width, list->height, list->letter); // DEBUG
|
||||
while ((pos = find_place(map, list, size, pos)))
|
||||
{
|
||||
list->memory = (list->memory << 1) + 1;
|
||||
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');
|
||||
check_tetri_memory(list, pos);
|
||||
print_final_map(link, size); // DEBUG
|
||||
// ft_putnbrendl(pos);
|
||||
// print_map(map, size, size, '#'); // DEBUG
|
||||
ft_putchar('\n'); // DEBUG
|
||||
// if (list->same && list->position == 1)
|
||||
// {
|
||||
// list = list->next;
|
||||
// if (fill_map(map, list->next, size, link))
|
||||
// return (1);
|
||||
// }
|
||||
if (fill_map(map, list->next, size, link))
|
||||
return (1);
|
||||
add_remove(map, list, size, pos);
|
||||
// list->position = -1; // DEBUG
|
||||
list->position = -1; // DEBUG
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
@@ -155,12 +216,11 @@ void search_map(t_fillist *list)
|
||||
// imression pour tests
|
||||
print = tmp->tetribit;
|
||||
print <<= 16;
|
||||
// print_map(&print, tmp->width, tmp->height, tmp->letter); // test, imprime le tetri
|
||||
// ft_putchar('\n');
|
||||
print_map(&print, tmp->width, tmp->height, tmp->letter); // test, imprime le tetri
|
||||
ft_putchar('\n');
|
||||
tmp = tmp->next;
|
||||
}
|
||||
|
||||
|
||||
check_same_tetri(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++);
|
||||
|
||||
Reference in New Issue
Block a user