a la norme et sans erreur

This commit is contained in:
Hugo LAMY
2019-06-03 13:00:46 +02:00
parent d86dc433dc
commit 700fb91632
8 changed files with 32 additions and 67 deletions

View File

@@ -6,7 +6,7 @@
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/05/24 14:42:46 by hulamy #+# #+# */
/* Updated: 2019/06/01 14:11:32 by hulamy ### ########.fr */
/* Updated: 2019/06/03 12:51:22 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
@@ -23,14 +23,12 @@ int check_tetri_memory(t_fillist *list, int pos)
tetri = list;
mask = 1 << ((pos % 32) - 1);
if (!tetri->same && !tetri->memory)
return(1);
if (tetri->same)
{
if (!(tetri->same->memory[pos / 32] & mask))
return (tetri->same->memory[pos / 32] |= mask);
}
else if (tetri->memory)
else
{
if (!(tetri->memory[pos / 32] & mask))
return (tetri->memory[pos / 32] |= mask);
@@ -44,8 +42,6 @@ int check_tetri_memory(t_fillist *list, int pos)
int compare_tetri(t_fillist *tetri_a, t_fillist *tetri_b)
{
if (tetri_a->same)
return (0);
if (tetri_a->tetribit != tetri_b->tetribit)
return (0);
if (tetri_a->width != tetri_b->width)
@@ -82,11 +78,6 @@ int check_same_tetri(t_fillist *list, int num)
curr_tetri = clean_list_memory(list, list);
while (curr_tetri != NULL)
{
next_tetri = curr_tetri->next;
while (next_tetri != NULL)
{
if (compare_tetri(curr_tetri, next_tetri))
{
i = 0;
if (!(curr_tetri->memory =
@@ -94,11 +85,14 @@ int check_same_tetri(t_fillist *list, int num)
return (0);
while (i < num)
curr_tetri->memory[i++] = 0;
next_tetri = curr_tetri->next;
while (next_tetri != NULL)
{
if (compare_tetri(curr_tetri, next_tetri))
if (next_tetri->same == NULL)
next_tetri->same = curr_tetri;
}
next_tetri = next_tetri->next;
}
curr_tetri->position = 0;
curr_tetri->total_num = num;
curr_tetri = curr_tetri->next;
}

View File

@@ -24,20 +24,20 @@ t_fillist *print_tetri(t_fillist *list)
tmp = list;
if (list->dope[2])
{
check_same_tetri(list, 1);
while (tmp)
{
check_same_tetri(list, 1);
print = tmp->tetribit;
print <<= 16;
print_sized_map(&print, tmp->width, tmp->height, tmp->letter);
if (tmp->same && list->dope[1])
{
print = tmp->same->tetribit;
print <<= 16;
ft_putstr("same --> ");
ft_put_tetri_color(tmp->same->letter);
ft_putchar('\n');
}
if (list->dope[1] && tmp->memory)
ft_putendl("have a copy");
ft_putchar('\n');
tmp = tmp->next;
}

View File

@@ -6,7 +6,7 @@
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/01 13:29:05 by vmanzoni #+# #+# */
/* Updated: 2019/06/01 18:58:08 by hulamy ### ########.fr */
/* Updated: 2019/06/01 19:44:08 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
@@ -42,9 +42,9 @@ void print_error_extended(int error, int *dope)
if (error == 5)
print_error("error: File contains more than 26 tetriminos\n");
if (error == 6)
print_error("error: Tetrimino # are not all connected\n");
if (error == 7)
print_error("error: Tetrimino has more or less than 4 #\n");
if (error == 7)
print_error("error: Tetrimino # are not all connected\n");
print_error("error\n");
}

View File

@@ -121,7 +121,6 @@ int add_to_list(char *line, t_fillist **lst, char letter, int *dope)
tmp->letter = letter;
tmp->dope = dope;
tmp->start = *lst;
tmp->memory = NULL;
return (1);
}

View File

@@ -6,7 +6,7 @@
/* By: hulamy <hulamy@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/27 20:47:22 by hulamy #+# #+# */
/* Updated: 2019/06/03 09:54:05 by hulamy ### ########.fr */
/* Updated: 2019/06/03 13:00:28 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
@@ -103,46 +103,19 @@ void add_remove(unsigned int *map, t_fillist *list, int size)
}
}
void clean_memory(t_fillist *list, int pos, int mem)
{
t_fillist *tmp;
unsigned int mask;
tmp = list->start;
while (tmp)
{
if (tmp->memory)
{
pos = mem;
while (pos >= list->position)
{
mask = ~(1 << ((pos % 32) - 1));
tmp->memory[pos / 32] &= mask;
pos--;
}
}
tmp = tmp->next;
}
}
/*
** Function that recursively try to fill the map with the tetris
*/
int fill_map(unsigned int *map, t_fillist *list, int size)
{
int pos;
if (!list)
return (1);
pos = list->position;
list->position = 0;
while (find_place(map, list, size))
{
add_remove(map, list, size);
list->test = 1;
if (list->position < pos)
clean_memory(list, pos, pos);
if (list->dope[0])
{
print_letter_map(list->start, size, 1);

View File

@@ -43,7 +43,6 @@
** place : position sur l'axe des abscisses de la map (position % size)
** rank : position de 1 a 32 dans l'int du tableau d'int (position % 32)
** num : memorise dans quel int du tableau on se trouve (position / 32)
** total_num: memorise le nombre d'int dans le tableau
** test :
** letter : letter of the tetrimino for printing final map
** dope : flags for details, optimisation, printing and error

4
main.c
View File

@@ -6,7 +6,7 @@
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/02/12 13:20:48 by vmanzoni #+# #+# */
/* Updated: 2019/06/01 15:27:22 by vmanzoni ### ########.fr */
/* Updated: 2019/06/01 19:44:31 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
@@ -108,7 +108,7 @@ int main(int ac, char **av)
clean_list(list, list);
}
else
print_error("usage: Please submit a file.\n> ./fillit file.fillit\n");
print_error("usage: Please submit a file.\n");
free(dope);
return (0);
}