-
Notifications
You must be signed in to change notification settings - Fork 0
/
place_x.c
101 lines (93 loc) · 1.45 KB
/
place_x.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
#include "includes/filler.h"
static int cover_piece_right(t_info *info, t_piece *piece, int y, int x)
{
int i;
int j;
i = piece->piece_y - 1;
while (i >= 0)
{
j = piece->piece_x - 1;
while (j >= 0)
{
if (piece->piece[i][j] == '*')
{
if (checkplace(info, piece, x - j, y - i))
{
ft_putnbr(y - i);
ft_putchar(' ');
ft_putnbr(x - j);
ft_putchar('\n');
return (1);
}
}
j--;
}
i--;
}
return (0);
}
static int cover_piece_left(t_info *info, t_piece *piece, int y, int x)
{
int i;
int j;
i = 0;
while (i < piece->piece_y)
{
j = 0;
while (j < piece->piece_x)
{
if (piece->piece[i][j] == '*')
{
if (checkplace(info, piece, x - j, y - i))
{
ft_putnbr(y - i);
ft_putchar(' ');
ft_putnbr(x - j);
ft_putchar('\n');
return (1);
}
}
j++;
}
i++;
}
return (0);
}
void place_top_x(t_info *info, t_piece *piece)
{
int y;
int x;
y = 0;
while (y < info->map_y)
{
x = 0;
while (x < info->map_x)
{
if (info->map[y][x] == info->player)
if (cover_piece_right(info, piece, y, x) == 1)
return ;
x++;
}
y++;
}
info->finish = 1;
}
void place_bot_x(t_info *info, t_piece *piece)
{
int y;
int x;
y = info->map_y - 1;
while (y > 0)
{
x = info->map_x - 1;
while (x > 0)
{
if (info->map[y][x] == info->player)
if (cover_piece_left(info, piece, y, x) == 1)
return ;
x--;
}
y--;
}
info->fail_place = 1;
}