-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfillit.c
63 lines (55 loc) · 1.85 KB
/
fillit.c
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* fillit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rgaia <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/30 09:48:50 by rgaia #+# #+# */
/* Updated: 2017/12/05 17:18:36 by eguajard ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
/*
** This is the entry point to our Fillit program
*/
void exit_failure(char *str)
{
ft_putstr(str);
exit(EXIT_FAILURE);
}
static t_map *check_2b2(t_piece *tetri)
{
t_map *map;
if (g_num_tetriminos != 1)
return (NULL);
if (ft_strequ(tetri->piece, "##...##") == 0)
return (NULL);
map = init_map(2);
ft_strcpy(map->grid[0], "AA");
ft_strcpy(map->grid[1], "AA");
return (map);
}
/*
** free_file_tetriminos(&file_tetriminos);
** free_tetriminos(&tetriminos);
** free_map(&map);
*/
int main(int argc, char **argv)
{
int fd;
char **file_tetriminos;
t_map *map;
t_list *tetriminos;
if (argc != 2)
exit_failure("usage: ./fillit source_file");
if ((fd = open(argv[1], O_RDONLY)) < 1)
exit_failure("error\n");
if ((file_tetriminos = valid_file_format(fd)) == NULL)
exit_failure("error\n");
tetriminos = read_tetriminos(file_tetriminos);
if ((map = check_2b2(tetriminos->content)) == NULL)
map = solve(tetriminos);
print_map(map);
return (0);
}