-
Notifications
You must be signed in to change notification settings - Fork 0
/
tools.c
109 lines (99 loc) · 2.32 KB
/
tools.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* tools.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dspyrydo <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/07/22 17:51:23 by dspyrydo #+# #+# */
/* Updated: 2017/07/22 19:44:18 by dspyrydo ### ########.fr */
/* */
/* ************************************************************************** */
#include "filler.h"
void clearflf(t_f *flf)
{
int i;
i = 0;
while (i < 1000)
{
flf->bst[i].corx = -1;
flf->bst[i].cory = -1;
flf->bst[i].toenemy = -1;
flf->diffx[i] = 0;
flf->diffy[i++] = 0;
}
flf->bi = 0;
}
void initialize(t_f *flf)
{
flf->x_token = 0;
flf->y_token = 0;
flf->tki = 0;
flf->mpi = 0;
flf->ex = -1;
flf->ey = -1;
}
void substitute(t_f *flf)
{
int i;
int j;
char c;
i = 0;
j = 0;
c = (char)((flf->p == 'O') ? 'O' : 'X');
while (i < flf->x_token)
{
while (j < flf->y_token)
{
if (flf->token[i][j] == '.')
j++;
if (flf->token[i][j] == '*')
flf->token[i][j++] = c;
}
i++;
j = 0;
}
}
void smallmpx(t_f *flf)
{
int tx;
int ty;
if (flf->map[3][3] != 'X')
{
tx = 3 - flf->bst[flf->bi].corx;
ty = 3 - flf->bst[flf->bi].cory;
modulus(&tx, &ty);
flf->bst[flf->bi].toenemy = tx + ty;
}
else
{
tx = 5 - flf->bst[flf->bi].corx;
ty = 16 - flf->bst[flf->bi].cory;
modulus(&tx, &ty);
flf->bst[flf->bi].toenemy = tx + ty;
}
if (flf->bst[flf->bi].toenemy < 0)
flf->bst[flf->bi].toenemy = flf->bst[flf->bi].toenemy * -1;
}
void clearmemory(t_f *flf)
{
int i;
int i2;
i = 0;
i2 = 0;
if (flf->fst % 2 > 0)
{
while (i < flf->mapx)
ft_strdel(&flf->map[i++]);
free(flf->map);
}
else if (flf->fst % 2 == 0 && flf->fst != 0)
{
while (i < flf->mapx)
ft_strdel(&flf->map2[i++]);
free(flf->map2);
}
while (i2 < flf->x_token)
ft_strdel(&flf->token[i2++]);
free(flf->token);
}