-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile_checker.c
133 lines (123 loc) · 2.36 KB
/
file_checker.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
129
130
131
132
133
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* file_checker.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vroussea <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/01/10 19:12:40 by vroussea #+# #+# */
/* Updated: 2016/01/14 22:17:34 by vroussea ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
#include "libft.h"
int check_symbols(char *buf, int size)
{
while (size > 0)
{
size--;
if ((buf[size] != '.') && (buf[size] != '#') && (buf[size] != '\n'))
return (0);
}
return (1);
}
int check_size(char *buf, int size)
{
int squ_x;
int squ_y;
while (size >= 0)
{
size--;
squ_y = 0;
while (squ_y < 4)
{
squ_x = 0;
if (buf[size] != '\n')
return (0);
while (squ_x < 4)
{
size--;
if (size < 0 || buf[size] == '\n')
return (0);
squ_x++;
}
squ_y++;
size--;
}
}
return (1);
}
int check_size_tetri(char **tetri)
{
int i;
int j;
int size;
i = 0;
size = 0;
while (i < 4)
{
j = 0;
while (j < 4)
{
if (tetri[i][j] == '#')
size++;
j++;
}
i++;
}
if (size == 4)
return (1);
return (0);
}
int check_next(char **tetri)
{
int i;
int j;
int valid;
i = 0;
valid = 0;
while (i < 4)
{
j = 0;
while (j < 4)
{
if (tetri[i][j] == '#')
{
if (j < 3 && tetri[i][j + 1] == '#')
valid++;
if (i < 3 && tetri[i + 1][j] == '#')
valid++;
}
j++;
}
i++;
}
if ((valid = valid + check_next2(tetri)) < 5)
return (0);
return (1);
}
int check_next2(char **tetri)
{
int i;
int j;
int valid;
i = 3;
valid = 0;
while (i >= 0)
{
j = 3;
while (j >= 0)
{
if (tetri[i][j] == '#')
{
if (j > 0 && tetri[i][j - 1] == '#')
valid++;
if (i > 0 && tetri[i - 1][j] == '#')
valid++;
}
j--;
}
i--;
}
return (valid);
}