From 671585098f6154e5218b683be0be178a49701c79 Mon Sep 17 00:00:00 2001 From: Hugo LAMY Date: Fri, 3 May 2019 16:06:11 +0200 Subject: [PATCH] fonction print_final_map fonctionne mais backtracking bug.. --- fillit.h | 4 ++-- parse_input.c | 3 +-- print.c | 32 ++++++++++++++------------------ search_map.c | 7 ++++--- 4 files changed, 21 insertions(+), 25 deletions(-) diff --git a/fillit.h b/fillit.h index 501072c..9d2f7b0 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/03 14:22:25 by hulamy ### ########.fr */ +/* Updated: 2019/05/03 15:23:22 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -49,7 +49,7 @@ 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_map(unsigned int *tab, int width, int height, char letter); void print_final_map(t_fillist *list, int size); #endif diff --git a/parse_input.c b/parse_input.c index d2cd51a..4de2907 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/03 14:24:00 by hulamy ### ########.fr */ +/* Updated: 2019/05/03 15:24:28 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -132,7 +132,6 @@ void parse_input(char *input) i = 0; letter = 'A'; - --letter; while (input[i]) { j = 0; diff --git a/print.c b/print.c index b8e7397..f318fec 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/03 14:19:51 by hulamy ### ########.fr */ +/* Updated: 2019/05/03 16:05:19 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -36,7 +36,7 @@ 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, char letter) { int i; unsigned int mask; @@ -50,7 +50,7 @@ void print_map(unsigned int *tab, int width, int height) { if (i && !(i % width)) ft_putchar('\n'); - tab[i / 32] & (1 << (31 - i % 32)) ? ft_putchar('#') : ft_putchar('.'); + tab[i / 32] & (1 << (31 - i % 32)) ? ft_putchar(letter) : ft_putchar('.'); ft_putchar(' '); i++; } @@ -63,7 +63,7 @@ void print_map(unsigned int *tab, int width, int height) void print_final_map(t_fillist *list, int size) { -// unsigned int print; + unsigned int print; // DEBUG t_fillist *tmp; char *map; int i; @@ -71,9 +71,9 @@ void print_final_map(t_fillist *list, int size) map = (char *)malloc(sizeof(*map) * (size * size + 1)); map[size*size] = '\0'; -// i = -1; -// while (++i < size * size) -// map[i] = '.'; + i = -1; + while (++i < size * size) + map[i] = '.'; tmp = list; while (tmp) { @@ -81,19 +81,15 @@ void print_final_map(t_fillist *list, int size) 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 (i && i % tmp->width == 0) + j += size - tmp->width; if (1 << (15 - i) & tmp->tetribit) - map[tmp->position + i + j] = tmp->letter; - else - map[tmp->position + i + j] = '.'; + map[tmp->position + i + j - 1] = tmp->letter; } + ft_putstr("position: "); ft_putnbrendl(tmp->position); // DEBUG + print = tmp->tetribit << 16; // DEBUG + print_map(&print, tmp->width, tmp->height, tmp->letter); // DEBUG + ft_putchar('\n'); // DEBUG tmp = tmp->next; } i = -1; diff --git a/search_map.c b/search_map.c index 6317db8..0eac674 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/03 14:19:42 by hulamy ### ########.fr */ +/* Updated: 2019/05/03 16:05:23 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -138,7 +138,8 @@ 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)) map = init_map(size++); - print_map(map, size, size); - print_final_map(list, size); + print_final_map(list, size); // DEBUG + ft_putchar('\n'); // DEBUG + print_map(map, size, size, '#'); }