From 8da1c5bec65cc748bca3382a8f7ad320dfc81082 Mon Sep 17 00:00:00 2001 From: Hugo LAMY Date: Wed, 24 Apr 2019 15:47:42 +0200 Subject: [PATCH 01/17] rangement des fichiers tests et makefile --- Makefile | 58 +++++----- README.md | 20 ---- parse_input.c | 103 +++++++++--------- add_to_list.c => test_add_to_list.c | 4 +- ...est_square.c => test_get_smallest_square.c | 0 print_fillit.c => test_print_fillit.c | 0 6 files changed, 77 insertions(+), 108 deletions(-) delete mode 100644 README.md rename add_to_list.c => test_add_to_list.c (95%) rename get_smallest_square.c => test_get_smallest_square.c (100%) rename print_fillit.c => test_print_fillit.c (100%) diff --git a/Makefile b/Makefile index acf29e3..8e8e8d3 100644 --- a/Makefile +++ b/Makefile @@ -6,49 +6,43 @@ # By: vmanzoni +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2019/03/01 13:24:35 by vmanzoni #+# #+# # -# Updated: 2019/04/24 13:49:48 by hulamy ### ########.fr # +# Updated: 2019/04/24 15:44:55 by hulamy ### ########.fr # # # # **************************************************************************** # -NAME = fillit +# - - - - - - - - - - - - - - - # +# VARIABLES # +# - - - - - - - - - - - - - - - # -OBJ_DIR = ./objs -HEADER = fillit.h +NAME = fillit +CC = gcc -SRCS = main.c \ - read_file.c \ - handle_errors.c \ - parse_input.c \ - add_to_list.c \ -# get_smallest_square.c \ - print_fillit.c +CFLAGS = -I. +CFLAGS += -Wall -Wextra -Werror + +LDFLAGS = -L./libft/ +LDLIBS = -lft + +SRCS = $(shell find . -depth 1 -type f -not -name '.*' -not -name 'test*' -name '*.c') -OBJS = $(SRCS:.c=.o) -LIB = libft/ +# - - - - - - - - - - - - - - - # +# RULES # +# - - - - - - - - - - - - - - - # -CC = gcc -CFLAGS = -Wall -Werror -Wextra +all: $(NAME) -RM = rm -rf +$(NAME): $(SRCS) + $(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) $(SRCS) -o $(NAME) -all: $(NAME) +debug: + $(CC) -g $(CFLAGS) $(LDFLAGS) $(LDLIBS) $(SRCS) -o $(NAME) -$(NAME): - make -C $(LIB) - $(CC) $(CFLAGS) -I$(HEADER) -c $(SRCS) - $(CC) -o $(NAME) $(OBJS) -L $(LIB) -lft - mkdir $(OBJ_DIR) - mv $(OBJS) $(OBJ_DIR) +lib: + make -C ./libft/ clean: - make -C libft/ clean - $(RM) $(OBJ_DIR) + /bin/rm -rf $(NAME) + /bin/rm -rf $(NAME).dSYM -fclean: clean - make -C libft/ fclean - $(RM) $(NAME) - -re: fclean all - -.PHONY: all clean fclean re +re: clean all diff --git a/README.md b/README.md deleted file mode 100644 index 92de26a..0000000 --- a/README.md +++ /dev/null @@ -1,20 +0,0 @@ -# Fillit - -**hulamy** and **vmanzoni** - -## To do - -- [x] Check if we have a file -- [x] Read file -- [x] Check if there are errors in file - - At least 1 tetrimino or less than 26 -- [x] Check if every tetrimino is valid - - 4 char * 4 lines - - 4 blocks in 1 tetrimino - - No solo block -- [x] Transform file into tetriminos -- [ ] Backtracking for smallest square -- [ ] Transform tetriminos to letters -- [ ] Print result - -- [ ] Optimisation diff --git a/parse_input.c b/parse_input.c index c98c57b..3b75b63 100644 --- a/parse_input.c +++ b/parse_input.c @@ -6,28 +6,63 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/15 14:48:14 by vmanzoni #+# #+# */ -/* Updated: 2019/04/24 13:48:21 by hulamy ### ########.fr */ +/* Updated: 2019/04/24 15:12:32 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ #include "fillit.h" /* -** DELETE BEFORE EVAL -** Function that print a short in bites +** Function that transforme a tetrminos char* into a short of 16 bites +** and then fills it and its reversed into the list */ -//void print_short(short octet) -//{ -// unsigned int i; -// -// i = 1 << 15; -// while (i) -// { -// (octet & i) ? printf("1") : printf("0"); -// i >>= 1; -// } -//} +void fill_list(char line[], t_fillist *list) +{ + unsigned short tmp; + int i; + + i = 0; + while (line[i]) + { + list->tetribit <<= 1; + if (line[i] == '\n') + i++; + if (line[i++] == '#') + list->tetribit |= 1; + } + while (!(list->tetribit & (1 << 15))) + list->tetribit <<= 1; + tmp = list->tetribit; + while (tmp) + { + list->tibirtet <<= 1; + if (tmp & 1) + list->tibirtet |= 1; + tmp >>= 1; + } +} + +/* +** Function that creates the linked list and add a new structure +** linked each time needed +*/ + +int add_to_list(char *line, t_fillist **list) +{ + t_fillist *tmp; + + if (!(tmp = (t_fillist*)malloc(sizeof(*tmp)))) + return (0); + if (!(*list)) + tmp->next = NULL; + else + tmp->next = *list; + *list = tmp; + fill_list(line, *list); + return (1); +} + /* ** Function that parse a file and put each tetrimino in a linked list @@ -41,7 +76,6 @@ void parse_input(char *input) int j; i = 0; -// printf("%s", input); while (input[i]) { j = 0; @@ -51,47 +85,8 @@ void parse_input(char *input) if (check_tetri_errors(tetri)) print_error("Error: Tetrimino not valid."); add_to_list(tetri, &list); -// printf("added to list !!\n"); while (input[i] && input[i] != '.' && input[i] != '#') i++; } -/* DEBUG PART - Print each tetribit*/ -// while (list != NULL) -// { -// printf("%i\n", list->tetribit); -// print_short(list->tetribit); -// printf("\n"); -// print_short(list->tibirtet); -// printf("\n"); -// list = list->next; -// } } -/* -** DELETE BEFORE EVAL - NOT USED ANYMORE -** Function that parse a file and put each tetrimino in a linked list -*/ - -// char **create_square(char *tetri) -// { -// char **square; -// int i; -// int k; -// -// i = 0; -// if (!(square = (char**)malloc(sizeof(*square) * (4 + 1)))) -// return (NULL); -// square[4] = NULL; -// while (*tetri && (k = -1)) -// { -// if (!(square[i] = (char*)malloc(sizeof(**square) * (4 + 1)))) -// return (NULL); -// square[i][4] = '\0'; -// while (++k < 4) -// square[i][k] = *(tetri++); -// while (*tetri == '\n') -// tetri++; -// i++; -// } -// return (square); -// } diff --git a/add_to_list.c b/test_add_to_list.c similarity index 95% rename from add_to_list.c rename to test_add_to_list.c index add0b91..d90ca8f 100644 --- a/add_to_list.c +++ b/test_add_to_list.c @@ -6,7 +6,7 @@ /* By: hulamy +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/14 15:20:53 by hulamy #+# #+# */ -/* Updated: 2019/04/24 13:45:53 by hulamy ### ########.fr */ +/* Updated: 2019/04/24 15:12:48 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,7 +30,7 @@ /* ** Function that transforme a tetrminos char* into a short of 16 bites -** then it fills it and its reverse into the list +** and then fills it and its reversed into the list */ void fill_list(char line[], t_fillist *list) diff --git a/get_smallest_square.c b/test_get_smallest_square.c similarity index 100% rename from get_smallest_square.c rename to test_get_smallest_square.c diff --git a/print_fillit.c b/test_print_fillit.c similarity index 100% rename from print_fillit.c rename to test_print_fillit.c From dabdd7dbefdd223e455503da5f934fd4c6b0c57b Mon Sep 17 00:00:00 2001 From: Hugo LAMY Date: Thu, 25 Apr 2019 05:32:29 +0200 Subject: [PATCH 02/17] print_map fonctionne avec deux versions --- fillit.h | 3 +- parse_input.c | 10 +++++- test_right.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+), 3 deletions(-) create mode 100644 test_right.c diff --git a/fillit.h b/fillit.h index 247b5c6..172bc80 100644 --- a/fillit.h +++ b/fillit.h @@ -6,7 +6,7 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/03/01 13:34:46 by vmanzoni #+# #+# */ -/* Updated: 2019/04/24 13:46:32 by hulamy ### ########.fr */ +/* Updated: 2019/04/24 15:49:08 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -43,6 +43,5 @@ void parse_input(char *input); int check_file_errors(char *file); int check_tetri_errors(char *tetri); int check_tetri_errors_proxy(char *tetri); -int add_to_list(char *square, t_fillist **list); #endif diff --git a/parse_input.c b/parse_input.c index 3b75b63..511533f 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/04/24 15:12:32 by hulamy ### ########.fr */ +/* Updated: 2019/04/24 16:18:16 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -63,6 +63,13 @@ int add_to_list(char *line, t_fillist **list) return (1); } +void find_map(t_fillist *list) +{ + unsigned int map[10]; + + fill_map(list, map); + print_maop(map); +} /* ** Function that parse a file and put each tetrimino in a linked list @@ -88,5 +95,6 @@ void parse_input(char *input) while (input[i] && input[i] != '.' && input[i] != '#') i++; } + find_map(list); } diff --git a/test_right.c b/test_right.c new file mode 100644 index 0000000..b56b656 --- /dev/null +++ b/test_right.c @@ -0,0 +1,89 @@ +#include "./libft/includes/libft.h" + +void print_bits(unsigned int bits, int size) +{ + unsigned int mask; + + mask = 1 << (size - 1); + while (mask) + { + (bits & mask) ? write(1, "#", 1) : write(1, ".", 1); + write(1, " ", 1); + mask >>= 1; + } + write(1, "\n", 1); +} + +void print_map(unsigned int *tab, int s) +{ + int i; + unsigned int m; + unsigned int tmp; + + i = 0; + m = 0; + // creer un mask avec les size bits de gauche a 1 (ex: 11111110000000000000000000000000) + while (i++ < s) + m = (m >> 1) | ((m | 1) << 31); + write(1, "\n", 1); + i = 0; + while (i < s * s) + { +// /* +// ** first version : +// ** +// ** tmp = ((m >> i) & tab[i / 32]) << i; +// ** tmp |= ((m << (32 - i)) & tab[(i + s) / 32]) >> (32 - i); +// ** tmp >>= 32 - s; +// ** print_bits(tmp, s); +// ** i += s; +// */ +// +// tmp = (m & (tab[i / 32] << i)) | (m & (tab[(i + s) / 32] >> (32 - i))); +// print_bits(tmp >> (32 - s), s); +// i += s; + + /* + ** second version : + ** n'utilise pas le mask m + */ + if (!(i % s)) + ft_putchar('\n'); + tab[i / 32] & (1 << (31 - i % 32)) ? ft_putchar('#') : ft_putchar('.'); + ft_putchar(' '); + i++; + } + write(1, "\n", 1); +} + +int main(int ac, char **av) +{ + unsigned int tab[8]; + + // ce tableau permet de monter jusqu'a une map de 16*16 + tab[0] = 2656554334; + tab[1] = 1394456818; + tab[2] = 1494256918; + tab[3] = 2656554334; + tab[4] = 1592453883; + tab[5] = 1444352908; + tab[6] = 2154339230; + tab[7] = 1576493154; + print_bits(tab[0], 32); + print_bits(tab[1], 32); + print_bits(tab[2], 32); + print_bits(tab[3], 32); + print_bits(tab[4], 32); + print_bits(tab[5], 32); + print_bits(tab[6], 32); + print_bits(tab[7], 32); + if (ac > 1) + { + ++av; + // mettre l'option "b" pour afficher la troisieme argument en binaire + if (av[0][0] == 'b' && ac > 2) + ft_putendl(ft_convertbase(av[1], "01", "0123456789")); + print_map(tab, 16); + } + return (0); +} From 2364b6322a9629b64f4336af6acd780986bbe34e Mon Sep 17 00:00:00 2001 From: Hugo LAMY Date: Thu, 25 Apr 2019 07:06:37 +0200 Subject: [PATCH 03/17] fonction pour verifier si l'emplacement est libre en cours de construction --- test_right.c | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/test_right.c b/test_right.c index b56b656..1e5b9ff 100644 --- a/test_right.c +++ b/test_right.c @@ -45,7 +45,7 @@ void print_map(unsigned int *tab, int s) /* ** second version : - ** n'utilise pas le mask m + ** n'utilise pas le mask m et le tmp */ if (!(i % s)) ft_putchar('\n'); @@ -56,6 +56,43 @@ void print_map(unsigned int *tab, int s) write(1, "\n", 1); } +void find_place(unsigned int *tab, char *line, int s) +{ + unsigned short tetri; + int i; + unsigned int m; + unsigned int tmp; + + ft_putendl("# . . # # # # T T # . # . # # # # # . . # # . # T # . # # # # . . # . # . . # # T . . # # # . # # . # # # . . . # # # # . . # . . # . # # . . # . . . # . . . . # . . . # # . # . . . # . # # ."); + // create tetri + i = 0; + while (line[i]) + { + tetri <<= 1; + if (line[i] == '\n') + i++; + if (line[i++] == '#') + tetri |= 1; + } + while (!(tetri & (1 << 15))) + tetri <<= 1; + print_bits(tetri, 16); + write(1, "\n", 1); + + m = 15 << (32 - 4); + i = 0; + while (i < 20) + { + while (i < 4 * s) + { + tmp = (m & (tab[i / 32] << i)) | (m & (tab[(i + s) / 32] >> (32 - i))); + print_bits(tmp, 32); + i += s; + } + i++; + } +} + int main(int ac, char **av) { unsigned int tab[8]; @@ -84,6 +121,9 @@ int main(int ac, char **av) if (av[0][0] == 'b' && ac > 2) ft_putendl(ft_convertbase(av[1], "01", "0123456789")); print_map(tab, 16); + write(1, "\n", 1); + if (av[0][0] == 't' && ac > 2) + find_place(tab, av[1], 16); } return (0); } From 23ec23f8bc02e234f1367dc7ae7cef31e8fdec4e Mon Sep 17 00:00:00 2001 From: Hugo LAMY Date: Thu, 25 Apr 2019 14:46:46 +0200 Subject: [PATCH 04/17] boucle cherche tetra dans map et trouve quand ca fit --- test_right.c | 75 +++++++++++++++++++++++++--------------------------- 1 file changed, 36 insertions(+), 39 deletions(-) diff --git a/test_right.c b/test_right.c index 1e5b9ff..cda3782 100644 --- a/test_right.c +++ b/test_right.c @@ -14,40 +14,21 @@ void print_bits(unsigned int bits, int size) write(1, "\n", 1); } -void print_map(unsigned int *tab, int s) +void print_map(unsigned int *tab, int size) { int i; - unsigned int m; + unsigned int mask; unsigned int tmp; i = 0; - m = 0; + mask = 0; // creer un mask avec les size bits de gauche a 1 (ex: 11111110000000000000000000000000) - while (i++ < s) - m = (m >> 1) | ((m | 1) << 31); - write(1, "\n", 1); + while (i++ < size) + mask = (mask >> 1) | ((mask | 1) << 31); i = 0; - while (i < s * s) + while (i < size * size) { -// /* -// ** first version : -// ** -// ** tmp = ((m >> i) & tab[i / 32]) << i; -// ** tmp |= ((m << (32 - i)) & tab[(i + s) / 32]) >> (32 - i); -// ** tmp >>= 32 - s; -// ** print_bits(tmp, s); -// ** i += s; -// */ -// -// tmp = (m & (tab[i / 32] << i)) | (m & (tab[(i + s) / 32] >> (32 - i))); -// print_bits(tmp >> (32 - s), s); -// i += s; - - /* - ** second version : - ** n'utilise pas le mask m et le tmp - */ - if (!(i % s)) + if (!(i % size)) ft_putchar('\n'); tab[i / 32] & (1 << (31 - i % 32)) ? ft_putchar('#') : ft_putchar('.'); ft_putchar(' '); @@ -56,16 +37,18 @@ void print_map(unsigned int *tab, int s) write(1, "\n", 1); } -void find_place(unsigned int *tab, char *line, int s) +void find_place(unsigned int *tab, char *line, int size) { unsigned short tetri; int i; - unsigned int m; + int j; + unsigned int mask; unsigned int tmp; - ft_putendl("# . . # # # # T T # . # . # # # # # . . # # . # T # . # # # # . . # . # . . # # T . . # # # . # # . # # # . . . # # # # . . # . . # . # # . . # . . . # . . . . # . . . # # . # . . . # . # # ."); - // create tetri +// ft_putendl("# . . # # # # T T # . # . # # # # # . . # # . # T # . # # # # . . # . # . . # # T . . # # # . # # . # # # . . . # # # # . . # . . # . # # . . # . . . # . . . . # . . . # # . # . . . # . # # ."); + /////////////// create tetri /////////////// i = 0; + tmp = 0; while (line[i]) { tetri <<= 1; @@ -77,18 +60,32 @@ void find_place(unsigned int *tab, char *line, int s) while (!(tetri & (1 << 15))) tetri <<= 1; print_bits(tetri, 16); - write(1, "\n", 1); + tmp = (tetri | tmp) << 16; + print_map(&tmp, 4); + /////////////// create tetri /////////////// - m = 15 << (32 - 4); + mask = 15 << (32 - 4); i = 0; - while (i < 20) + while (i < 16) { - while (i < 4 * s) + tmp = 0; + j = 3 * size + i; + ft_putnbrendl(j); + while (j >= i) { - tmp = (m & (tab[i / 32] << i)) | (m & (tab[(i + s) / 32] >> (32 - i))); - print_bits(tmp, 32); - i += s; + tmp >>= 4; + tmp |= (mask & (tab[j / 32] << j)); + tmp |= (mask & (tab[(j + size) / 32] >> (32 - j))); + // print_bits(tmp, 32); + j -= size; } + //write(1, "\n", 1); + print_map(&tmp, 4); + print_bits(tmp >> 16, 32); + print_bits(tetri, 32); + //print_bits((tmp >> 16) & tetri, 32); + if (i % size == size - 4) + i += 3; i++; } } @@ -120,10 +117,10 @@ int main(int ac, char **av) // mettre l'option "b" pour afficher la troisieme argument en binaire if (av[0][0] == 'b' && ac > 2) ft_putendl(ft_convertbase(av[1], "01", "0123456789")); - print_map(tab, 16); + print_map(tab, 10); write(1, "\n", 1); if (av[0][0] == 't' && ac > 2) - find_place(tab, av[1], 16); + find_place(tab, av[1], 10); } return (0); } From ac29587a100d59348107abaaa7425b78541f2e1a Mon Sep 17 00:00:00 2001 From: Hugo LAMY Date: Thu, 25 Apr 2019 15:00:32 +0200 Subject: [PATCH 05/17] nettoye parse_input avec add_to_list a l'interieur --- parse_input.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/parse_input.c b/parse_input.c index 511533f..50f613c 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/04/24 16:18:16 by hulamy ### ########.fr */ +/* Updated: 2019/04/25 14:59:45 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -63,14 +63,6 @@ int add_to_list(char *line, t_fillist **list) return (1); } -void find_map(t_fillist *list) -{ - unsigned int map[10]; - - fill_map(list, map); - print_maop(map); -} - /* ** Function that parse a file and put each tetrimino in a linked list */ @@ -95,6 +87,5 @@ void parse_input(char *input) while (input[i] && input[i] != '.' && input[i] != '#') i++; } - find_map(list); } From 4007f0d707c8a95011d743cda47128641e24b7c0 Mon Sep 17 00:00:00 2001 From: Hugo LAMY Date: Thu, 25 Apr 2019 16:25:26 +0200 Subject: [PATCH 06/17] la recherche du tetri qui rentre dans la map fonctionne avec toutes les tailles de tetri --- test_right.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/test_right.c b/test_right.c index cda3782..88e4183 100644 --- a/test_right.c +++ b/test_right.c @@ -44,11 +44,13 @@ void find_place(unsigned int *tab, char *line, int size) int j; unsigned int mask; unsigned int tmp; + int large; // ft_putendl("# . . # # # # T T # . # . # # # # # . . # # . # T # . # # # # . . # . # . . # # T . . # # # . # # . # # # . . . # # # # . . # . . # . # # . . # . . . # . . . . # . . . # # . # . . . # . # # ."); /////////////// create tetri /////////////// i = 0; tmp = 0; + large = 3; while (line[i]) { tetri <<= 1; @@ -61,31 +63,31 @@ void find_place(unsigned int *tab, char *line, int size) tetri <<= 1; print_bits(tetri, 16); tmp = (tetri | tmp) << 16; - print_map(&tmp, 4); + print_map(&tmp, large); /////////////// create tetri /////////////// - mask = 15 << (32 - 4); + mask = ~0; + mask <<= 32 - large; + ft_putendl("mask: "); + print_bits(mask, 32); i = 0; - while (i < 16) + while (i < 20) { tmp = 0; j = 3 * size + i; - ft_putnbrendl(j); while (j >= i) { - tmp >>= 4; + tmp >>= large; tmp |= (mask & (tab[j / 32] << j)); tmp |= (mask & (tab[(j + size) / 32] >> (32 - j))); - // print_bits(tmp, 32); j -= size; } - //write(1, "\n", 1); - print_map(&tmp, 4); + print_map(&tmp, large); print_bits(tmp >> 16, 32); print_bits(tetri, 32); - //print_bits((tmp >> 16) & tetri, 32); - if (i % size == size - 4) - i += 3; + print_bits((tmp >> 16) & tetri, 32); + if (i % size == size - large) + i += large - 1; i++; } } From c83ac7599d801125d13fa6a680b17e4cb286a293 Mon Sep 17 00:00:00 2001 From: Hugo LAMY Date: Thu, 25 Apr 2019 18:45:21 +0200 Subject: [PATCH 07/17] tous les champs de list remplis --- fillit.h | 5 ++-- parse_input.c | 74 ++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 68 insertions(+), 11 deletions(-) diff --git a/fillit.h b/fillit.h index 172bc80..5f863b5 100644 --- a/fillit.h +++ b/fillit.h @@ -6,7 +6,7 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/03/01 13:34:46 by vmanzoni #+# #+# */ -/* Updated: 2019/04/24 15:49:08 by hulamy ### ########.fr */ +/* Updated: 2019/04/25 16:41:29 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -28,7 +28,8 @@ typedef struct s_fillist { unsigned short tetribit; - unsigned short tibirtet; + int large; + int height; int position; struct s_fillist *next; } t_fillist; diff --git a/parse_input.c b/parse_input.c index 50f613c..c8d34e8 100644 --- a/parse_input.c +++ b/parse_input.c @@ -6,12 +6,47 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/15 14:48:14 by vmanzoni #+# #+# */ -/* Updated: 2019/04/25 14:59:45 by hulamy ### ########.fr */ +/* Updated: 2019/04/25 18:44:53 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ #include "fillit.h" +void print_bits(unsigned int bits, int size) +{ + unsigned int mask; + + mask = 1 << (size - 1); + while (mask) + { + (bits & mask) ? write(1, "#", 1) : write(1, ".", 1); + write(1, " ", 1); + mask >>= 1; + } + write(1, "\n", 1); +} + +void print_map(unsigned int *tab, int large, int height) +{ + int i; + unsigned int mask; + + i = 0; + mask = 0; + while (i++ < large) + mask = (mask >> 1) | ((mask | 1) << 31); + i = 0; + while (i < large * height) + { + if (!(i % large)) + ft_putchar('\n'); + tab[i / 32] & (1 << (31 - i % 32)) ? ft_putchar('#') : ft_putchar('.'); + ft_putchar(' '); + i++; + } + write(1, "\n", 1); +} + /* ** Function that transforme a tetrminos char* into a short of 16 bites ** and then fills it and its reversed into the list @@ -19,10 +54,12 @@ void fill_list(char line[], t_fillist *list) { - unsigned short tmp; + unsigned int tmp; + unsigned short mask; int i; i = 0; + // transforme la ligne de . et # en un short de 0 et 1 while (line[i]) { list->tetribit <<= 1; @@ -31,16 +68,35 @@ void fill_list(char line[], t_fillist *list) if (line[i++] == '#') list->tetribit |= 1; } + // deplace le tetriminos tout en haut a gauche while (!(list->tetribit & (1 << 15))) list->tetribit <<= 1; + // cree un mask avec des 1 sur la colonne de droite + mask = (1 << 15) | (1 << 11) | (1 << 7) | (1 << 3); + // utilise le mask pour trouver la largeur que prend le tetriminos + i = -1; + while (i++ < 4 && mask & list->tetribit) + mask >>= 1; + list->large = i; + // cree un mask avec des 1 a gauche sur la largeur du tetriminos + mask = ~0; + mask <<= 16 - i; + // fabrique la ligne pour le tetriminos de la bonne largeur tmp = list->tetribit; - while (tmp) - { - list->tibirtet <<= 1; - if (tmp & 1) - list->tibirtet |= 1; - tmp >>= 1; - } + list->tetribit = (mask & tmp) | ((mask & tmp << 4) >> i); + list->tetribit |= ((mask & tmp << 8) >> 2 * i); + list->tetribit |= ((mask & tmp << 12) >> 3 * i); + // trouve la hauteur du tetri + i = 1; + print_bits(tmp, 32); + while (i && !(tmp & 1 << i)) + i++; + ft_putnbrendl((16 - i) / 4 + ((16 - i) % 4 != 0)); + list->height = ((16 - i) / 4 + ((16 - i) % 4 != 0)); + + tmp = list->tetribit; + tmp <<= 16; + print_map(&tmp, list->large, 4); } /* From b5ad1209f415133a1310dad2d1e29831ed1bd05b Mon Sep 17 00:00:00 2001 From: Hugo LAMY Date: Sat, 27 Apr 2019 02:01:54 +0200 Subject: [PATCH 08/17] add_to_list fonctionne pleinement en binaire et creer un vrai tetri reduit et ses dimensions --- fillit.h | 4 +- parse_input.c | 115 ++++++++++++++++++++++++++++++++++---------------- 2 files changed, 81 insertions(+), 38 deletions(-) diff --git a/fillit.h b/fillit.h index 5f863b5..ec0b69d 100644 --- a/fillit.h +++ b/fillit.h @@ -6,7 +6,7 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/03/01 13:34:46 by vmanzoni #+# #+# */ -/* Updated: 2019/04/25 16:41:29 by hulamy ### ########.fr */ +/* Updated: 2019/04/27 00:34:44 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -28,7 +28,7 @@ typedef struct s_fillist { unsigned short tetribit; - int large; + int width; int height; int position; struct s_fillist *next; diff --git a/parse_input.c b/parse_input.c index c8d34e8..0f90aa9 100644 --- a/parse_input.c +++ b/parse_input.c @@ -6,12 +6,17 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/15 14:48:14 by vmanzoni #+# #+# */ -/* Updated: 2019/04/25 18:44:53 by hulamy ### ########.fr */ +/* Updated: 2019/04/27 02:00:45 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ #include "fillit.h" +/* +** DELETE BEFORE EVAL - TEST FUNCTION +** prints a ligne of size bits +*/ + void print_bits(unsigned int bits, int size) { unsigned int mask; @@ -26,19 +31,24 @@ void print_bits(unsigned int bits, int size) write(1, "\n", 1); } -void print_map(unsigned int *tab, int large, int height) +/* +** DELETE BEFORE EVAL - TEST FUNCTION +** print a map of height and width +*/ + +void print_map(unsigned int *tab, int width, int height) { int i; unsigned int mask; i = 0; mask = 0; - while (i++ < large) + while (i++ < width) mask = (mask >> 1) | ((mask | 1) << 31); i = 0; - while (i < large * height) + while (i < width * height) { - if (!(i % large)) + if (i && !(i % width)) ft_putchar('\n'); tab[i / 32] & (1 << (31 - i % 32)) ? ft_putchar('#') : ft_putchar('.'); ft_putchar(' '); @@ -48,55 +58,88 @@ void print_map(unsigned int *tab, int large, int height) } /* -** Function that transforme a tetrminos char* into a short of 16 bites +** function that transform a tab of . and # into a binary tab of int +*/ + +unsigned short tab_to_bin(char line[]) +{ + unsigned short tmp; + int i; + + i = 0; + tmp = 0; + while (line[i]) + { + tmp <<= 1; + if (line[i] == '\n') + i++; + if (line[i++] == '#') + tmp |= 1; + } + return (tmp); +} + +/* +** function that take a tetrimino of 4*4 and reduce it to its right size, in binary +*/ + +unsigned short reduce_tetri(unsigned short tetri, int width) +{ + unsigned int mask; + unsigned int tmp; + + // cree un mask avec des 1 a gauche sur la largeur du tetriminos + mask = ~0u << (32 - width) >> 16; + // fabrique la ligne pour le tetriminos de la bonne largeur + tmp = tetri; + tmp = (mask & tetri); + tmp |= ((mask & tetri << 4) >> width); + tmp |= ((mask & tetri << 8) >> (2 * width)); + tmp |= ((mask & tetri << 12) >> (3 * width)); + return (tmp); +} + +/* +** Function that transforme a tetriminos char* into a short of 16 bites ** and then fills it and its reversed into the list */ void fill_list(char line[], t_fillist *list) { unsigned int tmp; - unsigned short mask; + unsigned int mask; int i; - i = 0; // transforme la ligne de . et # en un short de 0 et 1 - while (line[i]) - { - list->tetribit <<= 1; - if (line[i] == '\n') - i++; - if (line[i++] == '#') - list->tetribit |= 1; - } - // deplace le tetriminos tout en haut a gauche - while (!(list->tetribit & (1 << 15))) - list->tetribit <<= 1; + list->tetribit = tab_to_bin(line); // cree un mask avec des 1 sur la colonne de droite mask = (1 << 15) | (1 << 11) | (1 << 7) | (1 << 3); // utilise le mask pour trouver la largeur que prend le tetriminos - i = -1; - while (i++ < 4 && mask & list->tetribit) + i = 0; + while (!(mask & list->tetribit) && i++ < 4) mask >>= 1; - list->large = i; - // cree un mask avec des 1 a gauche sur la largeur du tetriminos - mask = ~0; - mask <<= 16 - i; - // fabrique la ligne pour le tetriminos de la bonne largeur - tmp = list->tetribit; - list->tetribit = (mask & tmp) | ((mask & tmp << 4) >> i); - list->tetribit |= ((mask & tmp << 8) >> 2 * i); - list->tetribit |= ((mask & tmp << 12) >> 3 * i); + list->width = i; + while (mask & list->tetribit && ++i < 4) + mask >>= 1; + list->width = i - list->width; + // deplace le tetriminos tout en haut a gauche (i - list->width = le nombre de colonne vide a gauche) + list->tetribit <<= (i - list->width); + while (!(list->tetribit & (~0u << 12))) + list->tetribit <<= 4; // trouve la hauteur du tetri - i = 1; - print_bits(tmp, 32); - while (i && !(tmp & 1 << i)) + i = 0; + while (i < 4 && list->tetribit & (~0u << 28 >> (i * 4 + 16))) i++; - ft_putnbrendl((16 - i) / 4 + ((16 - i) % 4 != 0)); - list->height = ((16 - i) / 4 + ((16 - i) % 4 != 0)); + list->height = i; + // fabrique la ligne pour le tetriminos de la bonne largeur + list->tetribit = reduce_tetri(list->tetribit, list->width); + // imression pour tests + ft_putchar('\n'); tmp = list->tetribit; tmp <<= 16; - print_map(&tmp, list->large, 4); + print_map(&tmp, list->width, list->height); + tmp >>= 16; } /* From 003d2b3cbb018f8905cd27dc0bd5c4b88f70d984 Mon Sep 17 00:00:00 2001 From: Hugo LAMY Date: Sun, 28 Apr 2019 01:09:43 +0200 Subject: [PATCH 09/17] recherche de la position du tetri dans la map fonctionne --- fillit.h | 4 +- parse_input.c | 73 ++++++-------------------------- search_map.c | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++ test_right.c | 37 ++++++++-------- 4 files changed, 149 insertions(+), 80 deletions(-) create mode 100644 search_map.c diff --git a/fillit.h b/fillit.h index ec0b69d..7741e3a 100644 --- a/fillit.h +++ b/fillit.h @@ -6,7 +6,7 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/03/01 13:34:46 by vmanzoni #+# #+# */ -/* Updated: 2019/04/27 00:34:44 by hulamy ### ########.fr */ +/* Updated: 2019/04/27 21:00:53 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -44,5 +44,7 @@ void parse_input(char *input); int check_file_errors(char *file); int check_tetri_errors(char *tetri); int check_tetri_errors_proxy(char *tetri); +void search_map(t_fillist *list); +void print_map(unsigned int *tab, int width, int height); #endif diff --git a/parse_input.c b/parse_input.c index 0f90aa9..97f663b 100644 --- a/parse_input.c +++ b/parse_input.c @@ -6,57 +6,12 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/15 14:48:14 by vmanzoni #+# #+# */ -/* Updated: 2019/04/27 02:00:45 by hulamy ### ########.fr */ +/* Updated: 2019/04/27 22:55:32 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ #include "fillit.h" -/* -** DELETE BEFORE EVAL - TEST FUNCTION -** prints a ligne of size bits -*/ - -void print_bits(unsigned int bits, int size) -{ - unsigned int mask; - - mask = 1 << (size - 1); - while (mask) - { - (bits & mask) ? write(1, "#", 1) : write(1, ".", 1); - write(1, " ", 1); - mask >>= 1; - } - write(1, "\n", 1); -} - -/* -** DELETE BEFORE EVAL - TEST FUNCTION -** print a map of height and width -*/ - -void print_map(unsigned int *tab, int width, int height) -{ - int i; - unsigned int mask; - - i = 0; - mask = 0; - while (i++ < width) - mask = (mask >> 1) | ((mask | 1) << 31); - i = 0; - while (i < width * height) - { - if (i && !(i % width)) - ft_putchar('\n'); - tab[i / 32] & (1 << (31 - i % 32)) ? ft_putchar('#') : ft_putchar('.'); - ft_putchar(' '); - i++; - } - write(1, "\n", 1); -} - /* ** function that transform a tab of . and # into a binary tab of int */ @@ -106,7 +61,7 @@ unsigned short reduce_tetri(unsigned short tetri, int width) void fill_list(char line[], t_fillist *list) { - unsigned int tmp; +// unsigned int tmp; unsigned int mask; int i; @@ -133,13 +88,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); - - // imression pour tests - ft_putchar('\n'); - tmp = list->tetribit; - tmp <<= 16; - print_map(&tmp, list->width, list->height); - tmp >>= 16; } /* @@ -150,15 +98,21 @@ void fill_list(char line[], t_fillist *list) int add_to_list(char *line, t_fillist **list) { t_fillist *tmp; + t_fillist *test; if (!(tmp = (t_fillist*)malloc(sizeof(*tmp)))) return (0); - if (!(*list)) - tmp->next = NULL; + tmp->next = NULL; + test = *list; + if (!test) + *list = tmp; else - tmp->next = *list; - *list = tmp; - fill_list(line, *list); + { + while(test->next) + test = test->next; + test->next = tmp; + } + fill_list(line, tmp); return (1); } @@ -186,5 +140,6 @@ void parse_input(char *input) while (input[i] && input[i] != '.' && input[i] != '#') i++; } + search_map(list); } diff --git a/search_map.c b/search_map.c new file mode 100644 index 0000000..a3d9e96 --- /dev/null +++ b/search_map.c @@ -0,0 +1,115 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* search_map.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/04/27 20:47:22 by hulamy #+# #+# */ +/* Updated: 2019/04/28 01:08:55 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "fillit.h" + +void print_bits(unsigned int bits, int size) +{ + unsigned int mask; + + mask = 1 << (size - 1); + while (mask) + { + (bits & mask) ? write(1, "#", 1) : write(1, ".", 1); + write(1, " ", 1); + mask >>= 1; + } + write(1, "\n", 1); +} + + +/* +** DELETE BEFORE EVAL - TEST FUNCTION +** print a map of height and width +*/ + +void print_map(unsigned int *tab, int width, int height) +{ + int i; + unsigned int mask; + + i = 0; + mask = ~0u << (32 - width); + while (i < width * height) + { + if (i && !(i % width)) + ft_putnbrendl(i); // pour imprimer les tailles du tableaux pour faciliter sa verification + tab[i / 32] & (1 << (31 - i % 32)) ? ft_putchar('#') : ft_putchar('.'); + ft_putchar(' '); + i++; + } + write(1, "\n", 1); +} + +void find_place(unsigned int *tab, t_fillist *list, int size) +{ + int i; + int j; + unsigned int mask; + unsigned int tmp; + + // creer un mask avec les size bits de gauche a 1 (ex: 11111110000000000000000000000000) + mask = ~0u << (32 - list->width); + tmp = mask; + i = 0; + // 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 && (tmp >> 16) & list->tetribit) + { + tmp = 0; + j = list->height * size + i; + while (j >= i) + { + tmp >>= list->width; + tmp |= (mask & (tab[j / 32] << j)); + tmp |= (mask & (tab[(j + size) / 32] >> (32 - j))); + j -= size; + } + // test pour imprimer la "photo de la map" + print_bits(tmp >> 16, 32); + if (i % size == size - list->width) + i += list->width - 1; + i++; + } + // ligne de test pour imprimer la position a laquelle le tetri a trouve une place + ft_putnbrendl(((i - list->width) % size == size - list->width) ? i - list->width : i); +} + +void search_map(t_fillist *list) +{ + unsigned int tmp; + unsigned int tab[8]; + t_fillist *print; + + // ce tableau permet de monter jusqu'a une map de 16*16 + tab[0] = 2656554334; + tab[1] = 1394456818; + tab[2] = 1494256918; + tab[3] = 2656554334; + tab[4] = 1592453883; + tab[5] = 1444352908; + tab[6] = 2154339230; + tab[7] = 1576493154; + print_map(tab, 10, 10); + print = list; + while (print) + { + // imression pour tests + tmp = print->tetribit; + tmp <<= 16; + print_map(&tmp, print->width, print->height); + ft_putchar('\n'); + find_place(tab, print, 10); + print = print->next; + } +// find_place(tab, list, 10); +} + diff --git a/test_right.c b/test_right.c index 88e4183..e2b5198 100644 --- a/test_right.c +++ b/test_right.c @@ -14,21 +14,17 @@ void print_bits(unsigned int bits, int size) write(1, "\n", 1); } -void print_map(unsigned int *tab, int size) +void print_map(unsigned int *tab, int width, int height) { int i; unsigned int mask; - unsigned int tmp; i = 0; - mask = 0; // creer un mask avec les size bits de gauche a 1 (ex: 11111110000000000000000000000000) - while (i++ < size) - mask = (mask >> 1) | ((mask | 1) << 31); - i = 0; - while (i < size * size) + mask = ~0u << (32 - width); + while (i < width * height) { - if (!(i % size)) + if (!(i % width)) ft_putchar('\n'); tab[i / 32] & (1 << (31 - i % 32)) ? ft_putchar('#') : ft_putchar('.'); ft_putchar(' '); @@ -44,13 +40,14 @@ void find_place(unsigned int *tab, char *line, int size) int j; unsigned int mask; unsigned int tmp; - int large; + int width; + int height; -// ft_putendl("# . . # # # # T T # . # . # # # # # . . # # . # T # . # # # # . . # . # . . # # T . . # # # . # # . # # # . . . # # # # . . # . . # . # # . . # . . . # . . . . # . . . # # . # . . . # . # # ."); /////////////// create tetri /////////////// i = 0; tmp = 0; - large = 3; + width = 3; + height = 2; while (line[i]) { tetri <<= 1; @@ -63,31 +60,31 @@ void find_place(unsigned int *tab, char *line, int size) tetri <<= 1; print_bits(tetri, 16); tmp = (tetri | tmp) << 16; - print_map(&tmp, large); + print_map(&tmp, width, height); /////////////// create tetri /////////////// mask = ~0; - mask <<= 32 - large; + mask <<= 32 - width; ft_putendl("mask: "); print_bits(mask, 32); i = 0; - while (i < 20) + while (i < (size - height + 1) * size) { tmp = 0; - j = 3 * size + i; + j = height * size + i; while (j >= i) { - tmp >>= large; + tmp >>= width; tmp |= (mask & (tab[j / 32] << j)); tmp |= (mask & (tab[(j + size) / 32] >> (32 - j))); j -= size; } - print_map(&tmp, large); + print_map(&tmp, width, height); print_bits(tmp >> 16, 32); print_bits(tetri, 32); print_bits((tmp >> 16) & tetri, 32); - if (i % size == size - large) - i += large - 1; + if (i % size == size - width) + i += width - 1; i++; } } @@ -119,7 +116,7 @@ int main(int ac, char **av) // mettre l'option "b" pour afficher la troisieme argument en binaire if (av[0][0] == 'b' && ac > 2) ft_putendl(ft_convertbase(av[1], "01", "0123456789")); - print_map(tab, 10); + print_map(tab, 10, 10); write(1, "\n", 1); if (av[0][0] == 't' && ac > 2) find_place(tab, av[1], 10); From 1dd8a9e8c845feda4c7315906f11d249c311d3ef Mon Sep 17 00:00:00 2001 From: Hugo LAMY Date: Sun, 28 Apr 2019 02:24:27 +0200 Subject: [PATCH 10/17] find_place renvois la position du tetri dans la map --- search_map.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/search_map.c b/search_map.c index a3d9e96..4312431 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/04/28 01:08:55 by hulamy ### ########.fr */ +/* Updated: 2019/04/28 01:44:50 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -50,7 +50,7 @@ void print_map(unsigned int *tab, int width, int height) write(1, "\n", 1); } -void find_place(unsigned int *tab, t_fillist *list, int size) +int find_place(unsigned int *tab, t_fillist *list, int size) { int i; int j; @@ -62,7 +62,7 @@ void find_place(unsigned int *tab, t_fillist *list, int size) tmp = mask; i = 0; // 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 && (tmp >> 16) & list->tetribit) + while (i < (size - list->height + 1) * size) { tmp = 0; j = list->height * size + i; @@ -73,14 +73,14 @@ void find_place(unsigned int *tab, t_fillist *list, int size) tmp |= (mask & (tab[(j + size) / 32] >> (32 - j))); j -= size; } - // test pour imprimer la "photo de la map" - print_bits(tmp >> 16, 32); +// print_bits(tmp >> 16, 32); // test pour imprimer la "photo de la map" + if (!((tmp >> 16) & list->tetribit)) + return (i + 1); if (i % size == size - list->width) i += list->width - 1; i++; } - // ligne de test pour imprimer la position a laquelle le tetri a trouve une place - ft_putnbrendl(((i - list->width) % size == size - list->width) ? i - list->width : i); + return (0); } void search_map(t_fillist *list) @@ -106,8 +106,8 @@ void search_map(t_fillist *list) tmp = print->tetribit; tmp <<= 16; print_map(&tmp, print->width, print->height); + ft_putnbrendl(find_place(tab, print, 10)); ft_putchar('\n'); - find_place(tab, print, 10); print = print->next; } // find_place(tab, list, 10); From 656973ae524ce3a86de82d369e04a56157abb662 Mon Sep 17 00:00:00 2001 From: Hugo LAMY Date: Sun, 28 Apr 2019 16:24:09 +0200 Subject: [PATCH 11/17] ebut implementation de la recursive --- .parse_input.c.swn | Bin 0 -> 16384 bytes parse_input.c | 2 +- search_map.c | 78 +++++++++++++++++++++++++++++++++++++-------- 3 files changed, 65 insertions(+), 15 deletions(-) create mode 100644 .parse_input.c.swn diff --git a/.parse_input.c.swn b/.parse_input.c.swn new file mode 100644 index 0000000000000000000000000000000000000000..0464e426fba93f899daf8fb6c4561971c745dd64 GIT binary patch literal 16384 zcmeI3UyLM09mfk$VSqbSo-{;jcg*hmxt*Dwo%=VpyAX}1r$7vPK6tmTJ>4}obvx5N zc31DQEFM0HBxr*1&BRE2@j;9v0zMdxB>syJ#;6HVc_Sf2UraC&P#^sMs=9jq?A>Jp z_kce*F%#5&Qx? z4;}#_@WB^=2b$mm;C65uco7RRzXLx3Pk|@FH^AfIF_3~ya0Z+PO|S?!_#n6oyZ~SS z3H%W}3w{K?2`+;K^nn1I;FI9vfX2rLnA=LFi+r88PO;J+D_t7Mq2Lw$5yv^XS!E?@ zGI0>85^Wbz(jH432LnH$bR|?G&$U~dNK2KkWWbgAG$d7}+EAtnmhL}$@4ctk9@~j! zSep7^q(WABP1jq6Yn!ZAjl=0!4L3no`l$7BxzrTR}0L zR4L@FRY(4C7zdS9J|yCPrG^4kYz!7Bl2ct&$5aaSXpd>{`C+)FVxxl*KUc#R=QZ8R z!W+4)MsYb3JQ5-l;eJO2iSSW3ye6i7p?!v0;h{)e;;Blq0A3N+N92)}4eiUGB#{yk zW`Wq!DR9+v?h)R0Gnf+2nn{m&h+>sFQ}kg-Gx*K2qWsEXDXpd8o5{afIxl zpIi`G!b-;WK*$RNs#n5ZN!IJw+3CR7c!w`7<+T=VT;i3>t&Fd&@%9P6v4MHRYbaRf z-ZAoqojcSzmBiVOu6*EU3f1y3GYvy!vz>#zb>5lOzA)E$KB?Ag>w2zmKAN&}1(8BA z9{K^=F{6r#X(~mWng;h=@UsBEn>PVza9R|PdWj$*gLtTQ+>!WU&qA+FYqV=f&DnO4 zwj)2?hFt61n{-mA?H727*Xxqh-*5M7mKG{kv{fbl!K=BkJgkvxG9}Sut%*KU4;$kz z3?B?8Gfp^-t#Kj{d1lmOrazdU9*qR=Xq7)~kG;w9@yX$8K4LLZ1kWO_YxQ?T098}& z@sx(GU+4>U!z7jpk!8-&2ugmBW^qqOI+*2#RpLi!KTa@7i^%{h4K5TflcP~-I*1cR zZfsGihtQD+bsGLzl+p|e5m1%x-YM2>&Zg?vmIv}lMAeam0?D~e1lCC?p@tWcgn~DM zLqwr`m~u>ZN|7qXl;08fh)~xX=K%y!eBZTTs)PRY^rq@-)aV!k()2LyV>WU`6p`9U zW3L7jHPKm$t`Ea~cHHRctzFr!>RG*tS#2WCHH)7xrP~K9-O;6s07i{K8}gy6n_w%W zOAjusXz5#ua@zDd&jVIvwT+2ss;5qR$Bg}}jY&Jd?clVN!bUN={H7R0Gb2Zjk=Z0_ z1zm%Ra@tF{=uO4?**w$xBjnY*z4rc~KXZSe{A~(DS}T1s0MB=79X+;;c^YXL8G4}U zSWlNvGK}F7`N{58#s}RP*g--OOJ9`r7)LnSBvxx9?{WG@<1`6l;#q_fGz6xzwg zUU6+PhUiYq3<0_ko4@BG-_MFdg|8svR5+NLiN(a56U;^lQqAvi=+)3_mF)~Nve-;G zKr2+1Q83I9ITmUDO4S%F;wH6*`-SVZaoqpG;C0-r!L#EK_aozUS%V+ZH#<`Xy`$XgbUP=yUWW|sjQr@KIFb{S zl_@x3uQPaCOst)(fO z*5IV<0guSq#3I_6Tek+Mo&y@e!EAQxT~jbWFgt7TU^eDTb-UIij%Y*vTQWFjU;i`) zuh%@mbrA;X`Tqxau74fS^FJQh_4bcD@Qet44!#3o@Bnxpcn>%X{)2Pg$j^O^&Uc$r zz$xGqa0)mDoB~b(r+`zyDc}@v3OEJcZVF&wE){+f47Nu8SidBpB~!gzXI|eF?{Db; zq~mp_eg$BU7qD*ESl*Xpmhz_Gj_DP}BYa7(VWWalX`Em!Y)d3boKzM+O1m!q46V`X zb;l@He8(Tku(3$((aV8&pAu}FS6Sw~6z>jk0=*@|OF?>b>Yc=DAzwb +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/15 14:48:14 by vmanzoni #+# #+# */ -/* Updated: 2019/04/27 22:55:32 by hulamy ### ########.fr */ +/* Updated: 2019/04/28 16:12:31 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/search_map.c b/search_map.c index 4312431..5eaf17b 100644 --- a/search_map.c +++ b/search_map.c @@ -6,12 +6,17 @@ /* By: hulamy +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/27 20:47:22 by hulamy #+# #+# */ -/* Updated: 2019/04/28 01:44:50 by hulamy ### ########.fr */ +/* Updated: 2019/04/28 16:23:19 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ #include "fillit.h" +/* +** DELETE BEFORE EVAL - TEST FUNCTION +** print a int in binary +*/ + void print_bits(unsigned int bits, int size) { unsigned int mask; @@ -26,7 +31,6 @@ void print_bits(unsigned int bits, int size) write(1, "\n", 1); } - /* ** DELETE BEFORE EVAL - TEST FUNCTION ** print a map of height and width @@ -66,6 +70,7 @@ int find_place(unsigned int *tab, t_fillist *list, int size) { tmp = 0; j = list->height * size + i; + // construit un tmp qui est une photo de la map de la taille du tetri a un emplacement donne while (j >= i) { tmp >>= list->width; @@ -75,7 +80,7 @@ int find_place(unsigned int *tab, t_fillist *list, int size) } // print_bits(tmp >> 16, 32); // test pour imprimer la "photo de la map" if (!((tmp >> 16) & list->tetribit)) - return (i + 1); + return ((list->position = i + 1)); if (i % size == size - list->width) i += list->width - 1; i++; @@ -83,13 +88,31 @@ int find_place(unsigned int *tab, t_fillist *list, int size) return (0); } +/* +int fill_map(unsigned int map, t_fillist *list, int size) +{ + if (!list) + return (1); + while (find_place(tab, list, size)) + { + add_to_map(map, list); // to create + if (fill_map(map, size, list->next) + return (1); + remove_from_map(map, list); // to create + list->position++; + } + return (0); +} +*/ + void search_map(t_fillist *list) { - unsigned int tmp; - unsigned int tab[8]; - t_fillist *print; + t_fillist *tmp; + //////////////////////////// TEST //////////////////////////// // ce tableau permet de monter jusqu'a une map de 16*16 + unsigned int print; + unsigned int tab[8]; tab[0] = 2656554334; tab[1] = 1394456818; tab[2] = 1494256918; @@ -99,17 +122,44 @@ void search_map(t_fillist *list) tab[6] = 2154339230; tab[7] = 1576493154; print_map(tab, 10, 10); - print = list; - while (print) + tmp = list; + while (tmp) { // imression pour tests - tmp = print->tetribit; - tmp <<= 16; - print_map(&tmp, print->width, print->height); - ft_putnbrendl(find_place(tab, print, 10)); + print = tmp->tetribit; + print <<= 16; + print_map(&print, tmp->width, tmp->height); + ft_putnbrendl(find_place(tab, tmp, 10)); ft_putchar('\n'); - print = print->next; + tmp = tmp->next; } -// find_place(tab, list, 10); + //////////////////////////// TEST //////////////////////////// + + /* + //////////////////////////// en cours //////////////////////////// + unsigned int *map; + int size; + int i; + + size = 2; + i = 1; + tmp = list; + // trouve le nombre de tetri en parcourant la liste chainee + while ((tmp = tmp->next)) + i++; + // trouve la taille minimale de la map + while (size * size < i * 4) + size++; + // alloue une map de la taille du nombre d'int necesaire pour contenir la taille de la map (size * size) + map = (unsigned int *)malloc(sizeof(*map) * ((size * size) / 32 + 1)); + // lance la recursive fill_map en augmentant la taille de la map tant qu'il n'y a pas de solution + while (!fill_map(map, list, size)) + { + size++; + free(map); + map = (unsigned int *)malloc(sizeof(*map) * ((size * size) / 32 + 1)); + } + //////////////////////////// en cours //////////////////////////// + */ } From 817528c9430fb02e9cff9a23ec361c53fc94622a Mon Sep 17 00:00:00 2001 From: Hugo LAMY Date: Sun, 28 Apr 2019 16:49:17 +0200 Subject: [PATCH 12/17] makefile delete tous les fichiers .o et .swp et du genre --- .parse_input.c.swn | Bin 16384 -> 0 bytes Makefile | 13 ++++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) delete mode 100644 .parse_input.c.swn diff --git a/.parse_input.c.swn b/.parse_input.c.swn deleted file mode 100644 index 0464e426fba93f899daf8fb6c4561971c745dd64..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 16384 zcmeI3UyLM09mfk$VSqbSo-{;jcg*hmxt*Dwo%=VpyAX}1r$7vPK6tmTJ>4}obvx5N zc31DQEFM0HBxr*1&BRE2@j;9v0zMdxB>syJ#;6HVc_Sf2UraC&P#^sMs=9jq?A>Jp z_kce*F%#5&Qx? z4;}#_@WB^=2b$mm;C65uco7RRzXLx3Pk|@FH^AfIF_3~ya0Z+PO|S?!_#n6oyZ~SS z3H%W}3w{K?2`+;K^nn1I;FI9vfX2rLnA=LFi+r88PO;J+D_t7Mq2Lw$5yv^XS!E?@ zGI0>85^Wbz(jH432LnH$bR|?G&$U~dNK2KkWWbgAG$d7}+EAtnmhL}$@4ctk9@~j! zSep7^q(WABP1jq6Yn!ZAjl=0!4L3no`l$7BxzrTR}0L zR4L@FRY(4C7zdS9J|yCPrG^4kYz!7Bl2ct&$5aaSXpd>{`C+)FVxxl*KUc#R=QZ8R z!W+4)MsYb3JQ5-l;eJO2iSSW3ye6i7p?!v0;h{)e;;Blq0A3N+N92)}4eiUGB#{yk zW`Wq!DR9+v?h)R0Gnf+2nn{m&h+>sFQ}kg-Gx*K2qWsEXDXpd8o5{afIxl zpIi`G!b-;WK*$RNs#n5ZN!IJw+3CR7c!w`7<+T=VT;i3>t&Fd&@%9P6v4MHRYbaRf z-ZAoqojcSzmBiVOu6*EU3f1y3GYvy!vz>#zb>5lOzA)E$KB?Ag>w2zmKAN&}1(8BA z9{K^=F{6r#X(~mWng;h=@UsBEn>PVza9R|PdWj$*gLtTQ+>!WU&qA+FYqV=f&DnO4 zwj)2?hFt61n{-mA?H727*Xxqh-*5M7mKG{kv{fbl!K=BkJgkvxG9}Sut%*KU4;$kz z3?B?8Gfp^-t#Kj{d1lmOrazdU9*qR=Xq7)~kG;w9@yX$8K4LLZ1kWO_YxQ?T098}& z@sx(GU+4>U!z7jpk!8-&2ugmBW^qqOI+*2#RpLi!KTa@7i^%{h4K5TflcP~-I*1cR zZfsGihtQD+bsGLzl+p|e5m1%x-YM2>&Zg?vmIv}lMAeam0?D~e1lCC?p@tWcgn~DM zLqwr`m~u>ZN|7qXl;08fh)~xX=K%y!eBZTTs)PRY^rq@-)aV!k()2LyV>WU`6p`9U zW3L7jHPKm$t`Ea~cHHRctzFr!>RG*tS#2WCHH)7xrP~K9-O;6s07i{K8}gy6n_w%W zOAjusXz5#ua@zDd&jVIvwT+2ss;5qR$Bg}}jY&Jd?clVN!bUN={H7R0Gb2Zjk=Z0_ z1zm%Ra@tF{=uO4?**w$xBjnY*z4rc~KXZSe{A~(DS}T1s0MB=79X+;;c^YXL8G4}U zSWlNvGK}F7`N{58#s}RP*g--OOJ9`r7)LnSBvxx9?{WG@<1`6l;#q_fGz6xzwg zUU6+PhUiYq3<0_ko4@BG-_MFdg|8svR5+NLiN(a56U;^lQqAvi=+)3_mF)~Nve-;G zKr2+1Q83I9ITmUDO4S%F;wH6*`-SVZaoqpG;C0-r!L#EK_aozUS%V+ZH#<`Xy`$XgbUP=yUWW|sjQr@KIFb{S zl_@x3uQPaCOst)(fO z*5IV<0guSq#3I_6Tek+Mo&y@e!EAQxT~jbWFgt7TU^eDTb-UIij%Y*vTQWFjU;i`) zuh%@mbrA;X`Tqxau74fS^FJQh_4bcD@Qet44!#3o@Bnxpcn>%X{)2Pg$j^O^&Uc$r zz$xGqa0)mDoB~b(r+`zyDc}@v3OEJcZVF&wE){+f47Nu8SidBpB~!gzXI|eF?{Db; zq~mp_eg$BU7qD*ESl*Xpmhz_Gj_DP}BYa7(VWWalX`Em!Y)d3boKzM+O1m!q46V`X zb;l@He8(Tku(3$((aV8&pAu}FS6Sw~6z>jk0=*@|OF?>b>Yc=DAzwb +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2019/03/01 13:24:35 by vmanzoni #+# #+# # -# Updated: 2019/04/24 15:44:55 by hulamy ### ########.fr # +# Updated: 2019/04/28 16:48:38 by hulamy ### ########.fr # # # # **************************************************************************** # @@ -25,6 +25,11 @@ LDLIBS = -lft SRCS = $(shell find . -depth 1 -type f -not -name '.*' -not -name 'test*' -name '*.c') +TRASH = $(shell find . -depth 1 -type f -name '*.dSYM') +TRASH += $(shell find . -depth 1 -type f -name '*.o') +TRASH += $(shell find . -depth 1 -type f -name '*.swp') +TRASH += $(shell find . -depth 1 -type f -name '*.swo') +TRASH += $(shell find . -depth 1 -type f -name '*.swn') # - - - - - - - - - - - - - - - # # RULES # @@ -35,14 +40,16 @@ all: $(NAME) $(NAME): $(SRCS) $(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) $(SRCS) -o $(NAME) -debug: +debug: $(SRCS) $(CC) -g $(CFLAGS) $(LDFLAGS) $(LDLIBS) $(SRCS) -o $(NAME) lib: make -C ./libft/ clean: + /bin/rm -rf $(TRASH) + +fclean: clean /bin/rm -rf $(NAME) - /bin/rm -rf $(NAME).dSYM re: clean all From 8967fcb4645712313adc2074e31413d8fd0640e4 Mon Sep 17 00:00:00 2001 From: Hugo LAMY Date: Tue, 30 Apr 2019 12:50:20 +0200 Subject: [PATCH 13/17] some changes to search map --- search_map.c | 98 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 70 insertions(+), 28 deletions(-) diff --git a/search_map.c b/search_map.c index 5eaf17b..7b5beda 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/04/28 16:23:19 by hulamy ### ########.fr */ +/* Updated: 2019/04/30 12:50:06 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -54,6 +54,10 @@ void print_map(unsigned int *tab, int width, int height) write(1, "\n", 1); } +/* +** 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 i; @@ -75,10 +79,12 @@ int find_place(unsigned int *tab, t_fillist *list, int size) { tmp >>= list->width; tmp |= (mask & (tab[j / 32] << j)); - tmp |= (mask & (tab[(j + size) / 32] >> (32 - j))); + tmp |= (mask & (tab[(j + size) / 32] >> (32 - j))); // cette deuxieme ligne est la au cas ou on serait a cheval sur deux int du tab j -= size; } -// print_bits(tmp >> 16, 32); // test pour imprimer la "photo de la map" +// print_map(&tmp, list->width, list->height); // test pour imprimer la photo en map +// write(1, "\n", 1); +// print_bits(tmp >> 16, 32); // test pour imprimer la photo en bits if (!((tmp >> 16) & list->tetribit)) return ((list->position = i + 1)); if (i % size == size - list->width) @@ -89,20 +95,60 @@ int find_place(unsigned int *tab, t_fillist *list, int size) } /* -int fill_map(unsigned int map, t_fillist *list, int size) +** function that add or remove a tetri on the map +*/ + +//void add_remove(unsigned int *map, t_fillist *list) +//{ +// unsigned int mask; +// unsigned int tmp; +// int i; +// +// mask = ~0u << (32 - list->width); +// tmp = 0; +// /* +// * trouver comment faire ;) +// */ +//} + +/* +** function that recursively try to fill the map with the tetris +*/ + +//int fill_map(unsigned int *map, t_fillist *list, int size) +//{ +// if (!list) +// return (1); +// while (find_place(map, list, size)) +// { +// add_remove(map, list, size); +// print_map(map, size, size); +// if (fill_map(map, size, list->next) +// return (1); +// add_remove(map, list, size); +// list->position++; +// } +// return (0); +//} + +/* +** function that init the map to the right size fill with int equal to zeros +*/ + +unsigned int *init_map(int i) { - if (!list) - return (1); - while (find_place(tab, list, size)) - { - add_to_map(map, list); // to create - if (fill_map(map, size, list->next) - return (1); - remove_from_map(map, list); // to create - list->position++; - } - return (0); + unsigned int *new; + int size; + + size = (i * i) / 32 + 1; + new = (unsigned int *)malloc(sizeof(*new) * size); + while (size) + new[size--] = 0; + return (new); } + +/* +** function that send to "fill_map" a map of a certain size and increment its size untill it's solved */ void search_map(t_fillist *list) @@ -128,15 +174,15 @@ void search_map(t_fillist *list) // imression pour tests print = tmp->tetribit; print <<= 16; - print_map(&print, tmp->width, tmp->height); +// print_map(&print, tmp->width, tmp->height); // test, imprime le tetri +// ft_putchar('\n'); ft_putnbrendl(find_place(tab, tmp, 10)); ft_putchar('\n'); tmp = tmp->next; } //////////////////////////// TEST //////////////////////////// - /* - //////////////////////////// en cours //////////////////////////// + ////////////////////////// en cours ////////////////////////// unsigned int *map; int size; int i; @@ -150,16 +196,12 @@ void search_map(t_fillist *list) // trouve la taille minimale de la map while (size * size < i * 4) size++; - // alloue une map de la taille du nombre d'int necesaire pour contenir la taille de la map (size * size) - map = (unsigned int *)malloc(sizeof(*map) * ((size * size) / 32 + 1)); + 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 - while (!fill_map(map, list, size)) - { - size++; - free(map); - map = (unsigned int *)malloc(sizeof(*map) * ((size * size) / 32 + 1)); - } - //////////////////////////// en cours //////////////////////////// - */ +// ft_putstr("test "); +// ft_putnbrendl(size); +// while (!fill_map(map, list, size)) +// map = init_map(size++); + ////////////////////////// en cours ////////////////////////// } From 0eef1b4825449f47f6e2fdd0989c01b95e12f82f Mon Sep 17 00:00:00 2001 From: Hugo LAMY Date: Tue, 30 Apr 2019 13:20:36 +0200 Subject: [PATCH 14/17] libft en symlink --- libft | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 160000 => 120000 libft diff --git a/libft b/libft deleted file mode 160000 index dad20d5..0000000 --- a/libft +++ /dev/null @@ -1 +0,0 @@ -Subproject commit dad20d5d96b1865b150de700861cfc63630dffa1 diff --git a/libft b/libft new file mode 120000 index 0000000..7d1e3da --- /dev/null +++ b/libft @@ -0,0 +1 @@ +../03_libft \ No newline at end of file From c7f7ac205c2cf38a93123fb52fe6e52ecf6ec6a8 Mon Sep 17 00:00:00 2001 From: Hugo LAMY Date: Tue, 30 Apr 2019 13:26:10 +0200 Subject: [PATCH 15/17] ajout du fichier print qui contient les fonctinos de print de bits --- fillit.h | 3 ++- parse_input.c | 2 +- print.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++ search_map.c | 44 +------------------------------------- 4 files changed, 63 insertions(+), 45 deletions(-) create mode 100644 print.c diff --git a/fillit.h b/fillit.h index 7741e3a..0cad1c2 100644 --- a/fillit.h +++ b/fillit.h @@ -6,7 +6,7 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/03/01 13:34:46 by vmanzoni #+# #+# */ -/* Updated: 2019/04/27 21:00:53 by hulamy ### ########.fr */ +/* Updated: 2019/04/30 13:25:06 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -46,5 +46,6 @@ int check_tetri_errors(char *tetri); int check_tetri_errors_proxy(char *tetri); void search_map(t_fillist *list); void print_map(unsigned int *tab, int width, int height); +void print_bits(unsigned int bits, int size); #endif diff --git a/parse_input.c b/parse_input.c index 051e4ba..7a47d6b 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/04/28 16:12:31 by hulamy ### ########.fr */ +/* Updated: 2019/04/30 13:24:40 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/print.c b/print.c new file mode 100644 index 0000000..5e3256e --- /dev/null +++ b/print.c @@ -0,0 +1,59 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* print.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/04/30 13:24:28 by hulamy #+# #+# */ +/* Updated: 2019/04/30 13:25:18 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "fillit.h" + +/* +** DELETE BEFORE EVAL - TEST FUNCTION +** Prints a ligne of size bits +*/ + +void print_bits(unsigned int bits, int size) +{ + unsigned int mask; + + mask = 1 << (size - 1); + while (mask) + { + (bits & mask) ? write(1, "#", 1) : write(1, ".", 1); + write(1, " ", 1); + mask >>= 1; + } + write(1, "\n", 1); +} + +/* +** DELETE BEFORE EVAL - TEST FUNCTION +** Print a map of height and width +*/ + +void print_map(unsigned int *tab, int width, int height) +{ + int i; + unsigned int mask; + + i = 0; + mask = 0; + while (i++ < width) + mask = (mask >> 1) | ((mask | 1) << 31); + i = 0; + while (i < width * height) + { + if (i && !(i % width)) + ft_putchar('\n'); + tab[i / 32] & (1 << (31 - i % 32)) ? ft_putchar('#') : ft_putchar('.'); + ft_putchar(' '); + i++; + } + write(1, "\n", 1); +} + diff --git a/search_map.c b/search_map.c index 7b5beda..afe5908 100644 --- a/search_map.c +++ b/search_map.c @@ -6,54 +6,12 @@ /* By: hulamy +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/27 20:47:22 by hulamy #+# #+# */ -/* Updated: 2019/04/30 12:50:06 by hulamy ### ########.fr */ +/* Updated: 2019/04/30 13:25:42 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ #include "fillit.h" -/* -** DELETE BEFORE EVAL - TEST FUNCTION -** print a int in binary -*/ - -void print_bits(unsigned int bits, int size) -{ - unsigned int mask; - - mask = 1 << (size - 1); - while (mask) - { - (bits & mask) ? write(1, "#", 1) : write(1, ".", 1); - write(1, " ", 1); - mask >>= 1; - } - write(1, "\n", 1); -} - -/* -** DELETE BEFORE EVAL - TEST FUNCTION -** print a map of height and width -*/ - -void print_map(unsigned int *tab, int width, int height) -{ - int i; - unsigned int mask; - - i = 0; - mask = ~0u << (32 - width); - while (i < width * height) - { - if (i && !(i % width)) - ft_putnbrendl(i); // pour imprimer les tailles du tableaux pour faciliter sa verification - tab[i / 32] & (1 << (31 - i % 32)) ? ft_putchar('#') : ft_putchar('.'); - ft_putchar(' '); - i++; - } - write(1, "\n", 1); -} - /* ** function that look for the first place in the map for a tetri */ From ed1cde6e22cc4af344781b9ed67864ae2a382c41 Mon Sep 17 00:00:00 2001 From: Hugo LAMY Date: Tue, 30 Apr 2019 13:32:27 +0200 Subject: [PATCH 16/17] modified test_right in test_big_tetri --- test_right.c => test_big_tetri.c | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test_right.c => test_big_tetri.c (100%) diff --git a/test_right.c b/test_big_tetri.c similarity index 100% rename from test_right.c rename to test_big_tetri.c From 2363e42167284a870061d69334d121cb66096629 Mon Sep 17 00:00:00 2001 From: Hugo LAMY Date: Tue, 30 Apr 2019 14:08:30 +0200 Subject: [PATCH 17/17] test add_remove qui ne fonctionne pas encore --- search_map.c | 69 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 41 insertions(+), 28 deletions(-) diff --git a/search_map.c b/search_map.c index afe5908..0effc76 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/04/30 13:25:42 by hulamy ### ########.fr */ +/* Updated: 2019/04/30 14:07:47 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -56,38 +56,45 @@ int find_place(unsigned int *tab, t_fillist *list, int size) ** function that add or remove a tetri on the map */ -//void add_remove(unsigned int *map, t_fillist *list) -//{ -// unsigned int mask; -// unsigned int tmp; -// int i; -// -// mask = ~0u << (32 - list->width); -// tmp = 0; -// /* -// * trouver comment faire ;) -// */ -//} +void add_remove(unsigned int *map, t_fillist *list, int size, int pos) +{ + unsigned int mask; + unsigned int tmp; + int j; + + mask = ~0u << (32 - list->width); + tmp = 0; + j = list->height * size + pos; +// (void)map; + // construit un tmp qui est une photo de la map de la taille du tetri a un emplacement donne +// ft_putnbrendl(pos); + while (j >= pos) + { + map[j / 32] |= ((mask >> (32 - j)) ^ map[j / 32]); + map[(j + size) / 32] |= ((mask << j) ^ map[(j + size) / 32]); // cette deuxieme ligne est la au cas ou on serait a cheval sur deux int du tab + j -= size; + } +} /* ** function that recursively try to fill the map with the tetris */ -//int fill_map(unsigned int *map, t_fillist *list, int size) -//{ -// if (!list) -// return (1); -// while (find_place(map, list, size)) -// { -// add_remove(map, list, size); -// print_map(map, size, size); -// if (fill_map(map, size, list->next) -// return (1); -// add_remove(map, list, size); -// list->position++; -// } -// return (0); -//} +int fill_map(unsigned int *map, t_fillist *list, int size) +{ + if (!list) + return (1); + while (find_place(map, list, size)) + { + add_remove(map, list, size, list->position); + print_map(map, size, size); + if (fill_map(map, list->next, size)) + return (1); + add_remove(map, list, size, list->position); + list->position++; + } + return (0); +} /* ** function that init the map to the right size fill with int equal to zeros @@ -155,6 +162,12 @@ void search_map(t_fillist *list) while (size * size < i * 4) size++; map = init_map(size); + + // en cours de test : + // quand add_remove_marchera la ligne d'apres imprimera la map avec les pixels du tetri rajoutes a la bonne place + add_remove(tab, list, 10, find_place(tab, list, 10)); + print_map(tab, 10, 10); + // lance la recursive fill_map en augmentant la taille de la map tant qu'il n'y a pas de solution // ft_putstr("test "); // ft_putnbrendl(size);