-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_solve_opt.c
More file actions
64 lines (59 loc) · 1.69 KB
/
ft_solve_opt.c
File metadata and controls
64 lines (59 loc) · 1.69 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_solve_opt.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jszabo <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/12/13 14:22:34 by jszabo #+# #+# */
/* Updated: 2018/01/11 17:55:09 by akaseris ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
static int ft_countdots(char **grid, char c)
{
int i;
int j;
int count;
i = 0;
count = 0;
while (grid[i])
{
j = 0;
while (grid[i][j])
{
if (grid[i][j] == '.')
count++;
else if (grid[i][j] == c)
return (count);
j++;
}
i++;
}
return (0);
}
int ft_solve_opt(t_tet *blocks, t_tet *initial, char **grid,
int ign)
{
t_tet *tmp;
while (blocks)
{
tmp = initial;
while (blocks->c != 'A' && tmp->c != (blocks->c) - 1)
tmp = tmp->next;
if (!ft_putblock(blocks, grid, ign))
{
if (blocks->c == 'A')
return (0);
ign = ft_countdots(grid, (blocks->c) - 1) + 1;
grid = ft_erase_block(grid, ((blocks->c) - 1));
blocks = tmp;
continue ;
}
ign = 0;
if (!blocks->next->next->next->next)
break ;
blocks = blocks->next->next->next->next;
}
return (1);
}