init tor funcitons

This commit is contained in:
Kolomiets Yaroslav 2016-12-21 01:47:55 +02:00
parent d8d007b41f
commit c2406e5830
5 changed files with 193 additions and 7 deletions

91
CMakeLists.txt Normal file
View file

@ -0,0 +1,91 @@
cmake_minimum_required(VERSION 3.6)
project(fillit)
set(CMAKE_CXX_STANDARD 11)
include_directories(inc)
set(SOURCE_FILES
inc/fillit.h
inc/libft.h
libft/ft_atoi.c
libft/ft_bzero.c
libft/ft_isalnum.c
libft/ft_isalpha.c
libft/ft_isascii.c
libft/ft_isdigit.c
libft/ft_isprint.c
libft/ft_itoa.c
libft/ft_lst_at.c
libft/ft_lstadd.c
libft/ft_lstadd_back.c
libft/ft_lstdel.c
libft/ft_lstdelone.c
libft/ft_lstfind.c
libft/ft_lstiter.c
libft/ft_lstmap.c
libft/ft_lstnew.c
libft/ft_lststrsplit.c
libft/ft_memalloc.c
libft/ft_memccpy.c
libft/ft_memchr.c
libft/ft_memcmp.c
libft/ft_memcpy.c
libft/ft_memdel.c
libft/ft_memmove.c
libft/ft_memset.c
libft/ft_putchar.c
libft/ft_putchar_fd.c
libft/ft_putendl.c
libft/ft_putendl_fd.c
libft/ft_putnbr.c
libft/ft_putnbr_fd.c
libft/ft_putstr.c
libft/ft_putstr_fd.c
libft/ft_realloc.c
libft/ft_strcat.c
libft/ft_strchr.c
libft/ft_strclr.c
libft/ft_strcmp.c
libft/ft_strcpy.c
libft/ft_strdel.c
libft/ft_strdup.c
libft/ft_strequ.c
libft/ft_striter.c
libft/ft_striteri.c
libft/ft_strjoin.c
libft/ft_strlcat.c
libft/ft_strlen.c
libft/ft_strmap.c
libft/ft_strmapi.c
libft/ft_strncat.c
libft/ft_strncmp.c
libft/ft_strncpy.c
libft/ft_strnequ.c
libft/ft_strnew.c
libft/ft_strnstr.c
libft/ft_strrchr.c
libft/ft_strsplit.c
libft/ft_strstr.c
libft/ft_strsub.c
libft/ft_strtrim.c
libft/ft_tolower.c
libft/ft_toupper.c
libft/libft.h
src/check_raw_string.c
src/dancing_links.c
src/fillit.c
src/get_types.c
src/glue_figure.c
src/main.c
src/move_up_left.c
src/read_file.c
src/string_to_table.c
src/test!_check.c
src/test!_print_one_string.c
src/test!_print_table.c
src/to_letters.c
tests/sample.fillit
tests/sample1.fillit)
add_executable(fillit ${SOURCE_FILES})

View file

@ -32,8 +32,8 @@ typedef struct s_coord
typedef struct s_ttrmn typedef struct s_ttrmn
{ {
char t[17]; char t[17];
int x; int width;
int y; int height;
t_coord c[4]; t_coord c[4];
} t_ttrmn; } t_ttrmn;
@ -80,7 +80,7 @@ int *to_strct_array(char **ttr, t_ttrmn *templates);
t_node *add_column(t_node *root); t_node *add_column(t_node *root);
t_node *add_node(t_node *col, int row); t_node *add_node(t_node *col, t_coord row);
void cover(t_node *to_cover); void cover(t_node *to_cover);

View file

@ -10,7 +10,17 @@
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "fillit.h" #include "../inc/fillit.h"
#include <stdlib.h>
t_node *init_root()
{
t_node *new;
new = (t_node*)malloc(sizeof(t_node));
new->left = new->right = new->down = new->up = NULL;
new->column = NULL;
}
t_node *add_column(t_node *root) t_node *add_column(t_node *root)
{ {
@ -26,12 +36,12 @@ t_node *add_column(t_node *root)
return (new_col); return (new_col);
} }
t_node *add_node(t_node *col, int row) t_node *add_node_with_coord(t_node *col, t_coord coord)
{ {
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->row = row; new_node->coord = coord;
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;
@ -39,6 +49,89 @@ t_node *add_node(t_node *col, int row)
return (new_node); return (new_node);
} }
t_node *add_node(t_node *col
{
t_node *new_node;
new_node = (t_node*)malloc(sizeof(t_node));
new_node->up = col->up;
new_node->down = col;
col->up->down = new_node;
col->up = new_node;
return (new_node);
}
t_node **add_cols(t_node *root, int number)
{
t_node **array;
array = (t_node**)malloc(number * sizeof(t_node*));
while (number--)
array[number] = add_column(root);
return (array);
}
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);
start = g_templates[type].c;
i = 1;
while (i < 5)
result[i++] = coord.x + coord.y * size + start->x + start->y * size + amount;
return (result);
}
void add_row(int *col_numbers, t_node **cols_arr, t_coord coord)
{
add_node_with_coord(cols_arr[col_numbers[0]], coord);
add_node(cols_arr[col_numbers[1]]);
add_node(cols_arr[col_numbers[2]]);
add_node(cols_arr[col_numbers[3]]);
add_node(cols_arr[col_numbers[4]]);
}
void link_row(int *col_nums, t_node **cols_arr)
{
cols_arr[col_nums[0]]->up->left = cols_arr[col_nums[4]]->up;
cols_arr[col_nums[0]]->up->right = cols_arr[col_nums[1]]->up;
cols_arr[col_nums[1]]->up->left = cols_arr[col_nums[0]]->up;
cols_arr[col_nums[1]]->up->right = cols_arr[col_nums[2]]->up;
cols_arr[col_nums[2]]->up->left = cols_arr[col_nums[1]]->up;
cols_arr[col_nums[2]]->up->right = cols_arr[col_nums[3]]->up;
cols_arr[col_nums[3]]->up->left = cols_arr[col_nums[2]]->up;
cols_arr[col_nums[3]]->up->right = cols_arr[col_nums[4]]->up;
cols_arr[col_nums[4]]->up->left = cols_arr[col_nums[3]]->up;
cols_arr[col_nums[4]]->up->right = cols_arr[col_nums[0]]->up;
}
void add_rows(int *types, int amount, int size, t_node **cols_arr)
{
int i = 0;
int k = 0;
int l = 0;
int *col_num;
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)
{
coord = {k, l};
col_num = get_coords(coord, amount, types[i], size);
col_num[0] = i;
add_row(col_num, cols_arr, coord);
link_row(col_num, cols_arr);
}
}
}
}
void cover(t_node *to_cover) void cover(t_node *to_cover)
{ {
t_node *step_vert; t_node *step_vert;

View file

@ -1,4 +1,5 @@
#include "fillit.h" #include "fillit.h"
#include <stdlib.h>
int *get_types(char **ttr) int *get_types(char **ttr)
{ {

View file

@ -47,6 +47,7 @@ int main(int argc, char **argv)
int i; int i;
int *types; int *types;
int amount; int amount;
int size;
t_node *r; t_node *r;
t_node **cols_arr; t_node **cols_arr;
t_list *ans; t_list *ans;
@ -84,7 +85,7 @@ int main(int argc, char **argv)
size = ft_sqrt_ceil(amount * 4); size = ft_sqrt_ceil(amount * 4);
r = init_root(); r = init_root();
cols_arr = add_cols(r, (size * size + amount)); cols_arr = add_cols(r, (size * size + amount));
add_rows(r, types, amount, cols_arr); add_rows(types, amount, cols_arr);
ans = dlx(r); ans = dlx(r);
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);