From 700fb9163213300d5511d2068f3defc8498d861c Mon Sep 17 00:00:00 2001 From: Hugo LAMY Date: Mon, 3 Jun 2019 13:00:46 +0200 Subject: [PATCH] a la norme et sans erreur --- f_bonus_opti.c | 26 ++++++++++---------------- f_bonus_print.c | 6 +++--- f_handle_errors.c | 6 +++--- f_parse_input.c | 1 - f_search_map.c | 31 ++----------------------------- fillit.h | 25 ++++++++++++------------- main.c | 4 ++-- 1tetribis => samples/1tetribis | 0 8 files changed, 32 insertions(+), 67 deletions(-) rename 1tetribis => samples/1tetribis (100%) diff --git a/f_bonus_opti.c b/f_bonus_opti.c index 1279d4e..bd2f971 100644 --- a/f_bonus_opti.c +++ b/f_bonus_opti.c @@ -6,7 +6,7 @@ /* 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; 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) @@ -83,22 +79,20 @@ int check_same_tetri(t_fillist *list, int num) curr_tetri = clean_list_memory(list, list); 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; while (next_tetri != NULL) { if (compare_tetri(curr_tetri, next_tetri)) - { - 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->same = curr_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; } diff --git a/f_bonus_print.c b/f_bonus_print.c index ccb310c..efc4223 100644 --- a/f_bonus_print.c +++ b/f_bonus_print.c @@ -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; } diff --git a/f_handle_errors.c b/f_handle_errors.c index 62c9d25..d9dc9a5 100644 --- a/f_handle_errors.c +++ b/f_handle_errors.c @@ -6,7 +6,7 @@ /* 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) 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"); } diff --git a/f_parse_input.c b/f_parse_input.c index fc13b1b..5b90a63 100644 --- a/f_parse_input.c +++ b/f_parse_input.c @@ -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); } diff --git a/f_search_map.c b/f_search_map.c index 80e4d57..cf6f156 100644 --- a/f_search_map.c +++ b/f_search_map.c @@ -6,7 +6,7 @@ /* 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 limit; - int pos; + int pos; pos = list->position; 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 */ 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); diff --git a/fillit.h b/fillit.h index e293f40..1f61ed3 100644 --- a/fillit.h +++ b/fillit.h @@ -37,20 +37,19 @@ /* ** STRUCTURE ** tetribit : tetri ecrit en binaire dans un short de 16 bits -** width : largeur du tetri -** height : hauteur du tetri +** width : largeur du tetri +** height : hauteur du tetri ** position : memorise la position d tetri bit a bit -** 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 -** memory : positions already tested by a tetrimino in bitwise -** same : pointer to previous identical tetrimino -** next : pointer to next tetrimino -** start : pointer to first tetrimino of input file +** 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) +** test : +** letter : letter of the tetrimino for printing final map +** dope : flags for details, optimisation, printing and error +** memory : positions already tested by a tetrimino in bitwise +** same : pointer to previous identical tetrimino +** next : pointer to next tetrimino +** start : pointer to first tetrimino of input file */ typedef struct s_fillist { diff --git a/main.c b/main.c index c2903a1..3f7361e 100644 --- a/main.c +++ b/main.c @@ -6,7 +6,7 @@ /* 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); } 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); } diff --git a/1tetribis b/samples/1tetribis similarity index 100% rename from 1tetribis rename to samples/1tetribis