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;
28 cout << "reg: " << _name << " " << _playerTypeNames[_type] << endl;
35 _name = value<string>(input);
36 //cerr << "Got name: " << _name << endl;
40 //cerr << "Got players, building graph." << endl;
44 preGamePreparations();
48 if (input == "game-over")
50 //cerr << input << endl;
51 //cerr << "Updating world" << endl;
53 //cerr << "Done updating world" << endl;
54 _type = _players[_name].type;
55 _location = _players[_name].location;
56 //cerr << "New turn" << endl;
61 //cerr << "Getting information " << endl;
71 //cerr << "Done with turn." << endl;
75 void Bot::getPlayers(){
79 _players[value<string>(input)].type = robber;
81 _players[value<string>(input)].type = cop_foot;
83 _players[value<string>(input)].type = cop_foot;
85 _players[value<string>(input)].type = cop_foot;
87 _players[value<string>(input)].type = cop_foot;
92 ( nod: loc node-tag coordinate coordinate eol )*
95 ( edg: loc loc edge-type eol )*
98 void Bot::buildGraph(){
101 if (input != "nod\\")
104 //cerr << "Getting intersections" << endl;
109 istringstream node(input);
113 Intersection& inter = _intersections[name];
115 if (input == "bank"){
119 else if (input == "hq"){
123 else if (input == "robber-start"){
124 inter.type = robber_start;
125 _robberLocation = name;
128 inter.type = ordinary;
133 //cerr << "Number of intersections: " << _intersections.size() << endl;
136 if (input != "edg\\")
139 //cerr << "Getting streets" << endl;
146 istringstream street(input);
154 //cerr << "Street between: " << from << " and " << to << " of type: " << type << endl;
156 _intersections[from].connections[to] = both;
157 Intersection& inter = _intersections[to];
158 hash_map<string,StreetType>::iterator conn = inter.connections.find(from);
159 if (conn == inter.connections.end())
160 inter.connections[from] = foot;
161 else if (conn->second == car)
162 inter.connections[from] = both;
164 Intersection& inter = _intersections[from];
165 hash_map<string,StreetType>::iterator conn = inter.connections.find(to);
166 if (conn == inter.connections.end())
167 inter.connections[from] = car;
168 else if (conn->second == foot)
169 inter.connections[from] = both;
172 //cerr << "Number of streets: " << streets << endl;
176 void Bot::updateWorld(){
179 _world = value<int>(input);
180 //cerr << "World: " << _world << endl;
183 _robbed = value<int>(input);
184 //cerr << "Robbed: " << _robbed << endl;
191 istringstream dirtyCop(input);
199 istringstream controlledCop(input);
200 controlledCop >> input;
201 controlledCop >> input;
202 _winningPlans.erase(input);
210 istringstream falseAccusation(input);
218 istringstream bank(input);
221 bank >> _banks[input];
223 //cerr << "Number of banks: " << _banks.size() << endl;
230 istringstream evidence(input);
235 _evidence[world] = input;
239 _smell = value<int>(input);
241 _robberLocation = "";
247 istringstream player(input);
250 //cerr << "Player: " << input << endl;
251 Player& pl = _players[input];
252 player >> pl.location;
254 pl.type = _playerTypes[input];
255 if (pl.type == robber)
256 _robberLocation = pl.location;
258 //cerr << "Number of players: " << _players.size() << endl;
262 void Bot::move(std::string location){
263 //cerr << "Moving to: " << location << endl;
264 cout << "mov: " << location << " " << _playerTypeNames[_type] << " " << _name << endl;
268 T value(std::string input){
269 istringstream istr(input);
276 std::string Bot::turn(){
277 //cerr << "Using stupid stand still Bot::turn" << endl;
282 void Bot::sendInformation(){
283 cout << "inf\\" << endl;
284 cout << "inf/" << endl;
287 void Bot::getInformation(){
291 }while(input != "from/");
294 void Bot::sendPlan(){
295 cout << "plan\\" << endl;
296 cout << "plan/" << endl;
299 void Bot::getPlans(){
304 }while(input != "from/");
308 cout << "vote\\" << endl;
309 cout << "vote: " << _name << endl;
310 priority_queue<pair<int,string> > players;
311 for (hash_map<string,int>::const_iterator player = _winningPlans.begin();
312 player != _winningPlans.end(); ++player){
313 players.push(pair<int,string>(-player->second, player->first));
315 while (players.size() > 0){
316 const pair<int,string>& player = players.top();
317 cout << "vote: " << player.second << endl;
318 //cerr << "voted for " << player.second << " with " << player.first << " previously won plans" << endl;
321 cout << "vote/" << endl;
324 void Bot::voteResult(){
327 if (input != "nowinner:"){
328 string winner = value<string>(input);
330 ++_winningPlans[winner];
334 #include "shortestPath.cpp"