1 Commits
master ... opti

Author SHA1 Message Date
Hugo LAMY
8fa68fa5a1 tentative de mettre toutes les divisions et modulo dans la structure 2019-05-17 15:57:20 +02:00
3 changed files with 79 additions and 82 deletions

View File

@@ -6,7 +6,7 @@
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */ /* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/01 13:34:46 by vmanzoni #+# #+# */ /* Created: 2019/03/01 13:34:46 by vmanzoni #+# #+# */
/* Updated: 2019/05/16 15:31:15 by hulamy ### ########.fr */ /* Updated: 2019/05/17 15:33:01 by hulamy ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -44,6 +44,10 @@ typedef struct s_fillist
int width; int width;
int height; int height;
int position; int position;
int posx;
int int_number;
int pos_in_int;
int limit;
int test; int test;
char letter; char letter;
struct s_fillist *next; struct s_fillist *next;

View File

@@ -6,7 +6,7 @@
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */ /* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/15 14:48:14 by vmanzoni #+# #+# */ /* Created: 2019/04/15 14:48:14 by vmanzoni #+# #+# */
/* Updated: 2019/05/16 15:30:57 by hulamy ### ########.fr */ /* Updated: 2019/05/17 15:32:59 by hulamy ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -89,8 +89,6 @@ void fill_list(char line[], t_fillist *list)
list->height = i; list->height = i;
// fabrique la ligne pour le tetriminos de la bonne largeur // fabrique la ligne pour le tetriminos de la bonne largeur
list->tetribit = reduce_tetri(list->tetribit, list->width); list->tetribit = reduce_tetri(list->tetribit, list->width);
list->position = 0;
list->test = 0; // DEBUG pour que print_final_map puisse imprimer correctement au fur et a mesure
} }
/* /*

View File

@@ -6,7 +6,7 @@
/* By: hulamy <hulamy@student.42.fr> +#+ +:+ +#+ */ /* By: hulamy <hulamy@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/27 20:47:22 by hulamy #+# #+# */ /* Created: 2019/04/27 20:47:22 by hulamy #+# #+# */
/* Updated: 2019/05/16 16:50:29 by hulamy ### ########.fr */ /* Updated: 2019/05/17 15:55:04 by hulamy ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -16,12 +16,16 @@
** function that look if a tretri fit in a place ** function that look if a tretri fit in a place
*/ */
unsigned int fit_in_place(unsigned int *map, t_fillist *list, int size, int n, int r) unsigned int fit_in_place(unsigned int *map, t_fillist *list, int size)
{ {
unsigned int tmp; unsigned int tmp;
unsigned int mask; unsigned int mask;
int i; int i;
int n;
int r;
n = list->int_number;
r = list->pos_in_int;
unsigned int tetri; unsigned int tetri;
i = list->height; i = list->height;
tetri = list->tetribit << 16 >> list->width; tetri = list->tetribit << 16 >> list->width;
@@ -40,42 +44,6 @@ unsigned int fit_in_place(unsigned int *map, t_fillist *list, int size, int n, i
return (!(tmp & tetri)); return (!(tmp & tetri));
} }
/*
** function that look for the first place in the map for a tetri
*/
int find_place(unsigned int *tab, t_fillist *list, int size)
{
int place; // designe la position sur la ligne du tableau de size*size
int r; // designe la position de pos dans l'int du tableau
int n; // designe dans quel int tu tableau pos se trouve
int limit; // limit en hauteur du tableau a chercher pour la position du tetri
int pos;
pos = list->position;
place = pos % size;
r = pos % 32;
n = pos / 32;
limit = (size - list->height + 1) * size;
while (pos < limit)
{
if (r >= 32 && ++n)
r -= 32;
if (place > size - list->width && (place = -1))
{
pos += list->width - 2;
r += list->width - 2;
}
else if (fit_in_place(tab, list, size, n, r))
return ((list->position = pos + 1));
// return (pos + 1);
pos++;
place++;
r++;
}
return (0);
}
/* /*
** function that add or remove a tetri on the map ** function that add or remove a tetri on the map
*/ */
@@ -101,51 +69,59 @@ void add_remove(unsigned int *map, t_fillist *list, int size)
} }
} }
/*
** function that look for the first place in the map for a tetri
*/
int find_place(unsigned int *tab, t_fillist *list, int size)
{
t_fillist tmp;
tmp = *list;
while (list->position < list->limit)
{
if (list->pos_in_int >= 32 && ++list->int_number)
list->pos_in_int -= 32;
if (list->posx > size - list->width && (list->posx = -1))
{
list->position += list->width - 2;
list->pos_in_int += list->width - 2;
}
else if (fit_in_place(tab, list, size))
{
list->pos_in_int++;
list->position++;
list->posx++;
return (1);
}
list->position++;
list->posx++;
list->pos_in_int++;
}
list = &tmp;
return (0);
}
/* /*
** function that recursively try to fill the map with the tetris ** 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 sert uniquement pour afficher le debug int fill_map(unsigned int *map, t_fillist *list, int size, t_fillist *link) // DEBUG link sert uniquement pour afficher le debug
{ {
// /*
// int posx;
// int posy;
// posx = list->posx;
// posy = list->posy;
if (!list) if (!list)
return (1); return (1);
list->position = 0; // comme les positions sont marquees en dure dans la liste et non plus dans une petite variable list->position = 0;
// au sein de la fonction, il faut remettre a zero la position a chaque nouveau tour de map list->int_number = 0;
list->pos_in_int = 0;
list->posx = 0;
while (find_place(map, list, size)) while (find_place(map, list, size))
{ {
// pos = list->position;
// list->test = 1; // DEBUG pour afficher la map a chaque etape
add_remove(map, list, size); add_remove(map, list, size);
// print_final_map(link, size); ft_putnbrendl(pos); print_map(map, size, size, '#'); ft_putchar('\n'); // DEBUG
if (fill_map(map, list->next, size, link)) if (fill_map(map, list->next, size, link))
return (1); return (1);
add_remove(map, list, size); add_remove(map, list, size);
// list->test = 0; // DEBUG pour afficher la map a chaque etape
} }
// */
/*
int pos;
pos = 0;
if (!list)
return (1);
while ((pos = find_place(map, list, size, pos)))
{
add_remove(map, list, size, pos);
list->position = pos;
if (fill_map(map, list->next, size, link))
return (1);
add_remove(map, list, size, pos);
}
*/
return (0); return (0);
} }
@@ -165,6 +141,26 @@ unsigned int *init_map(int i)
return (new); return (new);
} }
/*
** function that init the list with the new values for each map size
*/
void init_list(t_fillist *list, int size)
{
t_fillist *tmp;
tmp = list;
while (tmp)
{
list->posx = 0;
list->int_number = 0;
list->pos_in_int = 0;
list->test = 0; // DEBUG pour que print_final_map puisse imprimer correctement au fur et a mesure
tmp->limit = (size - tmp->height + 1) * size;
tmp = tmp->next;
}
}
/* /*
** function that send to "fill_map" a map of a certain size and increment its size untill it's solved ** function that send to "fill_map" a map of a certain size and increment its size untill it's solved
*/ */
@@ -172,7 +168,6 @@ unsigned int *init_map(int i)
void search_map(t_fillist *list) void search_map(t_fillist *list)
{ {
t_fillist *tmp; t_fillist *tmp;
unsigned int *map; unsigned int *map;
int size; int size;
int num; int num;
@@ -180,16 +175,12 @@ void search_map(t_fillist *list)
size = 2; size = 2;
num = 1; num = 1;
tmp = list; tmp = list;
// trouve le nombre de tetri en parcourant la liste chainee while ((tmp = tmp->next)) // trouve le nombre de tetri en parcourant la liste chainee
while ((tmp = tmp->next))
num++; num++;
// trouve la taille minimale de la map while (size * size < num * 4) // trouve la taille minimale de la map
while (size * size < num * 4)
size++; size++;
map = init_map(size);
//////////////////////////////////////// TEST
unsigned int print; unsigned int print;
tmp = list; tmp = list;
while (tmp) while (tmp)
@@ -201,11 +192,15 @@ void search_map(t_fillist *list)
ft_putchar('\n'); ft_putchar('\n');
tmp = tmp->next; tmp = tmp->next;
} }
//////////////////////////////////////// TEST
map = init_map(size);
// lance la recursive fill_map en augmentant la taille de la map tant qu'il n'y a pas de solution init_list(list, size);
while (!fill_map(map, list, size, list)) while (!fill_map(map, list, size, list))
{
map = init_map(size++); map = init_map(size++);
init_list(list, size);
}
print_final_map(list, size); // DEBUG print_final_map(list, size); // DEBUG
print_map(map, size, size, '#'); // DEBUG print_map(map, size, size, '#'); // DEBUG
} }