From 8a49caad945fa28ffd2c83b7b2a44b906ba941c9 Mon Sep 17 00:00:00 2001 From: Hugo LAMY Date: Thu, 2 May 2019 00:13:11 +0200 Subject: [PATCH] find place ne depasse plus les bords de droite et du bas --- parse_input.c | 3 +-- search_map.c | 22 +++++++++------------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/parse_input.c b/parse_input.c index d69ac65..2991b11 100644 --- a/parse_input.c +++ b/parse_input.c @@ -6,7 +6,7 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/15 14:48:14 by vmanzoni #+# #+# */ -/* Updated: 2019/05/01 23:35:16 by hulamy ### ########.fr */ +/* Updated: 2019/05/01 23:47:06 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -89,7 +89,6 @@ void fill_list(char line[], t_fillist *list) list->height = i; // fabrique la ligne pour le tetriminos de la bonne largeur list->tetribit = reduce_tetri(list->tetribit, list->width); - list->position = 0; // imression pour tests // ft_putchar('\n'); diff --git a/search_map.c b/search_map.c index f9138d1..08c4aa0 100644 --- a/search_map.c +++ b/search_map.c @@ -6,7 +6,7 @@ /* By: hulamy +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/27 20:47:22 by hulamy #+# #+# */ -/* Updated: 2019/05/01 23:46:11 by hulamy ### ########.fr */ +/* Updated: 2019/05/02 00:11:48 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -28,8 +28,11 @@ int find_place(unsigned int *tab, t_fillist *list, int size, int pos) tmp = mask; i = pos; // boucle jusqu'a la dernier place pour le tetri dans la map ou qu'il fit dans un trou - while (i < (size - list->height + 1) * size) + while (i <= (size - list->height) * size) { + // pour ne pas deborder a droite de la map + if (i % size == size - list->width + 1) + i += list->width - 1; tmp = 0; // construit un tmp qui est une photo de la map de la taille du tetri a un emplacement donne j = (list->height - 1) * size + i; @@ -42,9 +45,6 @@ int find_place(unsigned int *tab, t_fillist *list, int size, int pos) } if (!((tmp >> 16) & list->tetribit)) return (i + 1); - // pour ne pas deborder a droite de la map - if (i % size == size - list->width) - i += list->width - 1; i++; } return (0); @@ -88,19 +88,15 @@ int fill_map(unsigned int *map, t_fillist *list, int size) return (1); while ((pos = find_place(map, list, size, pos))) { - ft_putchar('\n'); ft_putendl("add_remove"); // POUR DEBUG +// ft_putchar('\n'); ft_putendl("add_remove"); // POUR DEBUG add_remove(map, list, size, pos); print_map(map, size, size); // POUR DEBUG ft_putchar('\n'); // POUR DEBUG if (fill_map(map, list->next, size)) - { - list->position = pos; - return (1); - } + return (list->position = pos); add_remove(map, list, size, pos); - print_map(map, size, size); // POUR DEBUG - ft_putchar('\n'); // POUR DEBUG - list->position++; +// print_map(map, size, size); // POUR DEBUG +// ft_putchar('\n'); // POUR DEBUG } return (0); }