10 using namespace __gnu_cxx;
13 Bot::Bot(const string& name, PlayerType type){
17 _playerTypeNames[robber] = "robber";
18 _playerTypeNames[cop_foot] = "cop-foot";
19 _playerTypeNames[cop_car] = "cop-car";
21 _playerTypes["robber"] = robber;
22 _playerTypes["cop-foot"] = cop_foot;
23 _playerTypes["cop-car"] = cop_car;
24 //shortestPath("",robber,SimpleSPGoal(""));
25 //shortestPath("",robber,FindPlayer(hash_map<string,Player>(),robber));
30 cout << "reg: " << _name << " " << _playerTypeNames[_type] << endl;
37 _name = value<string>(input);
38 //cerr << "Got name: " << _name << endl;
42 //cerr << "Got players, building graph." << endl;
46 preGamePreparations();
50 if (input == "game-over")
52 //cerr << input << endl;
53 //cerr << "Updating world" << endl;
55 //cerr << "Done updating world" << endl;
56 _type = _players[_name].type;
57 _location = _players[_name].location;
58 //cerr << "New turn" << endl;
63 //cerr << "Getting information " << endl;
73 //cerr << "Done with turn." << endl;
77 void Bot::getPlayers(){
81 _players[value<string>(input)].type = robber;
83 _players[value<string>(input)].type = cop_foot;
85 _players[value<string>(input)].type = cop_foot;
87 _players[value<string>(input)].type = cop_foot;
89 _players[value<string>(input)].type = cop_foot;
94 ( nod: loc node-tag coordinate coordinate eol )*
97 ( edg: loc loc edge-type eol )*
100 void Bot::buildGraph(){
103 if (input != "nod\\")
106 //cerr << "Getting intersections" << endl;
111 istringstream node(input);
115 Intersection& inter = _intersections[name];
117 if (input == "bank"){
121 else if (input == "hq"){
125 else if (input == "robber-start"){
126 inter.type = robber_start;
127 _robberLocation = name;
130 inter.type = ordinary;
135 //cerr << "Number of intersections: " << _intersections.size() << endl;
138 if (input != "edg\\")
141 //cerr << "Getting streets" << endl;
148 istringstream street(input);
156 //cerr << "Street between: " << from << " and " << to << " of type: " << type << endl;
158 _intersections[from].connections[to] = both;
159 Intersection& inter = _intersections[to];
160 hash_map<string,StreetType>::iterator conn = inter.connections.find(from);
161 if (conn == inter.connections.end())
162 inter.connections[from] = foot;
163 else if (conn->second == car)
164 inter.connections[from] = both;
166 Intersection& inter = _intersections[from];
167 hash_map<string,StreetType>::iterator conn = inter.connections.find(to);
168 if (conn == inter.connections.end())
169 inter.connections[from] = car;
170 else if (conn->second == foot)
171 inter.connections[from] = both;
174 //cerr << "Number of streets: " << streets << endl;
178 void Bot::updateWorld(){
181 _world = value<int>(input);
182 //cerr << "World: " << _world << endl;
185 _robbed = value<int>(input);
186 //cerr << "Robbed: " << _robbed << endl;
193 istringstream dirtyCop(input);
201 istringstream controlledCop(input);
209 istringstream falseAccusation(input);
217 istringstream bank(input);
220 bank >> _banks[input];
222 //cerr << "Number of banks: " << _banks.size() << endl;
229 istringstream evidence(input);
234 _evidence[world] = input;
238 _smell = value<int>(input);
240 _robberLocation = "";
246 istringstream player(input);
249 //cerr << "Player: " << input << endl;
250 Player& pl = _players[input];
251 player >> pl.location;
253 pl.type = _playerTypes[input];
254 if (pl.type == robber)
255 _robberLocation = pl.location;
257 //cerr << "Number of players: " << _players.size() << endl;
261 void Bot::move(std::string location){
262 //cerr << "Moving to: " << location << endl;
263 cout << "mov: " << location << " " << _playerTypeNames[_type] << " " << _name << endl;
267 T value(std::string input){
268 istringstream istr(input);
275 std::string Bot::turn(){
276 //cerr << "Using stupid stand still Bot::turn" << endl;
281 void Bot::sendInformation(){
282 cout << "inf\\" << endl;
283 cout << "inf/" << endl;
286 void Bot::getInformation(){
290 }while(input != "from/");
293 void Bot::sendPlan(){
294 cout << "plan\\" << endl;
295 cout << "plan/" << endl;
298 void Bot::getPlans(){
303 }while(input != "from/");
307 cout << "vote\\" << endl;
308 cout << "vote: " << _name << endl;
309 priority_queue<pair<int,string> > players;
310 for (hash_map<string,int>::const_iterator player = _winningPlans.begin();
311 player != _winningPlans.end(); ++player){
312 players.push(pair<int,string>(-player->second, player->first));
314 while (players.size() > 0){
315 const pair<int,string>& player = players.top();
316 cout << "vote: " << player.second << endl;
317 //cerr << "voted for " << player.second << " with " << player.first << " previously won plans" << endl;
320 cout << "vote/" << endl;
323 void Bot::voteResult(){
326 if (input != "nowinner:"){
327 string winner = value<string>(input);
329 ++_winningPlans[winner];
333 #include "shortestPath.cpp"