-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfillit.h
176 lines (143 loc) · 4.76 KB
/
fillit.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* fillit.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rgaia <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/12/01 16:29:53 by rgaia #+# #+# */
/* Updated: 2017/12/05 16:11:38 by rgaia ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FILLIT_H
# define FILLIT_H
# include <unistd.h>
# include <stdlib.h>
# include <fcntl.h>
# include "libft/libft.h"
# define TRUE 1
# define FALSE 0
# define CHR_FIELD '.'
# define CHR_PIECE '#'
/*
** Max 26 pieces -> 21 * 26 - 1 = Maximum bytes allowed within file
** If Buffer fills to size >= 546 -> invalid file
*/
# define MAX_TET 26
# define TET_SIZE 4
# define TET_AREA ((TET_SIZE * TET_SIZE) + TET_SIZE)
# define MAX_F_LEN (TET_AREA + 1) * MAX_TET
# define BUF_SIZE (MAX_F_LEN + 1)
int g_num_tetriminos;
typedef struct s_point
{
int row;
int col;
} t_point;
typedef struct s_piece
{
int length;
int height;
char letter;
char *piece;
} t_piece;
typedef struct s_map
{
char **grid;
int size;
} t_map;
/*
** INPUT FUNCTIONS:
** @in: text file containing 4x4 tetrimino pieces separated by a new line
** @out: a List comprised of Linked Piece Structures containing all variables
** that describe a tetrimino piece
*/
/*
** valid_file_format:
** @in: file descriptor for Opened inputted file
** @out: File Characters, and Formatting is good -> returns tetrimino strings
** @error: File not good -> returns NULL
*/
char **valid_file_format(int fd);
int get_num_tetriminos(size_t len);
t_point *point_new(int row, int col);
/*
** valid_shape.c
*/
int if_linea_sqr(char *file_buf, int i);
int if_l(char *file_buf, int i);
int if_t(char *file_buf, int i);
int if_li(char *file_buf, int i);
int if_s_si(char *file_buf, int i);
/*
** valid_integration.c
*/
int valid_characters(char **file_tet, int elem, int i,
int count);
int if_valid_hash_num(char *file_buf, int j);
int if_new_line_end(char *file_buf, int i);
int valid_tetri(char *file_buf, int i);
char **valid_file_format(int fd);
/*
** valid_read_and_split.c
*/
int get_num_tetriminos(size_t len);
char *read_file(int fd);
char **split_tetriminos(char *file_buf, int i);
/*
** read_tetriminos:
** @in: buffer containing a possibly valid tetrimino string at each index
** @out: a List of Structs containing all Tetrimino Piece required variables
** @error: if any tetrimino is invalid -> returns NULL
*/
t_list *read_tetriminos(char **file_tetriminos);
/*
** Checks if all tetriminos are valid tetriminos
*/
int check_tetrimino(t_list *tetrimino);
int check_negative_length(char **t_lines);
/*
** SOLVE FUNCTIONS:
*/
/*
** solve:
** Entry function to our fill smallest square solver.
** This function will call the recursive function, and initialize the
** map that'll be returned when a solution is found.
** If a solution is not found, we delete previously used map, create a
** new one with incremented size, and call solve_backtrack again
*/
t_map *solve(t_list *tetriminos);
int check_fit(t_piece *piece, t_point *point,
t_map *map);
int check_fit_return(char *piece, t_point *point);
void check_reset_column(char **piece, t_point *point,
int size);
void check_reset(t_point *point, int size);
void offset_column(t_point *point, int *tmp, int size);
void increment_col_piece(t_point *point, char **piece);
void increment_piece(char **piece, int *tmp);
int verify_check_fit(t_piece *tetri, t_point *point,
int size);
int verify_grid_set_tmp(char *piece, t_point *point,
t_map *map, int *tmp);
/*
** map_tetrimino works as place_tetrimino and remove_tetrimino:
** i_r == '.': remove_tetrimino
** i_r == '#': place_tetrimino.
** Obs: does not do error checking. Will insert character sent to i_r
*/
void io_tet(char i_r, char *piece, t_point *point,
t_map *map);
t_point *point_new(int row, int col);
/*
** OUTPUT FUNCTIONS:
*/
void print_map(t_map *map);
t_map *init_map(int size);
void map_delete(t_map *map);
/*
** MEMORY FREE FUNCTIONS
*/
void free_memories(t_list *tetriminos, t_map *map);
#endif