2 Commits

Author SHA1 Message Date
pia Lepetit
aa8a80b831 sauvegarde avant depart 2019-06-04 18:08:48 +02:00
pia Lepetit
0e52943b34 deux opti ilots et identiques 2019-06-04 16:56:24 +02:00
3 changed files with 61 additions and 9 deletions

View File

@@ -16,7 +16,7 @@
** function that print the given tetris if flag p is present ** function that print the given tetris if flag p is present
*/ */
t_fillist *print_tetri(t_fillist *list) t_fillist *print_tetri(t_fillist *list, int num)
{ {
unsigned int print; unsigned int print;
t_fillist *tmp; t_fillist *tmp;
@@ -39,6 +39,7 @@ t_fillist *print_tetri(t_fillist *list)
if (list->dope[1] && tmp->memory) if (list->dope[1] && tmp->memory)
ft_putendl("have a copy"); ft_putendl("have a copy");
ft_putchar('\n'); ft_putchar('\n');
tmp->total = num;
tmp = tmp->next; tmp = tmp->next;
} }
} }

View File

@@ -103,6 +103,50 @@ void add_remove(unsigned int *map, t_fillist *list, int size)
} }
} }
/*
** Function that try to place every tetri in the left places
** to know if it worth it to continue to check in this order
*/
int check_others(unsigned int *map, t_fillist *list, int size, int num)
{
t_fillist *tmp;
int dots;
int total;
int i;
int j;
dots = 0;
i = -1;
num *= 4;
total = size * size;
while (++i < total && dots <= total - num)
{
tmp = list->next;
j = 1;
while (1 << (i % 32) & map[i % 32])
i++;
while (j && tmp)
{
if (tmp->width > (size - i % size) || (total - i) <= (tmp->height * size))
tmp = tmp->next;
else if (!fit_in_place(map, list, size, i))
tmp = tmp->next;
else
j = 0;
}
if (j)
dots++;
}
return (dots > total - num);
}
/*
** Function that supress the memory of already placed tetri
** when a next one is placed before them
** because then they might fit where they already tried
*/
void clean_memory(t_fillist *list, int pos, int mem) void clean_memory(t_fillist *list, int pos, int mem)
{ {
t_fillist *tmp; t_fillist *tmp;
@@ -139,8 +183,8 @@ int fill_map(unsigned int *map, t_fillist *list, int size)
list->position = 0; list->position = 0;
while (find_place(map, list, size)) while (find_place(map, list, size))
{ {
// if (list->position < pos) if (list->position < pos)
// clean_memory(list, pos, pos); clean_memory(list, pos, pos);
add_remove(map, list, size); add_remove(map, list, size);
list->test = 1; list->test = 1;
if (list->dope[0]) if (list->dope[0])
@@ -150,8 +194,9 @@ int fill_map(unsigned int *map, t_fillist *list, int size)
} }
if (list->dope[1]) if (list->dope[1])
if (check_tetri_memory(list, list->position)) if (check_tetri_memory(list, list->position))
if (fill_map(map, list->next, size)) // if (check_others(map, list, size, list->total))
return (1); if (fill_map(map, list->next, size))
return (1);
if (!list->dope[1]) if (!list->dope[1])
if (fill_map(map, list->next, size)) if (fill_map(map, list->next, size))
return (1); return (1);
@@ -175,9 +220,14 @@ int search_map(t_fillist *list)
int i; int i;
size = 2; size = 2;
tmp = print_tetri(list);
// init_num_and_size(1, &size, tmp); num = 1;
size = 10; tmp = list;
while ((tmp = tmp->next))
num++;
tmp = print_tetri(list, num);
init_num_and_size(1, &size, tmp);
i = 0; i = 0;
while (!i) while (!i)
{ {

View File

@@ -63,6 +63,7 @@ typedef struct s_fillist
int num; int num;
int total_num; int total_num;
int test; int test;
int total;
char letter; char letter;
int *dope; int *dope;
unsigned int *memory; unsigned int *memory;
@@ -82,7 +83,7 @@ int check_same_tetri(t_fillist *list, int num);
/* /*
** bonus_print.c ** bonus_print.c
*/ */
t_fillist *print_tetri(t_fillist *list); t_fillist *print_tetri(t_fillist *list, int num);
int print_binary_map(unsigned int *map, int size, int *dope); int print_binary_map(unsigned int *map, int size, int *dope);
int print_flags_usage(void); int print_flags_usage(void);