diff --git a/Makefile b/Makefile index e6b8ac7..6a418a9 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: vmanzoni +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2019/03/01 13:24:35 by vmanzoni #+# #+# # -# Updated: 2019/04/30 14:20:52 by hulamy ### ########.fr # +# Updated: 2019/05/03 13:50:34 by hulamy ### ########.fr # # # # **************************************************************************** # diff --git a/fillit.h b/fillit.h index f2fc732..501072c 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/02 00:39:33 by hulamy ### ########.fr */ +/* Updated: 2019/05/03 14:22:25 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -31,6 +31,7 @@ typedef struct s_fillist int width; int height; int position; + char letter; struct s_fillist *next; } t_fillist; @@ -44,10 +45,11 @@ void parse_input(char *input); int check_file_errors(char *file); int check_tetri_errors(char *tetri); int check_tetri_errors_proxy(char *tetri); -int add_to_list(char *square, t_fillist **list); +int add_to_list(char *square, t_fillist **list, char letter); void fill_list(char line[], t_fillist *list); void print_bits(unsigned int bits, int size); //TO DELETE BEFORE EVAL void search_map(t_fillist *list); void print_map(unsigned int *tab, int width, int height); +void print_final_map(t_fillist *list, int size); #endif diff --git a/parse_input.c b/parse_input.c index 41df17b..d2cd51a 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/02 00:40:23 by hulamy ### ########.fr */ +/* Updated: 2019/05/03 14:24:00 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -96,7 +96,7 @@ void fill_list(char line[], t_fillist *list) ** linked each time needed */ -int add_to_list(char *line, t_fillist **list) +int add_to_list(char *line, t_fillist **list, char letter) { t_fillist *tmp; t_fillist *test; @@ -114,6 +114,7 @@ int add_to_list(char *line, t_fillist **list) test->next = tmp; } fill_list(line, tmp); + tmp->letter = letter; return (1); } @@ -127,8 +128,11 @@ void parse_input(char *input) char tetri[20]; int i; int j; + int letter; i = 0; + letter = 'A'; + --letter; while (input[i]) { j = 0; @@ -137,7 +141,7 @@ void parse_input(char *input) tetri[19] = '\0'; if (check_tetri_errors(tetri)) print_error("Error: Tetrimino not valid."); - add_to_list(tetri, &list); + add_to_list(tetri, &list, letter++); while (input[i] && input[i] != '.' && input[i] != '#') i++; } diff --git a/print.c b/print.c index 349478e..b8e7397 100644 --- a/print.c +++ b/print.c @@ -6,7 +6,7 @@ /* By: hulamy +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/30 13:24:28 by hulamy #+# #+# */ -/* Updated: 2019/05/02 00:39:56 by hulamy ### ########.fr */ +/* Updated: 2019/05/03 14:19:51 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,18 +17,18 @@ ** Prints a ligne of size bits */ -void print_bits(unsigned int bits, int size) +void print_bits(unsigned int bits, int size) { - unsigned int mask; + unsigned int mask; - mask = 1 << (size - 1); - while (mask) - { - (bits & mask) ? write(1, "#", 1) : write(1, ".", 1); - write(1, " ", 1); - mask >>= 1; - } - write(1, "\n", 1); + mask = 1 << (size - 1); + while (mask) + { + (bits & mask) ? write(1, "#", 1) : write(1, ".", 1); + write(1, " ", 1); + mask >>= 1; + } + write(1, "\n", 1); } /* @@ -36,24 +36,74 @@ void print_bits(unsigned int bits, int size) ** Print a map of height and width */ -void print_map(unsigned int *tab, int width, int height) +void print_map(unsigned int *tab, int width, int height) { - int i; - unsigned int mask; + int i; + unsigned int mask; - i = 0; - mask = 0; - while (i++ < width) - mask = (mask >> 1) | ((mask | 1) << 31); - i = 0; - while (i < width * height) - { - if (i && !(i % width)) - ft_putchar('\n'); - tab[i / 32] & (1 << (31 - i % 32)) ? ft_putchar('#') : ft_putchar('.'); - ft_putchar(' '); - i++; - } - write(1, "\n", 1); + i = 0; + mask = 0; + while (i++ < width) + mask = (mask >> 1) | ((mask | 1) << 31); + i = 0; + while (i < width * height) + { + if (i && !(i % width)) + ft_putchar('\n'); + tab[i / 32] & (1 << (31 - i % 32)) ? ft_putchar('#') : ft_putchar('.'); + ft_putchar(' '); + i++; + } + write(1, "\n", 1); +} + +/* +** Print the final map with the letters +*/ + +void print_final_map(t_fillist *list, int size) +{ +// unsigned int print; + t_fillist *tmp; + char *map; + int i; + int j; + + map = (char *)malloc(sizeof(*map) * (size * size + 1)); + map[size*size] = '\0'; +// i = -1; +// while (++i < size * size) +// map[i] = '.'; + tmp = list; + while (tmp) + { + j = 0; + i = -1; + while (++i < tmp->width * tmp->height) + { +// ft_putchar('\n'); +// print = tmp->tetribit << 16; +// print_map(&print, tmp->width, tmp->height); +// print_bits(tmp->tetribit, 16); +// print_bits(1 << (15 - i), 16); +// (1 >> i & tmp->tetribit) ? ft_putchar('1') : ft_putchar('.'); + if (i && i + 1 % tmp->width == 0) + j += size; + if (1 << (15 - i) & tmp->tetribit) + map[tmp->position + i + j] = tmp->letter; + else + map[tmp->position + i + j] = '.'; + } + tmp = tmp->next; + } + i = -1; + while (++i < size * size) + { + if (i && i % size == 0) + ft_putchar('\n'); + ft_putchar(map[i]); + ft_putchar(' '); + } + ft_putchar('\n'); } diff --git a/samples/test_ultra_lent b/samples/test_ultra_lent new file mode 100644 index 0000000..6f6a1e5 --- /dev/null +++ b/samples/test_ultra_lent @@ -0,0 +1,99 @@ +...# +...# +..## +.... + +#... +###. +.... +.... + +.#.. +.#.. +##.. +.... + +...# +...# +..## +.... + +...# +...# +..## +.... + +#... +###. +.... +.... + +.#.. +.#.. +##.. +.... + +...# +...# +..## +.... + +...# +...# +..## +.... + +#... +###. +.... +.... + +.#.. +.#.. +##.. +.... + +...# +...# +..## +.... + +...# +...# +..## +.... + +#... +###. +.... +.... + +.#.. +.#.. +##.. +.... + +...# +...# +..## +.... + +...# +...# +..## +.... + +#... +###. +.... +.... + +.#.. +.#.. +##.. +.... + +...# +...# +..## +.... diff --git a/search_map.c b/search_map.c index fbb5b65..6317db8 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/02 16:42:47 by hulamy ### ########.fr */ +/* Updated: 2019/05/03 14:19:42 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -139,5 +139,6 @@ void search_map(t_fillist *list) while (!fill_map(map, list, size)) map = init_map(size++); print_map(map, size, size); + print_final_map(list, size); } diff --git a/testmap b/testmap new file mode 100755 index 0000000..249f914 Binary files /dev/null and b/testmap differ