fillit/inc/fillit.h

178 lines
3.9 KiB
C
Raw Permalink Normal View History

2016-12-26 18:48:33 +02:00
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* fillit.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/14 16:42:06 by gtertysh #+# #+# */
/* Updated: 2016/12/26 17:46:30 by gtertysh ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FILLIT_H
# define FILLIT_H
# include "libft.h"
# include <unistd.h>
# include <stdlib.h>
# include <fcntl.h>
# define BUF_S 8192
/*
** s_coord contain
** coordinates of all #
** within tetromino
*/
typedef struct s_coord
{
int y;
int x;
} t_coord;
/*
** s_ttrmn contain:
** - t[17] represent tample
** tetromino in 4x4 square
** as string
** - actual width and height
** of tetromino
** - array of coordinates
** of each #
*/
typedef struct s_ttrmn
{
char t[17];
int width;
int height;
t_coord c[4];
} t_ttrmn;
/*
** s_node - node of double-linked list
** for Knuth's "dancing links".
** For more detail see:
** https://arxiv.org/pdf/cs/0011047v1.pdf
*/
typedef struct s_node
{
struct s_node *left;
struct s_node *right;
struct s_node *up;
struct s_node *down;
struct s_node *column;
t_coord coord;
int type;
int size;
} t_node;
/*
** declaration of global variable
** with all possible (19)
** tetrominoes where each one
** sits in upper-left corner
*/
extern t_ttrmn g_templates[19];
/*
** reads data from file to one string.
*/
char *read_file(char *path);
/*
** check right amount of '\n', their position
** and allowed chars
*/
void check_string(char *string);
/*
** split string to table by '\n'
*/
char **to_table(char **string);
/*
** creates new table where each string represent whole figrure.
** "Glues" each set of four strings into one
*/
char **glue_figure(char **table);
/*
** move tetromino in upper-left corner
*/
void move_up_left(char **table);
/*
** creates first node of double-chained list
** (in future "torus")
*/
t_node *init_root(int size);
/*
** links new node to the left of the root
*/
t_node *add_column(t_node *root);
/*
** calls function above to create first size * size + amount
** nodes, where:
** size - size of square side
** amount - quantity of tetrominoes in file
*/
t_node **add_cols(t_node *root, int number);
/*
** actually, the same as add_column. But why not to add yet another
** "useful" function ? :)
*/
t_node *add_node(t_node *col);
/*
** again, the same as add_node() and add_column(). For clarity :)
*/
t_node *add_node_with_coord(t_node *col, t_coord row, int type);
/*
** output of the program
*/
void print_square(t_node **sol, int amount, int size);
/*
** add all possible position variants of a given figures.
*/
void add_rows(int *types, int amount, int size,
t_node **cols_arr);
void link_row(int *col_nums, t_node **cols_arr);
void add_row(int *col_numbers, t_node **cols_arr,
t_coord coord, int type);
void search(t_node *root, t_node **solution, int k, int amount);
int cover(t_node *to_cover);
int uncover(t_node *to_uncover);
int *get_types(char **ttr);
int get_amount(char **ttr);
int ft_sqrt_ceil(int num);
void fill_map(char *map, int size, t_node *ttr, int letter);
void init(char *path);
void error(void);
void check_ch(char ch);
void check_table(char **ttr);
void algorithm(int *types, int amount);
#endif