-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmove_0.c
More file actions
executable file
·103 lines (94 loc) · 2.26 KB
/
move_0.c
File metadata and controls
executable file
·103 lines (94 loc) · 2.26 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
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* move_0.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: staeter <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/18 14:04:47 by staeter #+# #+# */
/* Updated: 2019/01/12 13:47:29 by nraziano ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
static void moveonposx_tetri(t_tetri *te, int x, unsigned short gsize)
{
unsigned short t[16];
int i;
i = -1;
while (++i < x)
t[i] = 0;
while (i < gsize)
{
t[i] = te->tab[i - x];
i++;
}
i = -1;
while (++i < gsize)
te->tab[i] = t[i];
}
static void moveonnegx_tetri(t_tetri *te, int x, unsigned short gsize)
{
unsigned short t[16];
int i;
x *= -1;
i = gsize;
while (--i >= gsize - x)
t[i] = 0;
while (i >= 0)
{
t[i] = te->tab[i + x];
i--;
}
i = -1;
while (++i < gsize)
te->tab[i] = t[i];
}
static void moveony_tetri(t_tetri *te, int y, unsigned short gsize, int i)
{
if (y > 0)
{
while (i < gsize && te->tab[i])
{
te->tab[i] = te->tab[i] << y;
i++;
}
}
else if (y < 0)
{
y *= -1;
while (i < gsize && te->tab[i])
{
te->tab[i] = te->tab[i] >> y;
i++;
}
}
}
/*
** c = 0 -> no tests applied
** c = 1 -> test x move
** c = 2 -> test y move
** c = 3 -> test all
*/
t_boolean move_tetri(t_tetri *te, int x, int y,
unsigned short gsize)
{
int i;
short c;
c = 3;
if ((c == 1 || c == 3) && !isvalidxmove(te, x, gsize))
return (0);
i = 0;
if (y)
{
while (i < gsize && !te->tab[i])
i++;
if ((c == 2 || c == 3) && !isvalidymove(te, y, gsize, i))
return (0);
moveony_tetri(te, y, gsize, i);
}
if (x < 0)
moveonnegx_tetri(te, x, gsize);
else if (x > 0)
moveonposx_tetri(te, x, gsize);
return (1);
}