-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwalls_checker.c
More file actions
114 lines (104 loc) · 2.32 KB
/
Copy pathwalls_checker.c
File metadata and controls
114 lines (104 loc) · 2.32 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* walls_checker.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ychedmi <ychedmi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/15 16:48:42 by ychedmi #+# #+# */
/* Updated: 2025/03/15 16:50:42 by ychedmi ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
int lenmap(t_list *p)
{
t_list *head;
head = p;
while (head)
{
p = head->next;
while (p)
{
if (ft_len(p->data) != ft_len(head->data))
return (1);
p = p->next;
}
head = head->next;
}
return (0);
}
int first_wall(t_list *map)
{
int i;
i = 0;
while (map->data[i] == '1')
{
if (map->data[i + 1] == '\n')
return (0);
i++;
}
return (1);
}
int last_wall(t_list *map)
{
int i;
i = 0;
map = ft_lstlast(map);
while (map->data[i] && map->data[i] == '1')
{
if (!map->data[i + 1] || map->data[i + 1] == '\n')
return (0);
i++;
}
return (1);
}
int else_walls(t_list *map)
{
int i;
int j;
j = 0;
i = 0;
map = map->next;
while (map && map->next)
{
if (map->data[0] == '1')
{
i = 0;
while (map->data[i])
{
if (map->data[i] != '1' && map->data[i + 1] == '\n')
return (1);
i++;
}
}
else
return (1);
j++;
map = map->next;
}
return (0);
}
int walls(t_list *map)
{
if (lenmap(map) == 1)
{
write(2, "Error\n", 6);
return (write (2, "The map is not rectangular !\n", 30), 1);
}
else if (first_wall(map) == 1)
{
write(2, "Error\n", 6);
return (write (2, "The upper wall is broken !\n", 28), 1);
}
else if (last_wall(map) == 1)
{
write(2, "Error\n", 6);
return (write (2, "The bottom wall is broken !\n", 29), 1);
}
else if (else_walls(map) == 1)
{
write(2, "Error\n", 6);
return (write(2, "The side wall is broken !\n", 27), 1);
}
return (0);
}