-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedge_checking.c
79 lines (72 loc) · 2.11 KB
/
edge_checking.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* edge_checking.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fatkeski <fatkeski@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/19 18:34:03 by fatkeski #+# #+# */
/* Updated: 2025/02/19 18:34:04 by fatkeski ### ########.fr */
/* */
/* ************************************************************************** */
#include "./includes/cub3d.h"
int is_edge(int row, int column, t_game *game)
{
if ((row == 0) || (column == 0) || (row == (game->map.height - 1))
|| (column == (game->map.width - 1)))
return (TRUE);
return (FALSE);
}
int is_valid_point(int row, int col, t_game *game)
{
if ((row < 0 || row > (game->map.height - 1) || col < 0
|| col > (game->map.width - 1)))
return (FALSE);
return (TRUE);
}
int check_neighbours(char **map, int row, int col, t_game *game)
{
int col_offset;
int row_offset;
row_offset = -1;
while (row_offset <= 1)
{
col_offset = -1;
while (col_offset <= 1)
{
if (is_valid_point((row + row_offset), (col + col_offset), game))
{
if (!(map[row + row_offset][col + col_offset] == ' ')
&& !(map[row + row_offset][col + col_offset] == '1'))
return (FALSE);
}
col_offset++;
}
row_offset++;
}
return (TRUE);
}
int is_closed_map(t_game *game, char **map)
{
int i;
int j;
i = 0;
while (map[i] != NULL)
{
j = 0;
while (map[i][j] != '\0')
{
if (is_edge(i, j, game))
{
if ((map[i][j] != '1') && (map[i][j] != ' '))
return (FALSE);
}
if (((map[i][j] == ' ')) && (check_neighbours(map, i, j,
game) == FALSE))
return (FALSE);
j++;
}
i++;
}
return (TRUE);
}