-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidpath.c
More file actions
81 lines (74 loc) · 1.82 KB
/
validpath.c
File metadata and controls
81 lines (74 loc) · 1.82 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
/* ************************************************************************** */
/* */
/* :::::::: */
/* validpath.c :+: :+: */
/* +:+ */
/* By: cstaats <cstaats@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2022/11/08 13:49:40 by cstaats #+# #+# */
/* Updated: 2022/11/08 15:17:33 by cstaats ######## odam.nl */
/* */
/* ************************************************************************** */
#include "so_long.h"
void validpath(char **map)
{
int valid;
valid = 0;
while (valid != 1)
{
valid = addp(map);
}
}
char addp(char **map)
{
int x;
int y;
int cntp;
cntp = 0;
y = 0;
while (map[y] != NULL)
{
x = 0;
while (map[y][x] != '\0')
{
if (map[y][x] == 'P')
{
if (map[y - 1][x] == 'E' || map[y + 1][x] == 'E'
|| map[y][x - 1] == 'E' || map[y][x + 1] == 'E')
return (1);
cntp = cntp + placingp(map, x, y);
}
x++;
}
y++;
}
if (cntp == 0)
itsanerror();
return (0);
}
int placingp(char **map, int x, int y)
{
int cntp;
cntp = 0;
if (map[y - 1][x] != '1' && map[y - 1][x] != 'P')
{
map[y - 1][x] = 'P';
cntp++;
}
if (map[y + 1][x] != '1' && map[y + 1][x] != 'P')
{
map[y + 1][x] = 'P';
cntp++;
}
if (map[y][x - 1] != '1' && map[y][x - 1] != 'P')
{
map[y][x - 1] = 'P';
cntp++;
}
if (map[y][x + 1] != '1' && map[y][x + 1] != 'P')
{
map[y][x + 1] = 'P';
cntp++;
}
return (cntp);
}