-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBot.h
More file actions
189 lines (156 loc) · 4.73 KB
/
Bot.h
File metadata and controls
189 lines (156 loc) · 4.73 KB
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#ifndef BOT_H_
#define BOT_H_
#include "State.h"
#include <list>
#include <limits>
#include <iostream>
#include <stdio.h>
#include <cstdlib>
#include <cmath>
#include <iterator>
#ifdef _WIN64
# include <memory>
#elif _WIN32
# include <memory>
#else
# include <tr1/memory>
#endif
namespace calc
{
struct Path
{
Location* start;
Location* dest;
long long cost;
unsigned int turn_counter;
bool turn_visited;
t_location_deque nodes;
static int astar_obreak;
static int astar_cbreak;
bool searchFood, searchHill, searchUnseen;
Path()
: start( 0 )
, dest( 0 )
, cost(std::numeric_limits<unsigned int>::max())
, turn_counter(0)
, turn_visited(false)
, searchFood(false)
, searchHill(false)
, searchUnseen(false)
{}
Path(
Location* s
, Location* d
, State &state
, bool exact = false );
Path( const Path & p)
: start(p.start)
, dest(p.dest)
, cost(p.cost)
, turn_counter(p.turn_counter)
, turn_visited(p.turn_visited)
, nodes(p.nodes)
, searchFood(p.searchFood)
, searchHill(p.searchHill)
, searchUnseen(p.searchUnseen)
{
}
Path& operator=(const Path & p)
{
start = p.start;
dest = p.dest;
cost = p.cost;
turn_counter = p.turn_counter;
turn_visited = p.turn_visited;
nodes = p.nodes;
searchFood = p.searchFood;
searchHill = p.searchHill;
searchUnseen = p.searchUnseen;
return *this;
}
bool operator>( const Path & rhs ) const
{ return cost > rhs.cost; }
bool operator<( const Path & rhs ) const
{ return cost < rhs.cost; }
inline bool operator==( const Location *l ) const
{ return start == l; }
bool astar(State &state);
inline void fill_nodes( t_location_deque &olist )
{
Location *v(olist.front());
while(v->prev)
{
nodes.push_front(v);
v = v->prev;
}
}
};
typedef std::vector<Path> t_order;
inline std::ostream& operator<<(std::ostream &os, const calc::Path &p)
{
if (p.start)
os << *p.start << "/";
if (p.dest)
os << *p.dest;
for(t_location_deque::const_iterator
itb(p.nodes.begin())
, ite(p.nodes.end())
; itb!=ite
; ++itb)
if (*itb)
os << "->" << **itb ;
return os;
}
}
/*
This struct represents your bot in the game of Ants
*/
struct Bot
{
State state;
Ann ann_out;
calc::t_order orders;
Bot();
void playGame(); //plays a single game of Ants
void makeMoves(); //makes moves for a single turn
int makeMoves(Location* loc, calc::t_order::iterator& o, bool exact = false);
void sort_all();
void sort_one( t_location_vector &to_sort_vector, Location & top_left );
bool preMakeMoves(calc::t_order::iterator &o, Location * loc);
void postMakeMoves(calc::Path & p, Location * ant);
void endTurn(); //indicates to the engine that it has made its moves
Location * closest_food(const Location &loc);
Location * closest_hill(const Location &loc);
Location * closest_enemy(const Location &loc);
Location * closest_ant(const Location &loc);
Location * closest_ant_for_reverse(const Location &loc);
inline void fill_suround( t_location_vector &suround, const Location & loc )
{
suround.reserve(24);
suround.push_back(state.getLocation(loc, e_north));
suround.push_back(state.getLocation(*suround.back(), e_east));
suround.push_back(state.getLocation(*suround.back(), e_south));
suround.push_back(state.getLocation(*suround.back(), e_south));
suround.push_back(state.getLocation(*suround.back(), e_west));
suround.push_back(state.getLocation(*suround.back(), e_west));
suround.push_back(state.getLocation(*suround.back(), e_north));
suround.push_back(state.getLocation(*suround.back(), e_north));
suround.push_back(state.getLocation(*suround.back(), e_north));
suround.push_back(state.getLocation(*suround.back(), e_east));
suround.push_back(state.getLocation(*suround.back(), e_east));
suround.push_back(state.getLocation(*suround.back(), e_east));
suround.push_back(state.getLocation(*suround.back(), e_south));
suround.push_back(state.getLocation(*suround.back(), e_south));
suround.push_back(state.getLocation(*suround.back(), e_south));
suround.push_back(state.getLocation(*suround.back(), e_south));
suround.push_back(state.getLocation(*suround.back(), e_west));
suround.push_back(state.getLocation(*suround.back(), e_west));
suround.push_back(state.getLocation(*suround.back(), e_west));
suround.push_back(state.getLocation(*suround.back(), e_west));
suround.push_back(state.getLocation(*suround.back(), e_north));
suround.push_back(state.getLocation(*suround.back(), e_north));
suround.push_back(state.getLocation(*suround.back(), e_north));
suround.push_back(state.getLocation(*suround.back(), e_north));
}
};
#endif //BOT_H_