From fb658728480a7fbaf1bb1e3af3bf6de0c72874e1 Mon Sep 17 00:00:00 2001 From: Gregory Tertyshny Date: Thu, 22 Dec 2016 21:12:16 +0200 Subject: [PATCH] some sort of refactoring :) --- Makefile | 4 ++-- inc/fillit.h | 6 ++++-- src/dancing_links.c | 16 ++++++---------- src/main.c | 22 +++++++++++----------- tests/color | Bin 8936 -> 0 bytes 5 files changed, 23 insertions(+), 25 deletions(-) delete mode 100755 tests/color 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 4ea5ef2ce9f1b4cb12340f7335d8e47da2c951e5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 8936 zcmeHMeQaCR6~DIgMO$o_@zD>oK6T9&isCvY34yZloR9XUN(;0J6R_~&*iK^bM`S;< z6tTjT7Rf4wO53FTF(jt3iD?_^q-}KjqfJ*ti!^O5;%j1)Is_!ql$E^&p> z#RhS`XaG`=qRSTIc8&R>a?QL+>G{CxP`bP}(B;)-h57Y1j2>*_5fZ2VDx|Bb%`d19 zm$1YU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