-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bot.h
108 lines (89 loc) · 3.02 KB
/
Bot.h
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
104
105
106
107
108
#ifndef BOT_H_
#define BOT_H_
#include "State.h"
#include "edt.h"
#include <queue>
#include <vector>
struct Move
{
Move(const Location &l, int d, int s, int c, const std::string &w)
: loc(l), dir(d), score(s), close(c), why(&w) { }
Move(const Move &other)
: loc(other.loc)
, dir(other.dir)
, score(other.score)
, close(other.close)
, why(other.why)
{ }
struct BestScore
{
bool operator () (const Move &lhs, const Move &rhs) const
{
if ((rhs.dir == -1) == (lhs.dir == -1))
return lhs.score > rhs.score;
else
return lhs.dir == -1;
}
};
struct Closest
{
bool operator () (const Move &lhs, const Move &rhs) const
{
if ((rhs.dir == -1) == (lhs.dir == -1))
return lhs.close > rhs.close;
else
return lhs.dir == -1;
}
};
typedef std::priority_queue<Move, std::vector<Move>, BestScore> score_queue;
typedef std::priority_queue<Move, std::vector<Move>, Closest> close_queue;
Location loc;
int dir, score, close;
const std::string *why;
};
/*
This struct represents your bot in the game of Ants
*/
struct Bot
{
int maxVisibleSquares, maxVisibleTurn;
Edt e_food;
Gpath<ForwardBiased<3>, NarrowBusyCost> e_explore;
UniEdt e_push, e_frontline;
Edt e_attack, e_defend;
Gpath<Passable, UnitCost> e_enemies, e_self, e_myHills;
Grid<char> busy;
Grid<bool> combatOccupied;
Grid<bool> enemyThreat, enemyNextThreat, selfThreat;
Grid<int> combatLabels;
LocationSet interesting;
std::vector<Location> hotspots;
int myInitialAnts, myFoodEaten, myDeadAnts, myNewAntTurn;
Grid<bool> maybeEnemies;
Grid<int> tbonus, vbonus;
int amIdead;
std::vector<Location> homeDefense, visionNeighborhood_m1, combatNeighborhood_p1;
Bot();
void playGame(); //plays a single game of Ants
void makeMoves(); //makes moves for a single turn
void endTurn(); //indicates to the engine that it has made its moves
template <typename Predicate>
std::vector<Location> frontier(const Predicate &pred);
Move pickMove(const Location &loc) const;
void visualize();
void combat(Move::close_queue &moves, LocationSet &sessile);
void eat(Move::close_queue &moves, LocationSet &sessile);
void defend(Move::close_queue &moves, LocationSet &sessile);
void pushy();
void territory(Move::close_queue &moves, LocationSet &sessile);
void combatLabel(std::vector<int> &equiv, int &nextLabel, const std::vector<Location> &ants);
std::vector<Location> combatThreat(const std::vector<Location> &ants, const std::vector<Location> &enemies, Grid<bool>& threat);
void combatGroup(Move::close_queue &moves, LocationSet &sessile, const std::vector<Location> &, const std::vector<Location> &);
int hive() const;
void resetHive();
void updateHive();
void maybeInitial();
void maybe();
static Bot *self;
};
#endif //BOT_H_