-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_choice.c
executable file
·115 lines (105 loc) · 2.38 KB
/
ft_choice.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_choice.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: oltkache <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/03/25 10:12:27 by oltkache #+# #+# */
/* Updated: 2018/03/25 10:12:28 by oltkache ### ########.fr */
/* */
/* ************************************************************************** */
#include "filler.h"
void ft_coor_add(int x, int y, t_coor **coor)
{
t_coor *add;
if (!(*coor))
{
*coor = (t_coor*)malloc(sizeof(t_coor));
(*coor)->next = NULL;
(*coor)->x = x;
(*coor)->y = y;
return ;
}
add = (t_coor*)malloc(sizeof(t_coor));
add->x = x;
add->y = y;
add->next = NULL;
if (add && coor)
{
add->next = *coor;
*coor = add;
}
}
void ft_iter_piece(t_m map, t_c t, t_coor **coor, t_pc piece)
{
int my;
int op;
int i;
int j;
i = -1;
my = 0;
op = 0;
while (++i < piece.x)
{
j = -1;
while (++j < piece.y)
if (piece.p[i][j] == 1)
{
if (ft_ignore_case(map.pl, map.m[t.x + i][t.y + j]))
my += 1;
else if (ft_ignore_case(map.op, map.m[t.x + i][t.y + j]))
op += 1;
}
}
if (my == 1 && op == 0)
ft_coor_add(t.x, t.y, coor);
}
void ft_itarate_map(t_m map, t_coor **coor, t_pc piece)
{
t_c t;
t.x = 0;
while (t.x + piece.x <= map.x)
{
t.y = 0;
while (t.y + piece.y <= map.y)
{
ft_iter_piece(map, t, coor, piece);
++t.y;
}
++t.x;
}
}
int ft_dist(int a, int b)
{
if (a > b)
return (a - b);
return (b - a);
}
void ft_find_best(t_coor *coor, t_coor *opon, t_c *t)
{
int dist;
int d;
t_coor *h1;
t_coor *h2;
t->x = coor->x;
t->y = coor->y;
d = ft_dist(coor->x, opon->x) + ft_dist(coor->y, opon->y);
h1 = coor;
while (h1)
{
h2 = opon;
while (h2)
{
dist = ft_dist(h1->x, h2->x) + ft_dist(h1->y, h2->y);
if (dist <= d)
{
d = dist;
t->x = h1->x;
t->y = h1->y;
}
h2 = h2->next;
}
h1 = h1->next;
}
}