-
Notifications
You must be signed in to change notification settings - Fork 0
/
valid_shape.c
113 lines (104 loc) · 2.23 KB
/
valid_shape.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* valid_shape.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mschroed <mschroed@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/12/31 19:03:31 by mschroed #+# #+# */
/* Updated: 2019/01/08 17:20:31 by mschroed ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
#include <libft.h>
int hash_per(char **coord)
{
int i;
int j;
i = 0;
while (coord[i])
{
j = 0;
while (coord[i][j])
{
if (coord[i][j] != '#' && coord[i][j] != '.')
return (0);
j++;
}
i++;
}
return (1);
}
int hash_num(char **coord)
{
int i;
int j;
int hash;
int per;
i = 0;
hash = 0;
per = 0;
while (coord[i])
{
j = 0;
while (coord[i][j])
{
if (coord[i][j] == '#')
hash++;
if (coord[i][j] == '.')
per++;
j++;
}
i++;
}
return (hash == 4 && per == 12);
}
int six_eight(char **coord)
{
int i;
int j;
int cnct;
i = -1;
cnct = 0;
while (coord[++i] != '\0')
{
j = -1;
while (coord[i][++j] != '\0')
{
if (coord[i][j] == '#')
{
if ((j + 1) <= 3 && coord[i][j + 1] == '#')
cnct++;
if ((j - 1) >= 0 && coord[i][j - 1] == '#')
cnct++;
if ((i + 1) <= 3 && coord[i + 1][j] == '#')
cnct++;
if ((i - 1) >= 0 && coord[i - 1][j] == '#')
cnct++;
}
}
}
return (cnct == 8 || cnct == 6);
}
int val_mino(t_mino *head)
{
t_mino *vald;
int id;
id = 0;
vald = head;
while (vald != NULL)
{
if (id >= 26)
return (-1);
if (hash_per(vald->crd) == 0)
return (-1);
if (hash_num(vald->crd) == 0)
return (-1);
if (six_eight(vald->crd) == 0)
return (-1);
vald = cuter(vald, id);
vald = vald->next;
id++;
}
return (0);
}