-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresolve.c
More file actions
74 lines (67 loc) · 2.05 KB
/
Copy pathresolve.c
File metadata and controls
74 lines (67 loc) · 2.05 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
65
66
67
68
69
70
71
72
73
74
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* resolve.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: abezanni <abezanni@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/28 15:07:43 by abezanni #+# #+# */
/* Updated: 2017/11/28 16:10:22 by abezanni ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
int ft_ispoint(t_tetri *pos, char *tab, int size, int *nb_essai)
{
int i;
i = -1;
while (++i < 4)
{
if (pos->x[i] + pos->y[i] * size + *nb_essai < size * (size + 1))
{
if (tab[pos->x[i] + pos->y[i] * (size + 1) + *nb_essai] != '.')
return (0);
}
else
return (0);
}
return (1);
}
void ft_write_char(char *tab, t_tetri *pos, int size, int nb_essai)
{
int i;
i = -1;
while (++i < 4)
{
if (tab[pos->x[i] + pos->y[i] * (size + 1) + nb_essai] == '.')
tab[pos->x[i] + pos->y[i] * (size + 1) + nb_essai] = pos->c;
else
tab[pos->x[i] + pos->y[i] * (size + 1) + nb_essai] = '.';
}
}
int ft_back_track(t_list **list, char *tab, int *nb_essai, int size)
{
int next_pos;
t_tetri *pos;
next_pos = 0;
pos = (t_tetri*)((*list)->content);
if (*nb_essai < size * (size + 1) && ft_ispoint(pos, tab, size, nb_essai))
{
ft_write_char(tab, pos, size, *nb_essai);
if ((*list)->next)
{
while (next_pos <= size * (size + 1))
{
if (ft_back_track(&((*list)->next), tab, &next_pos, size))
return (1);
next_pos++;
}
}
if (next_pos)
{
ft_write_char(tab, pos, size, *nb_essai);
return (0);
}
return (1);
}
return (0);
}