From 7d0dab1e1edb5f16b6b56443121a16f38f733bb3 Mon Sep 17 00:00:00 2001 From: Manzovince Date: Fri, 3 May 2019 18:44:51 +0200 Subject: [PATCH] Auto stash before merge of "master" and "origin/master" --- search_map.c | 3 +- test_othermethod_fillit.c | 78 ++++++++++++++++++++++++++++++++++----- 2 files changed, 70 insertions(+), 11 deletions(-) diff --git a/search_map.c b/search_map.c index 0eac674..cd2de01 100644 --- a/search_map.c +++ b/search_map.c @@ -3,7 +3,7 @@ /* ::: :::::::: */ /* search_map.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: hulamy +#+ +:+ +#+ */ +/* By: hulamy +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/27 20:47:22 by hulamy #+# #+# */ /* Updated: 2019/05/03 16:05:23 by hulamy ### ########.fr */ @@ -142,4 +142,3 @@ void search_map(t_fillist *list) ft_putchar('\n'); // DEBUG print_map(map, size, size, '#'); } - diff --git a/test_othermethod_fillit.c b/test_othermethod_fillit.c index 2da7a80..22cc411 100644 --- a/test_othermethod_fillit.c +++ b/test_othermethod_fillit.c @@ -6,11 +6,12 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/05/01 15:25:46 by vmanzoni #+# #+# */ -/* Updated: 2019/05/01 20:07:41 by vmanzoni ### ########.fr */ +/* Updated: 2019/05/02 17:08:26 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft/includes/libft.h" +#include typedef struct s_fillist { @@ -67,7 +68,7 @@ void error(char *str) char *read_file(char *file) { - char buf[130]; + char buf[1000]; int fd; int rv; int i; @@ -128,7 +129,7 @@ unsigned int tetri_to_binary(char line[]) { unsigned int tmp; int i; - unsigned int mask; +// unsigned int mask; i = 0; tmp = 0; @@ -140,11 +141,11 @@ unsigned int tetri_to_binary(char line[]) if (line[i++] == '#') tmp |= 1; } - mask = (1 << 3 | 1 << 2 | 1 << 1) + 1; +// mask = (1 << 3 | 1 << 2 | 1 << 1) + 1; // while ((tmp & mask) < 8) //place le tetri le plus en bas a droite possible sans le casser // tmp /= 2; - print_bits("before\n", tmp, 32); - print_bits("after\n", tetribit_resize(tmp, 4, 5), 32); +// print_bits("before\n", tmp, 32); +// print_bits("after\n", tetribit_resize(tmp, 4, 5), 32); return (tmp); } @@ -169,9 +170,65 @@ int add_to_list(char *line, t_fillist **list) return (1); } -void parse_file(char *file) +unsigned int *init_map(int i) +{ + unsigned int *new; + int size; + + size = (i * i) / 32 + 1; + new = (unsigned int *)malloc(sizeof(*new) * size); + while (size) + new[size--] = 0; + return (new); +} + +int find_place(unsigned int *map, t_fillist *list) +{ + ft_putstr(">>>\n"); + print_bits("map: ", *map, 32); + print_bits("lst: ", list->tetribit, 32); + print_bits("m&l: ", (*map & (short)(list->tetribit)), 32); + while ((*map & (int)(list->tetribit)) == 0 + && ((int)(list->tetribit) & (1 << 31))) + { + list->tetribit = list->tetribit << 1; + print_bits("lst: ", list->tetribit, 32); + ft_putnbr(list->tetribit); + } + return (0); +} + +int backtracking(t_fillist *list) +{ + unsigned int *map; + + map = init_map(1); + if (!list) + return (0); +// while (list) +// { +// print_bits("test: ", list->tetribit, 16); +// list = list->next; +// } + find_place(map, list); +// list = list->next; +// find_place(map, list); + /* + while (find_place(map, list)) + { + add_remove(map, list, size, list->position); + if (fill_map(map, list->next)) + return (1); + add_remove(map, list, size, list->position); + list->position++; + } + */ + return (0); +// mask = (mask >> 1) | (((1 << (i % 32)) & map[j]) << (31 - (i % 32))); +} + +void parse_file(char *file, t_fillist *list) { - static t_fillist *list = NULL; char tetri[20]; int i; int j; @@ -189,11 +246,14 @@ void parse_file(char *file) while (file[i] && file[i] != '.' && file[i] != '#') i++; } + backtracking(list); } int solve(char *file) { - parse_file(read_file(file)); + static t_fillist *list = NULL; + + parse_file(read_file(file), list); return (1); }