some sort of refactoring :)

This commit is contained in:
Gregory Tertyshny 2016-12-22 21:12:16 +02:00
parent 46387d1666
commit fb65872848
5 changed files with 23 additions and 25 deletions

View file

@ -6,7 +6,7 @@
# By: gtertysh <marvin@42.fr> +#+ +:+ +#+ # # By: gtertysh <marvin@42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2016/12/14 16:54:48 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/ LIBFOLDER = ./libft/
FLAGS = -Werror -Wextra -Wall FLAGS = -Werror -Wextra -Wall -O2
CC = clang CC = clang

View file

@ -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 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); 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 fill_map(char *map, int size, t_node *ttr, int letter);
void init(char **argv);
#endif #endif

View file

@ -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_vert;
static t_node *step_horiz; static t_node *step_horiz;
@ -164,9 +164,10 @@ void cover(t_node *to_cover)
} }
step_vert = step_vert->down; 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_vert;
static t_node *step_horiz; static t_node *step_horiz;
@ -185,6 +186,7 @@ void uncover(t_node *to_uncover)
} }
to_uncover->left->right = to_uncover; to_uncover->left->right = to_uncover;
to_uncover->right->left = to_uncover; to_uncover->right->left = to_uncover;
return (1);
} }
void fill_map(char *map, int size, t_node *ttr, int letter) 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; solution[k] = row;
j = row->right; j = row->right;
while (j != row) while (j != row && cover(j->column))
{
cover(j->column);
j = j->right; j = j->right;
}
search(root, solution, k + 1, amount); search(root, solution, k + 1, amount);
j = row->left; j = row->left;
while (j != row) while (j != row && uncover(j->column))
{
uncover(j->column);
j = j->left; j = j->left;
}
row = row->down; row = row->down;
} }
uncover(current_col); uncover(current_col);

View file

@ -13,7 +13,9 @@
#include "fillit.h" #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] = t_ttrmn g_templates[19] =
@ -54,16 +56,14 @@ int main(int argc, char **argv)
ans = NULL; ans = NULL;
i = 0; i = 0;
if (argc != 2)
{ if (argc != 2)
ft_putstr("error\n"); ft_putstr("error\n");
return (1); else
} init(argv[1]);
if (!(string = read_file(argv[1])))
{ string = read_file(argv[1]);
ft_putstr("error\n"); //printf("string:\n\n\n%s\n", string);
return (1);
} //printf("string:\n\n\n%s\n", string);
table = to_table(&string); table = to_table(&string);
//printf("print_table:\n\n\n"); //printf("print_table:\n\n\n");

Binary file not shown.