diff --git a/fillit.h b/fillit.h index 9900eb5..9820b60 100644 --- a/fillit.h +++ b/fillit.h @@ -6,7 +6,7 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/03/01 13:34:46 by vmanzoni #+# #+# */ -/* Updated: 2019/05/08 17:52:19 by hulamy ### ########.fr */ +/* Updated: 2019/05/13 17:56:19 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,6 +16,7 @@ #include #include // for system call write #include // for system call open +#include #include // for printf (DELETE BEFORE EVAL) #include "libft/includes/libft.h" @@ -34,6 +35,14 @@ #define CYN "\x1B[36m" #define RESET "\x1B[0m" +//#define RED "\e[41m" +//#define GRN "\e[42m" +//#define YEL "\e[43m" +//#define BLU "\e[44m" +//#define MAG "\e[45m" +//#define CYN "\e[46m" +//#define RESET "\e[49m" + /* ** STRUCTURE */ @@ -45,6 +54,8 @@ typedef struct s_fillist int height; int position; char letter; + uint64_t memory; + struct s_fillist *same; struct s_fillist *next; } t_fillist; diff --git a/parse_input.c b/parse_input.c index 6354e0f..ad3dd5a 100644 --- a/parse_input.c +++ b/parse_input.c @@ -6,7 +6,7 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/15 14:48:14 by vmanzoni #+# #+# */ -/* Updated: 2019/05/09 11:45:08 by vmanzoni ### ########.fr */ +/* Updated: 2019/05/13 17:13:08 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ @@ -67,6 +67,7 @@ void fill_list(char line[], t_fillist *list) // transforme la ligne de . et # en un short de 0 et 1 list->tetribit = tab_to_bin(line); + list->memory = 0; // cree un mask avec des 1 sur la colonne de droite (#...#...#...#...) mask = (1 << 15) | (1 << 11) | (1 << 7) | (1 << 3); // utilise le mask pour trouver la largeur que prend le tetriminos diff --git a/samples/5square b/samples/5square new file mode 100644 index 0000000..0c77b74 --- /dev/null +++ b/samples/5square @@ -0,0 +1,24 @@ +##.. +##.. +.... +.... + +##.. +##.. +.... +.... + +##.. +##.. +.... +.... + +##.. +##.. +.... +.... + +##.. +##.. +.... +.... diff --git a/samples/map_hard b/samples/map_hard index 6f6a1e5..887429b 100644 --- a/samples/map_hard +++ b/samples/map_hard @@ -38,11 +38,6 @@ ..## .... -...# -...# -..## -.... - #... ###. .... @@ -52,48 +47,3 @@ .#.. ##.. .... - -...# -...# -..## -.... - -...# -...# -..## -.... - -#... -###. -.... -.... - -.#.. -.#.. -##.. -.... - -...# -...# -..## -.... - -...# -...# -..## -.... - -#... -###. -.... -.... - -.#.. -.#.. -##.. -.... - -...# -...# -..## -.... diff --git a/samples/opti_test b/samples/opti_test new file mode 100644 index 0000000..1f3c081 --- /dev/null +++ b/samples/opti_test @@ -0,0 +1,14 @@ +...# +.### +.... +.... + +.... +#... +##.. +.#.. + +##.. +.##. +.... +.... diff --git a/samples/test_opti b/samples/test_opti new file mode 100644 index 0000000..1808a8c --- /dev/null +++ b/samples/test_opti @@ -0,0 +1,19 @@ +..#. +..#. +..## +.... + +.... +.##. +.##. +.... + +..#. +..#. +..## +.... + +..#. +..#. +..## +.... diff --git a/search_map.c b/search_map.c index 89fed03..0348fcf 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/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++);