-
Notifications
You must be signed in to change notification settings - Fork 0
/
map_check_contain.c
90 lines (82 loc) · 1.92 KB
/
map_check_contain.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* map_check_contain.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kristori <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/09 14:26:30 by kristori #+# #+# */
/* Updated: 2022/11/15 15:12:43 by kristori ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
int ft_map_check_contain(t_program *program)
{
if (ft_map_check_contain_start(program) == 1
&& ft_map_check_contain_collectible(program) == 0
&& ft_map_check_contain_exit(program) == 1)
return (0);
ft_printf("Error\nMap not contain essential value\n");
return (1);
}
int ft_map_check_contain_exit(t_program *program)
{
int k;
int x;
int i;
k = 0;
x = 0;
i = 0;
while (program->map[x] != 0)
{
while (program->map[x][i])
{
if (program->map[x][i] == 'E')
k++;
i++;
}
i = 0;
x++;
}
return (k);
}
int ft_map_check_contain_collectible(t_program *program)
{
int k;
int i;
k = 0;
i = 0;
while (program->map[k] != 0)
{
while (program->map[k][i])
{
if (program->map[k][i] == 'C')
return (0);
i++;
}
i = 0;
k++;
}
return (1);
}
int ft_map_check_contain_start(t_program *program)
{
int k;
int x;
int i;
k = 0;
x = 0;
i = 0;
while (program->map[x] != 0)
{
while (program->map[x][i])
{
if (program->map[x][i] == 'P')
k++;
i++;
}
i = 0;
x++;
}
return (k);
}