-
Notifications
You must be signed in to change notification settings - Fork 0
/
player_o.c
103 lines (96 loc) · 1.6 KB
/
player_o.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
#include "includes/filler.h"
static int check_line(t_info *info, int y, char c)
{
int x;
x = 0;
while (x < info->map_x)
{
if (info->map[y][x] == c || info->map[y][x] == ft_toupper(c))
return (1);
x++;
}
return (0);
}
static int check_enemy_inline(t_info *info)
{
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 (check_line(info, y, 'x') == 1)
return (1);
else
return (0);
}
x--;
}
y--;
}
return (0);
}
static int check_top_line(t_info *info)
{
int x;
x = 0;
while (x < info->map_x)
{
if (info->map[0][x] == info->player)
{
return (1);
}
x++;
}
return (0);
}
int player_o(t_info *info, t_piece *piece)
{
info->fail_place = 0;
if(info->map == 0)
{
if(get_map(info) == 0)
return (0);
get_start_position_enemy(info);
get_start_position_player(info);
}
else
{
if(get_map(info) == 0)
return (0);
}
if(!(get_piece(piece)))
return (0);
if(info->startpoint_player <= info->startpoint_enemy)
{
if (check_enemy_inline(info) == 1 && check_top_line(info) == 0)
place_top_o(info, piece);
else
place_bot_o(info, piece);
if (info->fail_place == 1)
place_bot_o(info, piece);
}
else
{
if (check_enemy_inline(info) == 1 && check_top_line(info) == 0)
place_bot_o(info, piece);
else
place_top_o(info, piece);
if (info->fail_place == 1)
place_bot_o(info, piece);
}
if (info->finish == 1)
{
ft_putnbr(0);
ft_putchar(' ');
ft_putnbr(0);
ft_putchar('\n');
return (0);
}
free_map_piece(info, piece);
return (1);
}