-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap5.c
More file actions
96 lines (89 loc) · 2.4 KB
/
Copy pathmap5.c
File metadata and controls
96 lines (89 loc) · 2.4 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* map5.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fracerba <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/05 11:08:24 by fracerba #+# #+# */
/* Updated: 2023/12/05 11:08:26 by fracerba ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
int check_outer_block(t_check *check, int i, int j, int *t)
{
if (check->copy[i][j] == '0' || check->copy[i][j] == '2')
return (print_error(19, 1));
else if (check->copy[i][j] == ' ')
{
check->copy[i][j] = '3';
(*t)++;
}
else if (check->copy[i][j] != '1' && check->copy[i][j] != '3')
{
if (check->copy[i][j] != '4')
return (print_error(15, 1));
}
return (0);
}
int check_map_outer_aux(t_check *check, int i, int j, int *t)
{
if (j != (check->width + 1) && check_outer_block(check, i, j + 1, t))
return (1);
else if (j != 0 && check_outer_block(check, i, j - 1, t))
return (1);
else if (i != (check->height + 1) && check_outer_block(check, i + 1, j, t))
return (1);
else if (i != 0 && check_outer_block(check, i - 1, j, t))
return (1);
check->copy[i][j] = '4';
(*t)--;
return (0);
}
int find_first_space(int *x, int *y, char **copy)
{
int i;
int j;
i = -1;
while (copy[++i])
{
j = -1;
while (copy[i][++j])
{
if (copy[i][j] == ' ')
{
*x = i;
*y = j;
return (1);
}
}
}
return (0);
}
int check_map_outer_borders(t_check *check, int x, int y, int t)
{
int i;
int j;
while (find_first_space(&x, &y, check->copy))
{
check->copy[x][y] = '3';
t = 1;
if (check_map_outer_aux(check, x, y, &t))
return (1);
while (t > 0)
{
i = -1;
while ((++i) < (check->height + 2))
{
j = -1;
while ((++j) < (check->width + 2))
{
if (check->copy[i][j] == '3')
if (check_map_outer_aux(check, i, j, &t))
return (1);
}
}
}
}
return (0);
}