-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
92 lines (83 loc) · 2.21 KB
/
main.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
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ldubos <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/12/07 13:18:39 by ldubos #+# #+# */
/* Updated: 2016/01/12 20:18:01 by dchristo ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
static int ft_min_sqr(t_tetrimino **tetrimino, int i)
{
t_tetrimino *t;
t = *tetrimino;
while (t->next != NULL)
{
i++;
t = t->next;
}
return (((int)((ft_sqrt((i * 4), 0.01) + 0.5))));
}
static int ft_map(char **map, int min_sqr)
{
free(*map);
if ((*map = ft_strnew(min_sqr * min_sqr)) == NULL)
return (0);
return (1);
}
static int ft_resolve_it(t_tetrimino *tetrimino, char **map,
int min_sqr)
{
min_sqr = ft_min_sqr(&tetrimino, 1);
if (!ft_map(map, min_sqr))
return (0);
while (((ft_resolve(tetrimino, min_sqr, *map))) != 1)
{
tetrimino->w_pos = (t_vector2){0, 0};
min_sqr++;
if (!ft_map(map, min_sqr))
return (0);
}
return (min_sqr);
}
static void ft_init_vector(t_tetrimino **tetrimino)
{
t_tetrimino *t;
t = *tetrimino;
while (t != NULL)
{
t->w_pos.x = 0;
t->w_pos.y = 0;
t = t->next;
}
}
int main(int argc, char **argv)
{
t_tetrimino *t;
char *map;
int min_sqr;
if ((t = (t_tetrimino *)malloc(sizeof(t_tetrimino))) == NULL)
return (0);
if (argc != 2)
write(1, "error\n", 6);
else
{
if (!ft_gettab(argv[1], &t))
{
write(1, "error\n", 6);
return (0);
}
ft_init_vector(&t);
ft_sort_tetri(&t, 0, 0, 0);
if (!(min_sqr = ft_resolve_it(t, &map, 0)))
{
write(1, "error\n", 6);
return (0);
}
ft_affichage_solution(map, min_sqr);
}
return (0);
}