-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgaps.c
More file actions
59 lines (54 loc) · 1.8 KB
/
gaps.c
File metadata and controls
59 lines (54 loc) · 1.8 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* gaps.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: staeter <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/01/11 13:14:45 by staeter #+# #+# */
/* Updated: 2019/01/12 13:33:59 by nraziano ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
static unsigned short get_gap(unsigned short t[16], short x, short y,
unsigned short gsize)
{
unsigned short acc;
acc = 1;
t[x] |= (1 << y);
if (y + 1 < gsize && !(t[x] & (1 << (y + 1))))
acc += get_gap(t, x, y + 1, gsize);
if (y - 1 >= 0 && !(t[x] & (1 << (y - 1))))
acc += get_gap(t, x, y - 1, gsize);
if (x + 1 < gsize && !(t[x + 1] & (1 << y)))
acc += get_gap(t, x + 1, y, gsize);
if (x - 1 >= 0 && !(t[x - 1] & (1 << y)))
acc += get_gap(t, x - 1, y, gsize);
return (acc);
}
t_boolean isvalidgap(const t_grid *g)
{
unsigned short t[16];
short i;
short j;
unsigned short gap;
unsigned short a;
i = -1;
while (++i < g->gsize)
t[i] = g->tab[i];
gap = 0;
i = -1;
while (++i < g->gsize)
{
j = -1;
while (t[i] && ++j < g->gsize)
if (!(t[i] & (1 << j)))
{
a = get_gap(t, i, j, g->gsize);
gap += a % 4;
if (gap > g->maxgap)
return (0);
}
}
return (1);
}