-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexpansion.h
230 lines (141 loc) · 7.1 KB
/
expansion.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
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
/*
static bool operator<(const LocationScore& lsc1, const LocationScore& lsc2) {
return (lsc1.score < lsc2.score);
}
/*
void bfs(hlt::GameMap presentMap, int* scoreMap, std::queue<hlt::Location> queue, unsigned char myID) {
//BFS - Momentan incomplet(cred), trb analizat faza cu minimul casutelor / sau nu trb deaorece verifica daca e 0 la inceput
while(!queue.empty()) {
hlt::Location site = queue.front();
queue.pop();
for(unsigned char i = 1; i < 5; i++) {
const hlt::Site neighborSite = presentMap.getSite({ site.x, site.y}, i);
const hlt::Location neighborLocation = presentMap.getLocation({ site.x, site.y}, i);
if((neighborSite.owner == myID) && (scoreMap[neighborLocation.y * neighborLocation.x + neighborLocation.x] == 0)) {
scoreMap[neighborLocation.y * neighborLocation.x + neighborLocation.x] = scoreMap[site.y * site.x + site.x] + 1;
queue.push({neighborLocation.x, neighborLocation.y});
}
}
}
}
*/
struct Square {
hlt::Location location;
hlt::Site site;
};
void expansionStrategy(hlt::GameMap &presentMap, std::set<hlt::Move> &moves, unsigned char myID) {
//Debug file
//std::ofstream output("Score.txt");
std::queue<hlt::Location> queue;
std::list<Square> borders;
std::list<std::pair<hlt::Location, unsigned char>> attackers;
int scoreMap[presentMap.height][presentMap.width];
int movesMap[presentMap.height][presentMap.width];
int numberOfSquares = presentMap.height * presentMap.width + 1;
//nu reinitializa linia 0 din anumite motive
//int scoreMap[presentMap.width][presentMap.height] = {0};
//Resets Scoremap
for(unsigned short a = 0; a < presentMap.height; a++) {
for(unsigned short b = 0; b < presentMap.width; b++) {
scoreMap[a][b] = 0;
movesMap[a][b] = 0;
}
}
for(unsigned short a = 0; a < presentMap.height; a++) {
for(unsigned short b = 0; b < presentMap.width; b++) {
if(presentMap.getSite({ b, a }).owner == myID) {
//unsigned char plm = sendBotTo({ b, a }, {0, 0}, presentMap);
//moves.insert({{b, a}, plm});
for(unsigned char i = 1; i < 5; i++) {
const hlt::Site neighborSite = presentMap.getSite({ b, a }, i);
//Finding the borders
if(neighborSite.owner != myID) {
const hlt::Location neighborLocation = presentMap.getLocation({ b, a }, i);
scoreMap[neighborLocation.y][neighborLocation.x] = 1;
queue.push({neighborLocation.x, neighborLocation.y});
borders.push_front({{neighborLocation.x, neighborLocation.y}, neighborSite});
}
}
}
}
}
//BFS - Momentan incomplet(cred), trb analizat faza cu minimul casutelor / sau nu trb deaorece verifica daca e 0 la inceput
while(!queue.empty()) {
hlt::Location borderLocation = queue.front();
queue.pop();
for(unsigned char i = 1; i < 5; i++) {
const hlt::Site neighborSite = presentMap.getSite({ borderLocation.x, borderLocation.y}, i);
const hlt::Location neighborLocation = presentMap.getLocation({ borderLocation.x, borderLocation.y}, i);
if((neighborSite.owner == myID) && (scoreMap[neighborLocation.y][neighborLocation.x] == 0)) {
scoreMap[neighborLocation.y][neighborLocation.x] = scoreMap[borderLocation.y][borderLocation.x] + 1;
queue.push(neighborLocation);
}
}
}
/*
int sum = 0;
while(!borders.empty()) {
Square bot = borders.front();
borders.pop_front();
for(unsigned char i = 1; i < 5; i++) {
const hlt::Site neighborSite = presentMap.getSite({bot.location.x, bot.location.y}, i);
const hlt::Location neighborLocation = presentMap.getLocation({bot.location.x, bot.location.y}, i);
if(myID == neighborSite.owner) {
sum += neighborSite.strength;
attackers.push_front(std::make_pair(neighborLocation, i));
if(sum > bot.site.strength) {
while(!attackers.empty()) {
std::pair<hlt::Location, unsigned char> attackPosition = attackers.front();
hlt::Location attackerLocation = attackPosition.first;
unsigned char dir = attackPosition.second;
attackers.pop_front();
output << "Uite sumabahahahahahaha \n" << sum;
moves.insert({{attackerLocation.y, attackerLocation.x}, reverseCardinal(dir)});
movesMap[attackerLocation.y][attackerLocation.x] = 1;
}
break;
}
}
}
sum = 0;
}
*/
/*
output << "After doing them bfs\n";
for(unsigned short a = 0; a < presentMap.height; a++) {
for(unsigned short b = 0; b < presentMap.width; b++) {
output << scoreMap[a][b] << " ";
}
output << '\n';
}
output << '\n';
*/
for(unsigned short a = 0; a < presentMap.height; a++) {
for(unsigned short b = 0; b < presentMap.width; b++) {
if((presentMap.getSite({ b, a }).owner == myID) && (movesMap[b][a] == 0)) {
const hlt::Site currentSite = presentMap.getSite({ b, a });
if(currentSite.strength > 5 * currentSite.production) {
int minScore = numberOfSquares;
unsigned char dir = 0;
//We should always make it to check first points of interest - atm it prioritises to go to the WEST, because of the for startiing from 1 to 5
//and because in the if has >= so when all neighbors are good, it will go to the WEST
//for future we will want different directions prioritization
for(unsigned char i = 1; i < 5; i++) {
const hlt::Location neighborLocation = presentMap.getLocation({ b, a}, i);
if(minScore >= scoreMap[neighborLocation.y][neighborLocation.x]) {
minScore = scoreMap[neighborLocation.y][neighborLocation.x];
dir = i;
}
}
if(myID != presentMap.getSite({b, a}, dir).owner) {
if(currentSite.strength >= presentMap.getSite({b, a}, dir).strength) {
moves.insert({ { b, a} , dir});
}
} else {
moves.insert({ { b, a} , dir});
}
}
}
}
}
}