-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_check_tetr.c
51 lines (48 loc) · 1.51 KB
/
ft_check_tetr.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_check_tetr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: itiievsk <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/03/29 15:54:38 by itiievsk #+# #+# */
/* Updated: 2018/03/29 17:56:59 by itiievsk ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
static void get_touches(char *s, int p[], int i)
{
if (s[i - 1] == '#')
p[7]++;
if (s[i - 5] == '#')
p[7]++;
if (s[i + 1] == '#')
p[7]++;
if (s[i + 5] == '#')
p[7]++;
}
void ft_check_tetr(char *s, int p[], int i, int x)
{
while (s[i] != '\0')
{
if (i % 21 == 0)
{
x = 0;
p[5] = 0;
p[7] = 0;
}
if (s[i] == '#')
{
if (s[i - 1] != '#' && s[i + 1] != '#' && (s[i - 5] != '#'
|| (s[i - 5] == '#' && x - 5 < 0)) && (s[i + 5] != '#'
|| (s[i + 5] == '#' && x + 5 > 19)))
ft_quit(s, p);
get_touches(s, p, i);
p[5]++;
if (p[5] == 4 && p[7] < 6)
ft_quit(s, p);
}
i++;
x++;
}
}