-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_validation.c
72 lines (65 loc) · 1.62 KB
/
ft_validation.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_validation.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yijhuang <yijhuang@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/02 21:56:14 by yijhuang #+# #+# */
/* Updated: 2019/03/02 23:37:33 by yijhuang ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
static int diff(int x, int y)
{
return (((x - y) == 1) || ((y - x) == 1));
}
int check_count(char **p)
{
int i;
int j;
int reg;
i = -1;
reg = 0;
while (p[++i])
{
j = -1;
while (p[i][++j])
{
if (p[i][j] == '#')
reg += 1;
else if (p[i][j] != '.')
ft_error();
}
}
if (reg != 4)
return (0);
return (1);
}
int check_relate(int *x, int *y)
{
int i;
int j;
int reg;
i = -1;
reg = 0;
while (++i < 4)
{
j = -1;
while (++j < 4)
{
reg += relate_two(x[i], y[i], x[j], y[j]);
}
}
if (reg == 6 || reg == 8)
return (1);
return (0);
}
int relate_two(int x1, int y1, int x2, int y2)
{
if (x1 == x2 && diff(y1, y2))
return (1);
else if (y1 == y2 && diff(x1, x2))
return (1);
return (0);
}