/
MyBot.cpp
112 lines (83 loc) · 2.56 KB
/
MyBot.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
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
#include<iostream>
#include<string>
#include<sstream>
#include<fstream>
#include<cstdlib>
#include<unordered_map>
#include<ctime>
#include<sys/time.h>
#include"base.hh"
#include"helpers.hh"
std::hash<unsigned long long> std::hash<pos>::ull_hasher;
std::ofstream logStream;
bool vdebug=false;
int elapsedTime(timeval& start, timeval& end){
return (end.tv_sec-start.tv_sec)*1000+(end.tv_usec-start.tv_usec)/1000.0+0.5;
}
int main(int argc, char**){
srand(time(NULL));
#ifdef VDEBUG
if(argc>1) vdebug=true;
#endif
timeval startTime, endTime;
std::cout.sync_with_stdio(0);
std::unordered_map<std::string, int> gameParams;
std::istringstream istream;
std::string oneLine, tmpString;
while(std::getline(std::cin, oneLine)){
int paramValue;
istream.clear();
istream.str(oneLine);
istream >> tmpString >> paramValue;
if(tmpString=="ready") break;
gameParams[tmpString] = paramValue;
}
_gameData gameData(gameParams["rows"],
gameParams["cols"],
gameParams["viewradius2"],
gameParams["attackradius2"]);
go();
while(std::getline(std::cin, oneLine)){
gettimeofday(&startTime, NULL);
istream.clear();
istream.str(oneLine);
istream >> tmpString;
LOG("turn: " << gameData.turn);
if(tmpString=="end"){break;};
gameData.perTurnReset();
while(getline(std::cin, oneLine)){
istream.clear();
istream.str(oneLine);
pos f1f2;
int f3=-1;
istream >> tmpString >> f1f2.row >> f1f2.col >> f3;
if(tmpString=="go") break;
if(tmpString=="a"){gameData.receiveAnt(f1f2, f3); continue;};
if(tmpString=="w"){gameData.receiveWater(f1f2); continue;};
if(tmpString=="f"){gameData.receiveFood(f1f2); continue;};
if(tmpString=="h"){gameData.receiveHill(f1f2, f3); continue;};
}
gameData.processAnts();
gameData.processFood();
gameData.processHills();
gameData.assocFoodWithAnt();
if(gameData.ant_count_water_mark>15){
gameData.captureEnemyHills();
}
gameData.clusterAnts();
gameData.computeClusterPrioritiesAndDispatch();
gameData.computeThreat();
gameData.reachEnemy();
gameData.wanderAntsAroundCompositeMod();
if(vdebug){
gameData.debugDraw();
gameData.toPPM();
}
gameData.keepHillInSightOverride();
gameData.outputCoordinates();
gettimeofday(&endTime, NULL);
LOG("turn took " << elapsedTime(startTime, endTime) << "ms");
go();
}
return 0;
}