-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathis_surface.c
56 lines (51 loc) · 1.82 KB
/
is_surface.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* is_surface.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rvan-der <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/19 18:52:45 by rvan-der #+# #+# */
/* Updated: 2017/02/19 19:30:19 by rvan-der ### ########.fr */
/* */
/* ************************************************************************** */
#include "filler.h"
int is_surface2(t_coord p, t_plateau plt, int sides, int lim)
{
int i;
i = 0;
while ((p.x + i) < (plt.size).x && i <= lim && \
!is_ennemi((plt.map)[p.y][p.x + i], plt.pl))
i++;
if ((p.x + i) < (plt.size).x && i <= lim)
sides++;
i = 0;
while ((p.x - i) >= 0 && i <= lim && \
!is_ennemi((plt.map)[p.y][p.x - i], plt.pl))
i++;
if ((p.x - i) >= 0 && i <= lim)
sides++;
return (sides == 1 ? 1 : 0);
}
int is_surface(t_coord p, t_plateau plt)
{
int i;
int sides;
int lim;
lim = (MAX((plt.size).x, (plt.size).y)) / 6;
lim = (lim < 2 ? 2 : lim);
sides = 0;
i = 0;
while ((p.y + i) < (plt.size).y && i <= lim && \
!is_ennemi((plt.map)[p.y + i][p.x], plt.pl))
i++;
if ((p.y + i) < (plt.size).y && i <= lim)
sides++;
i = 0;
while ((p.y - i) >= 0 && i <= lim && \
!is_ennemi((plt.map)[p.y - i][p.x], plt.pl))
i++;
if ((p.y - i) >= 0 && i <= lim)
sides++;
return (is_surface2(p, plt, sides, lim));
}