forked from albertz/planet_wars-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BotExampleRage.cpp
48 lines (45 loc) · 1.17 KB
/
BotExampleRage.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
#include <iostream>
#include "game.h"
static void DoTurn(const Game& pw) {
typedef std::vector<Planet> Planets;
Planets myPlanets = pw.MyPlanets();
Planets enemyPlanets = pw.EnemyPlanets();
for (Planets::iterator source = myPlanets.begin(); source != myPlanets.end(); ++source) {
if (source->numShips < 10 * source->growthRate) {
continue;
}
int dest = -1;
int bestDistance = 999999;
for (Planets::iterator p = enemyPlanets.begin(); p != enemyPlanets.end(); ++p) {
int dist = pw.desc.Distance(source->planetId, p->planetId);
if (dist < bestDistance) {
bestDistance = dist;
dest = p->planetId;
}
}
if (dest >= 0) {
pw.IssueOrder(source->planetId, dest, source->numShips);
}
}
}
int main(int argc, char *argv[]) {
std::string current_line;
std::string map_data;
while (true) {
int c = std::cin.get();
current_line += (char)c;
if (c == '\n') {
if (current_line.length() >= 2 && current_line.substr(0, 2) == "go") {
Game game;
game.ParseGameState(map_data);
map_data = "";
DoTurn(game);
game.FinishTurn();
} else {
map_data += current_line;
}
current_line = "";
}
}
return 0;
}