-
Notifications
You must be signed in to change notification settings - Fork 0
/
pushy.cc
55 lines (49 loc) · 1.71 KB
/
pushy.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
#include "Bot.h"
using namespace std;
void Bot::pushy()
{
e_push.update(state.enemyAnts.begin(), state.enemyAnts.end());
UniEdt e_selfToward("toward", e_myHills);
e_selfToward.update(state.myAnts.begin(), state.myAnts.end());
tbonus.fill(0);
for (int row = 0; row < state.rows; ++row) {
for (int col = 0; col < state.cols; ++col) {
if (state.grid[row][col].isWater)
continue;
if (e_push[row][col] < e_selfToward[row][col])
tbonus[row][col] += max(2, min(6, 10 - e_push[row][col]));
if (e_frontline[row][col] < e_selfToward[row][col])
tbonus[row][col] += max(1, min(3, 10 - e_frontline[row][col]));
}
}
Grid<int> diffuse;
for (int i = 0; i < 2; ++i) {
diffuse.fill(0);
for (int row = 0; row < state.rows; ++row) {
for (int col = 0; col < state.cols; ++col) {
if (tbonus[row][col] == 0) {
int total = 0;
for (int d = 0; d < TDIRECTIONS; ++d)
total += tbonus(state.getLocation(Location(row, col), d));
diffuse[row][col] = total / TDIRECTIONS / 2;
} else {
diffuse[row][col] = tbonus[row][col];
}
}
}
tbonus.swap(diffuse);
}
#ifdef VISUALIZER
#if 1
for (uint i = 1; i < 10; ++i) {
int c = 255 - 40 * (i - 1);
state.v.setFillColor(c,c,c,0.5);
for (int row = 0; row < state.rows; ++row)
for (int col = 0; col < state.cols; ++col) {
if (tbonus[row][col] == int(i))
state.v.tile(Location(row,col));
}
}
#endif
#endif
}