-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_the_map.c
More file actions
130 lines (121 loc) · 2.89 KB
/
check_the_map.c
File metadata and controls
130 lines (121 loc) · 2.89 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
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* check_the_map.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: havyilma <havyilma@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/15 19:57:50 by havyilma #+# #+# */
/* Updated: 2023/03/25 07:20:14 by havyilma ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
void ft_read_map(char *av, t_settings *set)
{
int i;
int fd;
i = 1;
set->map = malloc((set->map_height + 1) * sizeof(char *));
fd = open(av, O_RDONLY);
set->map[0] = get_next_line(fd);
if (set->map[0] == NULL)
{
write(1, "ERROR!", 6);
exit(0);
}
while (i < set->map_height)
{
set->map[i] = get_next_line(fd);
i++;
}
set->map[i] = NULL;
close(fd);
ft_copy_map(av, set);
}
void what_the_height(char *av, t_settings *map)
{
int fd;
int i;
char *temp;
i = 0;
fd = open(av, O_RDONLY);
temp = get_next_line(fd);
while (temp)
{
free(temp);
temp = get_next_line(fd);
i++;
}
close(fd);
map->map_height = i;
}
void what_the_width(t_settings *set)
{
int size;
int i;
i = 1;
size = ft_strlen(set->map[0]) - 1;
while (i < set->map_height - 2)
{
if (size != ft_strlen(set->map[i]) - 1)
return ;
i++;
}
if (i == set->map_height - 2)
{
if (!(size != ft_strlen(set->map[i])))
return ;
set->map_width = size;
}
}
int ft_control_epc(t_settings *set, int i, int j, int check_p)
{
while (++i <= set->map_height - 1)
{
while (++j <= set->map_width - 1)
{
if (set->img_ch[i][j] == 'E')
set->count_e++;
if (set->img_ch[i][j] == 'P')
check_p++;
if (set->img_ch[i][j] == 'C')
set->check_coll++;
if (set->img_ch[i][j] != '1' && set->img_ch[i][j] != '0'
&& set->img_ch[i][j] != 'P' &&
set->img_ch[i][j] != 'E' && set->img_ch[i][j] != 'C'
&& set->img_ch[i][j] != '\n')
{
write(1, "ERROR! Wrong parameter!", 23);
return (0);
}
}
j = -1;
}
if (set->count_e != 1 || set->check_coll < 1 || check_p != 1)
return (0);
return (1);
}
int ft_check_edge(t_settings *set, int i, int j)
{
while (j < set->map_width)
{
if (set->img_ch[0][j] != '1')
return (0);
j++;
}
j = 0;
while (i < set->map_height)
{
while (j < set->map_width)
{
if (set->img_ch[set->map_height - 1][j] != '1'
|| set->img_ch[i][set->map_width - 1] != '1'
|| set->img_ch[i][0] != '1')
return (0);
j++;
}
j = 0;
i++;
}
return (1);
}