2016-12-14 20:00:58 +02:00
|
|
|
/* ************************************************************************** */
|
|
|
|
/* */
|
|
|
|
/* ::: :::::::: */
|
|
|
|
/* fillit.h :+: :+: :+: */
|
|
|
|
/* +:+ +:+ +:+ */
|
|
|
|
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
|
|
|
/* +#+#+#+#+#+ +#+ */
|
|
|
|
/* Created: 2016/12/14 16:42:06 by gtertysh #+# #+# */
|
2016-12-20 19:40:21 +02:00
|
|
|
/* Updated: 2016/12/20 19:18:00 by gtertysh ### ########.fr */
|
2016-12-14 20:00:58 +02:00
|
|
|
/* */
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
|
|
|
#ifndef FILLIT_H
|
|
|
|
# define FILLIT_H
|
|
|
|
|
|
|
|
#include "libft.h"
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <fcntl.h>
|
2016-12-20 05:47:48 +02:00
|
|
|
#include <stdint.h>
|
2016-12-14 20:00:58 +02:00
|
|
|
#include <stdio.h> // warning!
|
|
|
|
|
|
|
|
# define BUF_S 8192
|
|
|
|
|
2016-12-20 19:40:21 +02:00
|
|
|
typedef struct s_coord
|
|
|
|
{
|
|
|
|
int y;
|
2016-12-21 20:51:29 +02:00
|
|
|
int x;
|
2016-12-20 19:40:21 +02:00
|
|
|
} t_coord;
|
|
|
|
|
2016-12-20 05:47:48 +02:00
|
|
|
typedef struct s_ttrmn
|
2016-12-14 20:00:58 +02:00
|
|
|
{
|
2016-12-20 19:40:21 +02:00
|
|
|
char t[17];
|
2016-12-21 01:47:55 +02:00
|
|
|
int width;
|
|
|
|
int height;
|
2016-12-20 19:40:21 +02:00
|
|
|
t_coord c[4];
|
2016-12-20 05:47:48 +02:00
|
|
|
} t_ttrmn;
|
2016-12-14 20:00:58 +02:00
|
|
|
|
2016-12-20 19:40:21 +02:00
|
|
|
typedef struct s_node
|
|
|
|
{
|
|
|
|
struct s_node *left;
|
|
|
|
struct s_node *right;
|
|
|
|
struct s_node *up;
|
|
|
|
struct s_node *down;
|
2016-12-20 20:36:10 +02:00
|
|
|
struct s_node *column;
|
2016-12-20 21:46:08 +02:00
|
|
|
t_coord coord;
|
2016-12-22 05:34:24 +02:00
|
|
|
int type;
|
|
|
|
int size;
|
|
|
|
} t_node;
|
2016-12-20 19:40:21 +02:00
|
|
|
|
2016-12-20 21:46:08 +02:00
|
|
|
extern t_ttrmn g_templates[19];
|
2016-12-20 19:40:21 +02:00
|
|
|
|
2016-12-14 20:00:58 +02:00
|
|
|
// reads from file
|
|
|
|
char *read_file(char *path);
|
|
|
|
|
|
|
|
// convert string to table by spliting by '\n'
|
|
|
|
char **to_table(char **string);
|
|
|
|
|
|
|
|
// print table returned by to_table()
|
|
|
|
void print_table(char **table);
|
|
|
|
|
|
|
|
// creates new table where each string represent whole figrure
|
|
|
|
char **glue_figure(char **table);
|
|
|
|
|
|
|
|
// move tetromino in top left corner
|
|
|
|
void move_up_left(char **table);
|
|
|
|
|
|
|
|
// print table returned by glue_figure()
|
2016-12-20 20:32:30 +02:00
|
|
|
void print_one_string(t_ttrmn ttr);
|
2016-12-14 20:00:58 +02:00
|
|
|
|
|
|
|
// compare 19 templates with each tetromino in *ttr table
|
2016-12-20 05:47:48 +02:00
|
|
|
void test_check(char **ttr, t_ttrmn *tamplates);
|
2016-12-14 20:00:58 +02:00
|
|
|
|
|
|
|
// change hashes ('#') with letters
|
|
|
|
// obsolete, rewrite for structs array
|
|
|
|
void to_letters(char **ttr);
|
|
|
|
|
2016-12-22 05:34:24 +02:00
|
|
|
t_node *init_root(int size);
|
2016-12-21 16:47:36 +02:00
|
|
|
|
2016-12-20 20:36:10 +02:00
|
|
|
t_node *add_column(t_node *root);
|
2016-12-20 21:46:08 +02:00
|
|
|
|
2016-12-21 16:47:36 +02:00
|
|
|
t_node **add_cols(t_node *root, int number);
|
|
|
|
|
|
|
|
t_node *add_node(t_node *col);
|
|
|
|
|
2016-12-22 05:34:24 +02:00
|
|
|
t_node *add_node_with_coord(t_node *col, t_coord row, int type);
|
2016-12-21 16:47:36 +02:00
|
|
|
|
|
|
|
t_node **add_cols(t_node *root, int number);
|
|
|
|
|
2016-12-22 05:34:24 +02:00
|
|
|
void print_solution(t_list *sol, t_node *root, int amount);
|
2016-12-21 16:47:36 +02:00
|
|
|
|
|
|
|
void add_rows(int *types, int amount, int size, t_node **cols_arr);
|
|
|
|
|
|
|
|
void link_row(int *col_nums, t_node **cols_arr);
|
|
|
|
|
2016-12-22 05:34:24 +02:00
|
|
|
void add_row(int *col_numbers, t_node **cols_arr, t_coord coord, int type);
|
2016-12-21 16:47:36 +02:00
|
|
|
|
|
|
|
void search(t_node* root, t_list *solution, int k, int amount);
|
2016-12-20 21:46:08 +02:00
|
|
|
|
2016-12-20 20:36:10 +02:00
|
|
|
void cover(t_node *to_cover);
|
2016-12-20 19:40:21 +02:00
|
|
|
|
2016-12-20 21:46:08 +02:00
|
|
|
void uncover(t_node *to_uncover);
|
2016-12-20 05:47:48 +02:00
|
|
|
|
2016-12-20 21:46:08 +02:00
|
|
|
int *get_types(char **ttr);
|
2016-12-15 19:16:26 +02:00
|
|
|
|
2016-12-21 16:47:36 +02:00
|
|
|
int get_amount(char **ttr);
|
|
|
|
|
|
|
|
unsigned int ft_sqrt_ceil(unsigned int num);
|
|
|
|
|
2016-12-22 05:49:27 +02:00
|
|
|
void fill_map(char *map, int size, t_node *ttr, int letter);
|
2016-12-22 05:34:24 +02:00
|
|
|
|
2016-12-14 20:00:58 +02:00
|
|
|
#endif
|