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