a la norme et sans erreur
This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/05/24 14:42:46 by hulamy #+# #+# */
|
/* 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;
|
tetri = list;
|
||||||
mask = 1 << ((pos % 32) - 1);
|
mask = 1 << ((pos % 32) - 1);
|
||||||
if (!tetri->same && !tetri->memory)
|
|
||||||
return(1);
|
|
||||||
if (tetri->same)
|
if (tetri->same)
|
||||||
{
|
{
|
||||||
if (!(tetri->same->memory[pos / 32] & mask))
|
if (!(tetri->same->memory[pos / 32] & mask))
|
||||||
return (tetri->same->memory[pos / 32] |= mask);
|
return (tetri->same->memory[pos / 32] |= mask);
|
||||||
}
|
}
|
||||||
else if (tetri->memory)
|
else
|
||||||
{
|
{
|
||||||
if (!(tetri->memory[pos / 32] & mask))
|
if (!(tetri->memory[pos / 32] & mask))
|
||||||
return (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)
|
int compare_tetri(t_fillist *tetri_a, t_fillist *tetri_b)
|
||||||
{
|
{
|
||||||
if (tetri_a->same)
|
|
||||||
return (0);
|
|
||||||
if (tetri_a->tetribit != tetri_b->tetribit)
|
if (tetri_a->tetribit != tetri_b->tetribit)
|
||||||
return (0);
|
return (0);
|
||||||
if (tetri_a->width != tetri_b->width)
|
if (tetri_a->width != tetri_b->width)
|
||||||
@@ -83,22 +79,20 @@ int check_same_tetri(t_fillist *list, int num)
|
|||||||
curr_tetri = clean_list_memory(list, list);
|
curr_tetri = clean_list_memory(list, list);
|
||||||
while (curr_tetri != NULL)
|
while (curr_tetri != NULL)
|
||||||
{
|
{
|
||||||
|
i = 0;
|
||||||
|
if (!(curr_tetri->memory =
|
||||||
|
(unsigned int *)malloc(sizeof(*curr_tetri->memory) * num)))
|
||||||
|
return (0);
|
||||||
|
while (i < num)
|
||||||
|
curr_tetri->memory[i++] = 0;
|
||||||
next_tetri = curr_tetri->next;
|
next_tetri = curr_tetri->next;
|
||||||
while (next_tetri != NULL)
|
while (next_tetri != NULL)
|
||||||
{
|
{
|
||||||
if (compare_tetri(curr_tetri, next_tetri))
|
if (compare_tetri(curr_tetri, next_tetri))
|
||||||
{
|
if (next_tetri->same == NULL)
|
||||||
i = 0;
|
next_tetri->same = curr_tetri;
|
||||||
if (!(curr_tetri->memory =
|
|
||||||
(unsigned int *)malloc(sizeof(*curr_tetri->memory) * num)))
|
|
||||||
return (0);
|
|
||||||
while (i < num)
|
|
||||||
curr_tetri->memory[i++] = 0;
|
|
||||||
next_tetri->same = curr_tetri;
|
|
||||||
}
|
|
||||||
next_tetri = next_tetri->next;
|
next_tetri = next_tetri->next;
|
||||||
}
|
}
|
||||||
curr_tetri->position = 0;
|
|
||||||
curr_tetri->total_num = num;
|
curr_tetri->total_num = num;
|
||||||
curr_tetri = curr_tetri->next;
|
curr_tetri = curr_tetri->next;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,20 +24,20 @@ t_fillist *print_tetri(t_fillist *list)
|
|||||||
tmp = list;
|
tmp = list;
|
||||||
if (list->dope[2])
|
if (list->dope[2])
|
||||||
{
|
{
|
||||||
check_same_tetri(list, 1);
|
|
||||||
while (tmp)
|
while (tmp)
|
||||||
{
|
{
|
||||||
|
check_same_tetri(list, 1);
|
||||||
print = tmp->tetribit;
|
print = tmp->tetribit;
|
||||||
print <<= 16;
|
print <<= 16;
|
||||||
print_sized_map(&print, tmp->width, tmp->height, tmp->letter);
|
print_sized_map(&print, tmp->width, tmp->height, tmp->letter);
|
||||||
if (tmp->same && list->dope[1])
|
if (tmp->same && list->dope[1])
|
||||||
{
|
{
|
||||||
|
print = tmp->same->tetribit;
|
||||||
|
print <<= 16;
|
||||||
ft_putstr("same --> ");
|
ft_putstr("same --> ");
|
||||||
ft_put_tetri_color(tmp->same->letter);
|
ft_put_tetri_color(tmp->same->letter);
|
||||||
ft_putchar('\n');
|
ft_putchar('\n');
|
||||||
}
|
}
|
||||||
if (list->dope[1] && tmp->memory)
|
|
||||||
ft_putendl("have a copy");
|
|
||||||
ft_putchar('\n');
|
ft_putchar('\n');
|
||||||
tmp = tmp->next;
|
tmp = tmp->next;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/03/01 13:29:05 by vmanzoni #+# #+# */
|
/* 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)
|
if (error == 5)
|
||||||
print_error("error: File contains more than 26 tetriminos\n");
|
print_error("error: File contains more than 26 tetriminos\n");
|
||||||
if (error == 6)
|
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");
|
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");
|
print_error("error\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -121,7 +121,6 @@ int add_to_list(char *line, t_fillist **lst, char letter, int *dope)
|
|||||||
tmp->letter = letter;
|
tmp->letter = letter;
|
||||||
tmp->dope = dope;
|
tmp->dope = dope;
|
||||||
tmp->start = *lst;
|
tmp->start = *lst;
|
||||||
tmp->memory = NULL;
|
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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/06/03 09:54:05 by hulamy ### ########.fr */
|
/* Updated: 2019/06/03 13:00:28 by hulamy ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -52,7 +52,7 @@ unsigned int fit_in_place(unsigned int *map, t_fillist *lst, int sze, int i)
|
|||||||
int find_place(unsigned int *map, t_fillist *list, int size)
|
int find_place(unsigned int *map, t_fillist *list, int size)
|
||||||
{
|
{
|
||||||
int limit;
|
int limit;
|
||||||
int pos;
|
int pos;
|
||||||
|
|
||||||
pos = list->position;
|
pos = list->position;
|
||||||
list->place = pos % size;
|
list->place = pos % size;
|
||||||
@@ -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
|
** Function that recursively try to fill the map with the tetris
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int fill_map(unsigned int *map, t_fillist *list, int size)
|
int fill_map(unsigned int *map, t_fillist *list, int size)
|
||||||
{
|
{
|
||||||
int pos;
|
|
||||||
|
|
||||||
if (!list)
|
if (!list)
|
||||||
return (1);
|
return (1);
|
||||||
pos = list->position;
|
|
||||||
list->position = 0;
|
list->position = 0;
|
||||||
while (find_place(map, list, size))
|
while (find_place(map, list, size))
|
||||||
{
|
{
|
||||||
add_remove(map, list, size);
|
add_remove(map, list, size);
|
||||||
list->test = 1;
|
list->test = 1;
|
||||||
if (list->position < pos)
|
|
||||||
clean_memory(list, pos, pos);
|
|
||||||
if (list->dope[0])
|
if (list->dope[0])
|
||||||
{
|
{
|
||||||
print_letter_map(list->start, size, 1);
|
print_letter_map(list->start, size, 1);
|
||||||
|
|||||||
25
fillit.h
25
fillit.h
@@ -37,20 +37,19 @@
|
|||||||
/*
|
/*
|
||||||
** STRUCTURE
|
** STRUCTURE
|
||||||
** tetribit : tetri ecrit en binaire dans un short de 16 bits
|
** tetribit : tetri ecrit en binaire dans un short de 16 bits
|
||||||
** width : largeur du tetri
|
** width : largeur du tetri
|
||||||
** height : hauteur du tetri
|
** height : hauteur du tetri
|
||||||
** position : memorise la position d tetri bit a bit
|
** position : memorise la position d tetri bit a bit
|
||||||
** place : position sur l'axe des abscisses de la map (position % size)
|
** 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)
|
** 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)
|
** num : memorise dans quel int du tableau on se trouve (position / 32)
|
||||||
** total_num: memorise le nombre d'int dans le tableau
|
** test :
|
||||||
** test :
|
** letter : letter of the tetrimino for printing final map
|
||||||
** letter : letter of the tetrimino for printing final map
|
** dope : flags for details, optimisation, printing and error
|
||||||
** dope : flags for details, optimisation, printing and error
|
** memory : positions already tested by a tetrimino in bitwise
|
||||||
** memory : positions already tested by a tetrimino in bitwise
|
** same : pointer to previous identical tetrimino
|
||||||
** same : pointer to previous identical tetrimino
|
** next : pointer to next tetrimino
|
||||||
** next : pointer to next tetrimino
|
** start : pointer to first tetrimino of input file
|
||||||
** start : pointer to first tetrimino of input file
|
|
||||||
*/
|
*/
|
||||||
typedef struct s_fillist
|
typedef struct s_fillist
|
||||||
{
|
{
|
||||||
|
|||||||
4
main.c
4
main.c
@@ -6,7 +6,7 @@
|
|||||||
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/02/12 13:20:48 by vmanzoni #+# #+# */
|
/* 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);
|
clean_list(list, list);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
print_error("usage: Please submit a file.\n> ./fillit file.fillit\n");
|
print_error("usage: Please submit a file.\n");
|
||||||
free(dope);
|
free(dope);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user