-
Notifications
You must be signed in to change notification settings - Fork 0
/
move_1.c
128 lines (117 loc) · 2.56 KB
/
move_1.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* move_1.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: staeter <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/01/11 12:23:46 by staeter #+# #+# */
/* Updated: 2019/01/12 13:54:50 by nraziano ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
t_boolean isvalidxmove(t_tetri *te, int x, unsigned short gsize)
{
int i;
if (x > 0)
{
if (x >= gsize)
return (0);
i = gsize;
while (--i >= gsize - x)
if (te->tab[i])
return (0);
}
else if (x < 0)
{
if (x <= -(int)(gsize))
return (0);
x *= -1;
i = -1;
while (++i < x)
if (te->tab[i])
return (0);
}
return (1);
}
static t_boolean isvalidymove_sub(t_tetri *te, int y,
unsigned short gsize, int i)
{
int j;
while (i < gsize && te->tab[i])
{
j = -1;
while (++j < y)
if (te->tab[i] & (1 << j))
return (0);
i++;
}
return (1);
}
t_boolean isvalidymove(t_tetri *te, int y,
unsigned short gsize, int i)
{
int j;
if (y > 0)
{
if (y >= gsize)
return (0);
while (i < gsize && te->tab[i])
{
j = gsize;
while (--j >= gsize - y)
if (te->tab[i] & (1 << j))
return (0);
i++;
}
}
else if (y < 0)
{
if (y <= -(int)(gsize))
return (0);
if (isvalidymove_sub(te, y, gsize, i) == 0)
return (0);
y *= -1;
}
return (1);
}
void movetopleft_tetri(t_tetri *te, unsigned short gsize)
{
int x;
int y;
int i;
int j;
i = 0;
while (i < gsize && !te->tab[i])
i++;
x = i;
y = gsize;
while (i < gsize && te->tab[i] && y)
{
j = 0;
while (j < gsize && !(te->tab[i] & (1 << j)))
j++;
y = (j < y) ? j : y;
i++;
}
move_tetri(te, -x, -y, gsize);
}
t_boolean movenextline_tetri(t_tetri *te, unsigned short gsize)
{
int y;
int i;
int j;
i = 0;
while (i < gsize && !te->tab[i])
i++;
y = gsize;
while (i < gsize && te->tab[i] && y)
{
j = 0;
while (j < gsize && !(te->tab[i] & (1 << j)))
j++;
y = (j < y) ? j : y;
i++;
}
return (move_tetri(te, 1, -y, gsize));
}