diff --git a/Makefile b/Makefile index 05e55b2..16a7a94 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: gtertysh +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2016/12/14 16:54:48 by gtertysh #+# #+# # -# Updated: 2016/12/20 20:37:58 by gtertysh ### ########.fr # +# Updated: 2016/12/22 18:18:36 by gtertysh ### ########.fr # # # # **************************************************************************** # @@ -45,7 +45,7 @@ LIBFLAGS = -lft -L $(LIBFOLDER) LIBFOLDER = ./libft/ -FLAGS = -Werror -Wextra -Wall +FLAGS = -Werror -Wextra -Wall -O2 CC = clang diff --git a/inc/fillit.h b/inc/fillit.h index 273b06d..c4a5a5b 100644 --- a/inc/fillit.h +++ b/inc/fillit.h @@ -97,9 +97,9 @@ void add_row(int *col_numbers, t_node **cols_arr, t_coord coord, int void search(t_node* root, t_node **solution, int k, int amount); -void cover(t_node *to_cover); +int cover(t_node *to_cover); -void uncover(t_node *to_uncover); +int uncover(t_node *to_uncover); int *get_types(char **ttr); @@ -109,4 +109,6 @@ unsigned int ft_sqrt_ceil(unsigned int num); void fill_map(char *map, int size, t_node *ttr, int letter); +void init(char **argv); + #endif diff --git a/src/dancing_links.c b/src/dancing_links.c index f2609fd..977a2dc 100644 --- a/src/dancing_links.c +++ b/src/dancing_links.c @@ -146,7 +146,7 @@ void add_rows(int *types, int amount, int size, t_node **cols_arr) } } -void cover(t_node *to_cover) +int cover(t_node *to_cover) { static t_node *step_vert; static t_node *step_horiz; @@ -164,9 +164,10 @@ void cover(t_node *to_cover) } step_vert = step_vert->down; } + return (1); } -void uncover(t_node *to_uncover) +int uncover(t_node *to_uncover) { static t_node *step_vert; static t_node *step_horiz; @@ -185,6 +186,7 @@ void uncover(t_node *to_uncover) } to_uncover->left->right = to_uncover; to_uncover->right->left = to_uncover; + return (1); } void fill_map(char *map, int size, t_node *ttr, int letter) @@ -244,18 +246,12 @@ void search(t_node* root,t_node **solution, int k, int amount) { solution[k] = row; j = row->right; - while (j != row) - { - cover(j->column); + while (j != row && cover(j->column)) j = j->right; - } search(root, solution, k + 1, amount); j = row->left; - while (j != row) - { - uncover(j->column); + while (j != row && uncover(j->column)) j = j->left; - } row = row->down; } uncover(current_col); diff --git a/src/main.c b/src/main.c index 976f37c..0b6f6c9 100644 --- a/src/main.c +++ b/src/main.c @@ -13,7 +13,9 @@ #include "fillit.h" /* -** bad global variable +** definition of global variable +** that contains all possible tetrominoes +** inside 4x4 square with initial coordinates at [0][0] */ t_ttrmn g_templates[19] = @@ -54,16 +56,14 @@ int main(int argc, char **argv) ans = NULL; i = 0; - if (argc != 2) - { - ft_putstr("error\n"); - return (1); - } - if (!(string = read_file(argv[1]))) - { - ft_putstr("error\n"); - return (1); - } //printf("string:\n\n\n%s\n", string); + + if (argc != 2) + ft_putstr("error\n"); + else + init(argv[1]); + + string = read_file(argv[1]); + //printf("string:\n\n\n%s\n", string); table = to_table(&string); //printf("print_table:\n\n\n"); diff --git a/tests/color b/tests/color deleted file mode 100755 index 4ea5ef2..0000000 Binary files a/tests/color and /dev/null differ