-
Notifications
You must be signed in to change notification settings - Fork 0
/
grid_0.c
executable file
·80 lines (72 loc) · 1.81 KB
/
grid_0.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* grid_0.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: staeter <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/18 13:48:38 by staeter #+# #+# */
/* Updated: 2019/01/12 13:38:21 by nraziano ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
void free_grid(t_grid **g)
{
if (*g)
{
free_node(&(*g)->incr);
free(*g);
*g = NULL;
}
}
t_grid *new_grid(unsigned short gsize)
{
t_grid *dest;
short i;
if (!(dest = (t_grid *)malloc(sizeof(t_grid))))
return (NULL);
dest->gsize = gsize;
dest->incr = NULL;
dest->maxgap = 0;
i = 0;
while (i < 16)
dest->tab[i++] = 0;
return (dest);
}
t_boolean insertetri_grid(t_grid *g, t_tetri *te)
{
unsigned short i;
unsigned short k;
i = 0;
while (i < g->gsize && !te->tab[i])
i++;
k = i;
while (i < g->gsize && te->tab[i])
{
if (g->tab[i] & te->tab[i])
return (0);
i++;
}
while (k < g->gsize && te->tab[k])
{
g->tab[k] += te->tab[k];
k++;
}
return (1);
}
void rmtetri_grid(t_grid *g, t_tetri *te)
{
unsigned short i;
if (te->ising)
{
i = 0;
while (i < g->gsize && !te->tab[i])
i++;
while (i < g->gsize && te->tab[i])
{
g->tab[i] -= te->tab[i];
i++;
}
te->ising = 0;
}
}