algorythm that works, maybe
This commit is contained in:
parent
60119d12bb
commit
28c1cd98fd
6 changed files with 50 additions and 35 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -37,3 +37,6 @@
|
||||||
|
|
||||||
# Sublime files
|
# Sublime files
|
||||||
*.sublime*
|
*.sublime*
|
||||||
|
|
||||||
|
# Clion files
|
||||||
|
.idea
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
cmake_minimum_required(VERSION 3.6)
|
cmake_minimum_required(VERSION 3.5.2)
|
||||||
project(fillit)
|
project(fillit)
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 11)
|
set(CMAKE_CXX_STANDARD 11)
|
||||||
|
|
||||||
include_directories(inc)
|
include_directories(inc)
|
||||||
|
include_directories(libft)
|
||||||
|
|
||||||
set(SOURCE_FILES
|
set(SOURCE_FILES
|
||||||
inc/fillit.h
|
inc/fillit.h
|
||||||
inc/libft.h
|
|
||||||
libft/ft_atoi.c
|
libft/ft_atoi.c
|
||||||
libft/ft_bzero.c
|
libft/ft_bzero.c
|
||||||
libft/ft_isalnum.c
|
libft/ft_isalnum.c
|
||||||
|
@ -71,6 +71,7 @@ set(SOURCE_FILES
|
||||||
libft/ft_strtrim.c
|
libft/ft_strtrim.c
|
||||||
libft/ft_tolower.c
|
libft/ft_tolower.c
|
||||||
libft/ft_toupper.c
|
libft/ft_toupper.c
|
||||||
|
libft/ft_lstpop.c
|
||||||
libft/libft.h
|
libft/libft.h
|
||||||
src/check_raw_string.c
|
src/check_raw_string.c
|
||||||
src/dancing_links.c
|
src/dancing_links.c
|
||||||
|
@ -85,6 +86,7 @@ set(SOURCE_FILES
|
||||||
src/test!_print_one_string.c
|
src/test!_print_one_string.c
|
||||||
src/test!_print_table.c
|
src/test!_print_table.c
|
||||||
src/to_letters.c
|
src/to_letters.c
|
||||||
|
src/get_amount.c
|
||||||
tests/sample.fillit
|
tests/sample.fillit
|
||||||
tests/sample1.fillit)
|
tests/sample1.fillit)
|
||||||
|
|
||||||
|
|
|
@ -25,8 +25,8 @@
|
||||||
|
|
||||||
typedef struct s_coord
|
typedef struct s_coord
|
||||||
{
|
{
|
||||||
int x;
|
|
||||||
int y;
|
int y;
|
||||||
|
int x;
|
||||||
} t_coord;
|
} t_coord;
|
||||||
|
|
||||||
typedef struct s_ttrmn
|
typedef struct s_ttrmn
|
||||||
|
@ -43,7 +43,6 @@ typedef struct s_node
|
||||||
struct s_node *right;
|
struct s_node *right;
|
||||||
struct s_node *up;
|
struct s_node *up;
|
||||||
struct s_node *down;
|
struct s_node *down;
|
||||||
int row;
|
|
||||||
struct s_node *column;
|
struct s_node *column;
|
||||||
t_coord coord;
|
t_coord coord;
|
||||||
} t_node;
|
} t_node;
|
||||||
|
|
|
@ -18,7 +18,7 @@ t_node *init_root(void)
|
||||||
t_node *new;
|
t_node *new;
|
||||||
|
|
||||||
new = (t_node*)malloc(sizeof(t_node));
|
new = (t_node*)malloc(sizeof(t_node));
|
||||||
new->left = new->right = new->down = new->up = NULL;
|
new->left = new->right = new->down = new->up = new;
|
||||||
new->column = NULL;
|
new->column = NULL;
|
||||||
return (new);
|
return (new);
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,8 @@ t_node *add_column(t_node *root)
|
||||||
new_col->up = new_col;
|
new_col->up = new_col;
|
||||||
new_col->left = root->left;
|
new_col->left = root->left;
|
||||||
new_col->right = root;
|
new_col->right = root;
|
||||||
new_col->row = -1;
|
root->left->right = new_col;
|
||||||
|
root->left = new_col;
|
||||||
new_col->column = NULL;
|
new_col->column = NULL;
|
||||||
return (new_col);
|
return (new_col);
|
||||||
}
|
}
|
||||||
|
@ -43,6 +44,7 @@ t_node *add_node_with_coord(t_node *col, t_coord coord)
|
||||||
|
|
||||||
new_node = (t_node*)malloc(sizeof(t_node));
|
new_node = (t_node*)malloc(sizeof(t_node));
|
||||||
new_node->coord = coord;
|
new_node->coord = coord;
|
||||||
|
new_node->column = col;
|
||||||
new_node->up = col->up;
|
new_node->up = col->up;
|
||||||
new_node->down = col;
|
new_node->down = col;
|
||||||
col->up->down = new_node;
|
col->up->down = new_node;
|
||||||
|
@ -55,6 +57,7 @@ t_node *add_node(t_node *col)
|
||||||
t_node *new_node;
|
t_node *new_node;
|
||||||
|
|
||||||
new_node = (t_node*)malloc(sizeof(t_node));
|
new_node = (t_node*)malloc(sizeof(t_node));
|
||||||
|
new_node->column = col;
|
||||||
new_node->up = col->up;
|
new_node->up = col->up;
|
||||||
new_node->down = col;
|
new_node->down = col;
|
||||||
col->up->down = new_node;
|
col->up->down = new_node;
|
||||||
|
@ -65,23 +68,27 @@ t_node *add_node(t_node *col)
|
||||||
t_node **add_cols(t_node *root, int number)
|
t_node **add_cols(t_node *root, int number)
|
||||||
{
|
{
|
||||||
t_node **array;
|
t_node **array;
|
||||||
|
int i;
|
||||||
|
|
||||||
array = (t_node**)malloc(number * sizeof(t_node*));
|
array = (t_node**)malloc(number * sizeof(t_node*));
|
||||||
while (number--)
|
i = 0;
|
||||||
array[number] = add_column(root);
|
while (i < number)
|
||||||
|
array[i++] = add_column(root);
|
||||||
return (array);
|
return (array);
|
||||||
}
|
}
|
||||||
int *get_coords(t_coord coord, int amount, int type, int size)
|
int *get_coords(t_coord coord, int amount, int type, int size) {
|
||||||
{
|
|
||||||
int *result;
|
int *result;
|
||||||
int i;
|
int i;
|
||||||
t_coord *start;
|
t_coord *start;
|
||||||
|
|
||||||
result = (int*)malloc(sizeof(int) * 4);
|
result = (int *) malloc(sizeof(int) * 5);
|
||||||
start = g_templates[type].c;
|
start = g_templates[type].c;
|
||||||
i = 1;
|
i = 0;
|
||||||
while (i < 5)
|
while (i < 4)
|
||||||
result[i++] = coord.x + coord.y * size + start->x + start->y * size + amount;
|
{
|
||||||
|
result[i + 1] = (coord.x + coord.y * size + start[i].x + start[i].y * size) + amount;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
return (result);
|
return (result);
|
||||||
}
|
}
|
||||||
void add_row(int *col_numbers, t_node **cols_arr, t_coord coord)
|
void add_row(int *col_numbers, t_node **cols_arr, t_coord coord)
|
||||||
|
@ -116,12 +123,12 @@ void add_rows(int *types, int amount, int size, t_node **cols_arr)
|
||||||
t_coord coord;
|
t_coord coord;
|
||||||
|
|
||||||
while (i < amount)
|
while (i < amount)
|
||||||
{
|
|
||||||
k = 0;
|
|
||||||
while (k < size - g_templates[types[i]].width)
|
|
||||||
{
|
{
|
||||||
l = 0;
|
l = 0;
|
||||||
while (l < size - g_templates[types[i]].height)
|
while (l <= size - g_templates[types[i]].height)
|
||||||
|
{
|
||||||
|
k = 0;
|
||||||
|
while (k <= size - g_templates[types[i]].width)
|
||||||
{
|
{
|
||||||
coord.x = k;
|
coord.x = k;
|
||||||
coord.y = l;
|
coord.y = l;
|
||||||
|
@ -129,10 +136,10 @@ void add_rows(int *types, int amount, int size, t_node **cols_arr)
|
||||||
col_num[0] = i;
|
col_num[0] = i;
|
||||||
add_row(col_num, cols_arr, coord);
|
add_row(col_num, cols_arr, coord);
|
||||||
link_row(col_num, cols_arr);
|
link_row(col_num, cols_arr);
|
||||||
l++;
|
|
||||||
}
|
|
||||||
k++;
|
k++;
|
||||||
}
|
}
|
||||||
|
l++;
|
||||||
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -180,8 +187,9 @@ void uncover(t_node *to_uncover)
|
||||||
|
|
||||||
void print_solution(t_list *sol)
|
void print_solution(t_list *sol)
|
||||||
{
|
{
|
||||||
sol = 0;
|
if (sol)
|
||||||
printf("as\n");
|
printf("as\n");
|
||||||
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void search(t_node* root, t_list *solution, int k, int amount)
|
void search(t_node* root, t_list *solution, int k, int amount)
|
||||||
|
@ -199,20 +207,20 @@ void search(t_node* root, t_list *solution, int k, int amount)
|
||||||
row = current_col->down;
|
row = current_col->down;
|
||||||
while (row != current_col)
|
while (row != current_col)
|
||||||
{
|
{
|
||||||
ft_lstadd(&solution, ft_lstnew(row, sizeof(row)));
|
ft_lstadd(&solution, ft_lstnew(&row, sizeof(t_node *)));
|
||||||
j = row->right;
|
j = row->right;
|
||||||
while (j != row)
|
while (j != row)
|
||||||
{
|
{
|
||||||
cover(j);
|
cover(j->column);
|
||||||
j = j->right;
|
j = j->right;
|
||||||
}
|
}
|
||||||
search(root, solution, k + 1, amount);
|
search(root, solution, k + 1, amount);
|
||||||
row = (t_node*)ft_lstpop(&solution);
|
row = *((t_node**)(ft_lstpop(&solution)->content));
|
||||||
current_col = row->column;
|
current_col = row->column;
|
||||||
j = row->left;
|
j = row->left;
|
||||||
while (j != row)
|
while (j != row)
|
||||||
{
|
{
|
||||||
uncover(j);
|
uncover(j->column);
|
||||||
j = j->left;
|
j = j->left;
|
||||||
}
|
}
|
||||||
row = row->down;
|
row = row->down;
|
||||||
|
|
|
@ -84,10 +84,13 @@ int main(int argc, char **argv)
|
||||||
types = get_types(ttr);
|
types = get_types(ttr);
|
||||||
amount = get_amount(ttr);
|
amount = get_amount(ttr);
|
||||||
size = ft_sqrt_ceil(amount * 4);
|
size = ft_sqrt_ceil(amount * 4);
|
||||||
|
while (1) {
|
||||||
r = init_root();
|
r = init_root();
|
||||||
cols_arr = add_cols(r, (size * size + amount));
|
cols_arr = add_cols(r, (size * size + amount));
|
||||||
add_rows(types, amount, size, cols_arr);
|
add_rows(types, amount, size, cols_arr);
|
||||||
//search(r, ans, 0, amount);
|
search(r, ans, 0, amount);
|
||||||
|
size++;
|
||||||
|
}
|
||||||
//print_ans(ans);
|
//print_ans(ans);
|
||||||
//printf("%s\n %d, %d", strct_ttr[0]->t, strct_ttr[0]->x, strct_ttr[0]->y);
|
//printf("%s\n %d, %d", strct_ttr[0]->t, strct_ttr[0]->x, strct_ttr[0]->y);
|
||||||
//to_letters(ttr);
|
//to_letters(ttr);
|
||||||
|
|
|
@ -1,8 +1,3 @@
|
||||||
####
|
|
||||||
....
|
|
||||||
....
|
|
||||||
....
|
|
||||||
|
|
||||||
....
|
....
|
||||||
##..
|
##..
|
||||||
.#..
|
.#..
|
||||||
|
@ -17,3 +12,8 @@
|
||||||
##..
|
##..
|
||||||
##..
|
##..
|
||||||
....
|
....
|
||||||
|
|
||||||
|
####
|
||||||
|
....
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
Loading…
Reference in a new issue