-
Notifications
You must be signed in to change notification settings - Fork 0
/
fugitive.cc
85 lines (77 loc) · 1.81 KB
/
fugitive.cc
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
#include <queue>
#include "game.hpp"
extern int H, W;
void Fugitive(const char **world, int *action)
{
int **dist_chas, **dist_far;
struct Position chas, fugi, far, pos, npos;
int max_dist, min_dist;
int i, j;
dist_chas = new int *[H];
dist_far = new int *[H];
for (i = 0; i < H; i++)
{
dist_chas[i] = new int[W];
dist_far[i] = new int[W];
}
chas = getPosition(world, CHASER);
fugi = getPosition(world, FUGITIVE);
calcDist(world, dist_chas, chas);
max_dist = 0;
for (i = 0; i < H; i++)
{
for (j = 0; j < W; j++)
{
if (max_dist <= dist_chas[i][j])
{
max_dist = dist_chas[i][j];
far.y = i;
far.x = j;
}
}
}
calcDist(world, dist_far, far);
if (far.y == fugi.y && far.x == fugi.x)
{
*action = -1;
return;
}
min_dist = H * W + 1;
max_dist = -1;
for (i = 0; i < 4; i++)
{
pos.y = fugi.y + dy[i];
pos.x = fugi.x + dx[i];
if (isFree(world, pos) && (min_dist > dist_far[pos.y][pos.x]))
{
min_dist = dist_far[pos.y][pos.x];
}
}
for (i = 0; i < 4; i++)
{
pos.y = fugi.y + dy[i];
pos.x = fugi.x + dx[i];
if (isFree(world, pos) && min_dist == dist_far[pos.y][pos.x] && max_dist <= dist_chas[pos.y][pos.x])
{
max_dist = dist_chas[pos.y][pos.x];
npos = pos;
}
}
switch ((npos.y - fugi.y) * 10 + (npos.x - fugi.x))
{
case 0 * 10 + 1:
*action = 0;
break;
case 1 * 10 + 0:
*action = 1;
break;
case 0 * 10 + -1:
*action = 2;
break;
case -1 * 10 + 0:
*action = 3;
break;
default:
*action = -1;
}
}