-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap_closed.c
101 lines (90 loc) · 2.43 KB
/
map_closed.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* map_closed.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aheinane <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/21 10:05:10 by aheinane #+# #+# */
/* Updated: 2024/10/22 13:19:35 by aheinane ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
int check_top_row_closed(t_textures *textures)
{
int i;
i = 0;
while (textures->map[0][i])
{
if (textures->map[0][i] != '1')
return (0);
i++;
}
return (1);
}
int check_bottom_row_closed(t_textures *textures)
{
int i;
int last_index;
i = 0;
last_index = textures->how_many_lines - 1;
while (textures->map[last_index][i])
{
if (textures->map[last_index][i] != '1')
return (0);
i++;
}
return (1);
}
int check_sides_closed(t_textures *textures, int i)
{
int len_current;
len_current = ft_strlen(textures->map[i]);
if (textures->map[i][0] != '1' || textures->map[i][len_current - 1] != '1')
return (0);
return (1);
}
int check_row_closure(t_textures *textures, int i)
{
int j;
textures->len_current = ft_strlen(textures->map[i]);
textures->len_next = ft_strlen(textures->map[i + 1]);
if (textures->len_current < textures->len_next)
{
j = textures->len_current;
while (j < textures->len_next)
{
if (textures->map[i + 1][j - 1] != '1')
return (0);
j++;
}
}
else if (textures->len_current > textures->len_next)
{
j = textures->len_next;
while (j < textures->len_current)
{
if (textures->map[i][j - 1] != '1')
return (0);
j++;
}
}
return (1);
}
int map_closed(t_textures *textures)
{
int i;
int last_index;
last_index = textures->how_many_lines - 1;
i = 0;
if (!check_top_row_closed(textures) || !check_bottom_row_closed(textures))
return (0);
while (i < last_index)
{
if (!check_sides_closed(textures, i)
|| !check_row_closure(textures, i))
return (0);
i++;
}
return (1);
}