-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGuardAnt.cpp
64 lines (58 loc) · 1.68 KB
/
GuardAnt.cpp
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
#include "GuardAnt.h"
#include "State.h"
GuardAnt::GuardAnt(void)
{
}
GuardAnt::~GuardAnt(void)
{
}
void GuardAnt::chooseMove(State & state)
{
int chosenD = 4;
state.bug << "ant at " << location.row << " " << location.col << ": " << "FoodStrength"
<< state.grid[state.getLocation(location, chosenD).row][state.getLocation(location, chosenD).row].foodStrength << std::endl;
for(int d=0; d<TDIRECTIONS; d++)
{
Location testLoc = state.getLocation(location, d);
Location bestLoc = state.getLocation(location, chosenD);
//state.bug << "ant " << ant << ": "
// << "Row" << testLoc.row << " Col" << testLoc.col << " FoodStrength" << state.grid[testLoc.row][testLoc.col].foodStrength << endl;
if (calculateValue(testLoc, state) > calculateValue(bestLoc, state))
{
chosenD = d;
}
}
if ((chosenD != 4) && state.isSafeMove(location, chosenD))
{
state.makeMove(location, chosenD);
location = state.getLocation(location, chosenD);
}
else if (idleTurns > 3)
{
chosenD = rand() % 4;
if (state.isSafeMove(location, chosenD))
{
state.makeMove(location, chosenD);
location = state.getLocation(location, chosenD);
}
idleTurns++;
}
else
{
idleTurns++;
}
}
int GuardAnt::calculateValue(Location & loc, State & state)
{
int value = 0;
value += state.grid[loc.row][loc.col].foodStrength;
value += state.grid[loc.row][loc.col].enemyHillStrength;
value += state.grid[loc.row][loc.col].unseenStrength;
//value -= state.grid[loc.row][loc.col].myHillStrength / 4;
value += state.grid[loc.row][loc.col].enemyStrength * 2;
if (state.grid[loc.row][loc.col].myHillStrength < 25)
{
value = state.grid[loc.row][loc.col].enemyStrength;
}
return value;
};