fonction print_final_map fonctionne mais backtracking bug..

This commit is contained in:
Hugo LAMY
2019-05-03 16:06:11 +02:00
parent bd38cd52ed
commit 671585098f
4 changed files with 21 additions and 25 deletions

View File

@@ -6,7 +6,7 @@
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View File

@@ -6,7 +6,7 @@
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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;

32
print.c
View File

@@ -6,7 +6,7 @@
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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;

View File

@@ -6,7 +6,7 @@
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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, '#');
}