-
Notifications
You must be signed in to change notification settings - Fork 0
/
solver.c
114 lines (103 loc) · 2.36 KB
/
solver.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* solver.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aallali <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/12/19 19:36:28 by aallali #+# #+# */
/* Updated: 2018/12/19 20:11:06 by aallali ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
void print_board(char **board, int size)
{
int i;
int j;
i = 0;
j = 0;
while (i < size)
{
while (j < size)
{
ft_putchar(board[i][j]);
j++;
}
ft_putchar('\n');
j = 0;
i++;
}
}
int solve(char **board, t_tet *tetris, int *sc, int c)
{
int it[2];
it[0] = 0;
it[1] = 0;
if (c == sc[1])
return (1);
while (it[0] < sc[0] - tetris[c].height + 1)
{
while (it[1] < sc[0] - tetris[c].weight + 1)
{
if (check_put_tetri(board, it[0], it[1], tetris[c]) == 1)
{
put_tetri(board, it[0], it[1], tetris[c]);
if (solve(board, tetris, sc, c + 1) == 1)
return (1);
else
delete_tetris(board, tetris[c]);
}
it[1]++;
}
it[1] = 0;
it[0]++;
}
c++;
return (0);
}
int solver(char **board, t_tet *tetris, int size, int count)
{
int it[2];
it[0] = size;
it[1] = count;
if (!solve(board, tetris, it, 0))
{
it[0]++;
creat_wokspace(board, it[0]);
return (solver(board, tetris, it[0], it[1]));
}
print_board(board, it[0]);
return (0);
}
void count_details(t_tet *tetris, int count)
{
int x;
int i;
int height;
int weight;
height = 0;
weight = 0;
x = 0;
i = 0;
while (i < count)
{
while (x < 4)
{
if (tetris[i].tet_coord[x][0] >= height)
tetris[i].height = tetris[i].tet_coord[x][0];
if (tetris[i].tet_coord[x][1] >= weight)
tetris[i].weight = tetris[i].tet_coord[x][1];
x++;
}
x = 0;
i++;
}
}
int ft_sqrt(int nbr)
{
int size;
size = 2;
while (size * size < nbr)
size++;
return (size);
}