-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_map.c
More file actions
85 lines (76 loc) · 1.87 KB
/
Copy pathcheck_map.c
File metadata and controls
85 lines (76 loc) · 1.87 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* check_map.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kamanfo <kamanfo@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/12/24 16:02:26 by kamanfo #+# #+# */
/* Updated: 2022/01/01 19:51:52 by kamanfo ### ########.fr */
/* */
/* ************************************************************************** */
#include "init_tab.h"
int checkline(char *line)
{
int i;
i = 0;
while (line[i] != '\n' && line[i])
{
if (line[i] != '1')
return (0);
i++;
}
return (1);
}
int checkcol(char **col, int j)
{
int i;
i = 0;
while (col[i])
{
if (col[i][j] != '1' )
return (0);
i++;
}
return (1);
}
int find_elem(char **map, char c)
{
int i;
int j;
int elem;
i = 0;
elem = 0;
while (map[i])
{
j = 0;
while (is_mapset(map[i][j]))
{
if (map[i][j] == c)
elem++;
j++;
}
i++;
}
if (!elem)
return (0);
return (elem);
}
int check_wall(char **map, int height, int width)
{
if (!checkline(map[0]) || !checkline(map[height - 1])
|| !checkcol(map, 0) || !checkcol(map, width - 2))
return (0);
return (1);
}
int check_rules(char **map, int height, int width)
{
if (map == NULL)
return (0);
if (!check_wall(map, height, width))
return (free_map(map), 0);
if (!find_elem(map, 'E') || find_elem(map, 'P') != 1
|| !find_elem(map, 'C'))
return (free_map(map), 0);
return (1);
}