-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_check_errors.c
121 lines (111 loc) · 2.38 KB
/
ft_check_errors.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_check_errors.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ikgonzal <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/12/03 10:51:47 by ikgonzal #+# #+# */
/* Updated: 2021/12/13 18:08:35 by ikgonzal ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
void ft_check_perimeter(t_data *m)
{
int row;
int col;
row = 0;
while (row < m->row_len)
{
col = 0;
while (col < m->col_len)
{
if (m->map[0][col] != '1' || m->map[m->row_len - 1][col] != '1')
{
write(1, "Error\n", 6);
exit (0);
}
else if (m->map[row][0] != '1'
|| m->map[row][m->col_len - 1] != '1')
{
write (1, "Error\n", 6);
exit (0);
}
col++;
}
row++;
}
}
void ft_check_values3(t_data *m, int row)
{
int col;
while (row < m->row_len)
{
col = 0;
while (col < m->col_len)
{
if (m->map[row][col] != '0' && m->map[row][col] != '1'
&& m->map[row][col] != 'C' && m->map[row][col] != 'P'
&& m->map[row][col] != 'E')
{
write(1, "Error\n", 6);
exit (0);
}
col++;
}
row++;
}
}
void ft_check_values2(t_data *m, int row)
{
int col;
int p;
p = 0;
while (row < m->row_len)
{
col = 0;
while (col < m->col_len)
{
if (m->map[row][col] == 'P')
p++;
col++;
}
row++;
}
if (p > 1)
{
write (1, "Error\n", 6);
exit (0);
}
}
void ft_check_values1(t_data *m, int row)
{
int e;
int col;
e = 0;
while (row < m->row_len)
{
col = 0;
while (col < m->col_len)
{
if (m->map[row][col] == 'C')
m->c++;
else if (m->map[row][col] == 'E')
e++;
col++;
}
row++;
}
if (e > 1 || m->c < 1)
{
write (1, "Error\n", 6);
exit (0);
}
}
void ft_check_errors(t_data *mlx)
{
ft_check_perimeter(mlx);
ft_check_values1(mlx, 0);
ft_check_values2(mlx, 0);
ft_check_values3(mlx, 0);
}