-
Notifications
You must be signed in to change notification settings - Fork 0
/
piece_util.c
98 lines (89 loc) · 2.21 KB
/
piece_util.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* piece_util.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: asarandi <asarandi@student.42.us.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/12/27 17:28:03 by asarandi #+# #+# */
/* Updated: 2017/12/27 17:28:27 by asarandi ### ########.fr */
/* */
/* ************************************************************************** */
#include "filler.h"
int piece_minify(void)
{
int i;
int j;
int k;
i = g_piece_top_extra;
k = 0;
while (i < g_piece_height - g_mini_bottom)
{
j = g_piece_left_extra;
while (j < g_piece_width - g_mini_right)
{
g_mini[k] = g_piece[i * g_piece_width + j];
j++;
k++;
}
i++;
}
return (1);
}
int trim_piece(void)
{
int i;
i = 0;
while ((i < g_piece_height) && (trim_piece_top(i)))
i++;
g_piece_top_extra = i;
i = 0;
while ((i < g_piece_width) && (trim_piece_left(i)))
i++;
g_piece_left_extra = i;
if ((g_mini = ft_memalloc(g_piece_width * g_piece_height + 1)) == NULL)
return (0);
g_mini_bottom = mini_bottom_extra();
g_mini_right = mini_right_extra();
g_mini_height = (g_piece_height - g_piece_top_extra - g_mini_bottom);
g_mini_width = (g_piece_width - g_piece_left_extra - g_mini_right);
piece_minify();
return (1);
}
int plateau_slice(char *plateau)
{
int i;
int j;
int k;
i = 0;
k = g_mini_width;
while (i < g_mini_height)
{
j = 0;
while ((j < k) && (plateau[(i * g_plateau_width) + j]))
{
g_slice[(i * k) + j] = plateau[(i * g_plateau_width) + j];
j++;
}
i++;
}
return (1);
}
int count_adjacent(char *slice)
{
char c;
int i;
int count;
c = 'X';
if (g_player == '1')
c = 'O';
i = 0;
count = 0;
while (slice[i])
{
if (slice[i] == c)
count++;
i++;
}
return (count);
}