-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_parsing_check.c
70 lines (62 loc) · 1.82 KB
/
ft_parsing_check.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_parsing_check.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: spopieul <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/01/09 17:16:30 by spopieul #+# #+# */
/* Updated: 2018/01/09 17:20:43 by spopieul ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
int ft_horizontal_sum(char *tetriminos, int i)
{
int right;
int left;
right = (i + 1) <= 16 ? tetriminos[i + 1] == '#' : 0;
left = (i - 1) >= 0 ? tetriminos[i - 1] == '#' : 0;
return (right + left);
}
int ft_vertical_sum(char *tetriminos, int i)
{
int top;
int bottom;
top = (i - 4) >= 0 ? tetriminos[i - 4] == '#' : 0;
bottom = (i + 4) <= 16 ? tetriminos[i + 4] == '#' : 0;
return (top + bottom);
}
int ft_is_valid_tetriminos(char *tetriminos)
{
int i;
int hash_count;
int sum;
i = 0;
hash_count = 0;
sum = 0;
while (tetriminos[i] != '\0')
{
if (tetriminos[i] == '#')
{
hash_count++;
sum += ft_vertical_sum(tetriminos, i);
sum += ft_horizontal_sum(tetriminos, i);
}
i++;
}
if (hash_count != 4)
return (0);
return (sum >= 6);
}
int ft_check_line(char *line)
{
if (ft_strlen(line) != 4)
return (0);
while (*line)
{
if (*line != '.' && *line != '#')
return (0);
line++;
}
return (1);
}