9 using namespace __gnu_cxx;
11 Bot::Bot(string name, string type){
17 cout << "reg: " << _name << " " << _type << endl;
24 _name = value<string>(input);
25 cerr << "Got name: " << _name << endl;
29 _players[value<string>(input)].type = "robber";
31 _players[value<string>(input)].type = "cop-foot";
33 _players[value<string>(input)].type = "cop-foot";
35 _players[value<string>(input)].type = "cop-foot";
37 _players[value<string>(input)].type = "cop-foot";
39 cerr << "Got players, building graph." << endl;
46 if (input == "game-over")
49 _type = _players[_name].type;
50 _location = _players[_name].location;
52 cerr << "New turn" << endl;
54 cerr << "Done with turn." << endl;
63 ( nod: loc node-tag coordinate coordinate eol )*
66 ( edg: loc loc edge-type eol )*
69 void Bot::buildGraph(){
75 cerr << "Getting intersections" << endl;
80 istringstream node(input);
83 Intersection& inter = _intersections[input];
89 cerr << "Number of intersections: " << _intersections.size() << endl;
95 cerr << "Getting streets" << endl;
102 istringstream street(input);
110 cerr << "Street between: " << from << " and " << to << " of type: " << type << endl;
112 _intersections[from].connections[to] = both;
113 Intersection& inter = _intersections[to];
114 if (inter.connections.find(from) == inter.connections.end())
115 inter.connections[from] = foot;
117 _intersections[from].connections[to] = car;
119 cerr << "Number of streets: " << streets << endl;
122 void Bot::updateWorld(){
125 _world = value<int>(input);
126 cerr << "World: " << _world << endl;
129 _robbed = value<int>(input);
130 cerr << "Robbed: " << _robbed << endl;
137 istringstream bank(input);
140 bank >> _banks[input];
142 cerr << "Number of banks: " << _banks.size() << endl;
149 istringstream evidence(input);
153 _smell = value<int>(input);
160 istringstream player(input);
163 cerr << "Player: " << input << endl;
164 Player& pl = _players[input];
165 player >> pl.location;
168 cerr << "Number of players: " << _players.size() << endl;
171 void Bot::move(std::string location){
172 cerr << "Moving to: " << location << endl;
173 cout << "mov: " << location << " " << _type << endl;
177 T value(std::string input){
178 istringstream istr(input);
185 std::string Bot::turn(){
186 cerr << "Using stupid stand still Bot::turn" << endl;
190 std::vector<std::string> Bot::shortestPath(std::string from, std::string to, std::string type){
192 priority_queue<vector<string>, vector<vector<string> >, greater<vector<string> > > pq;
198 hash_map<string,bool> settled;
201 const vector<string>& w = pq.top();
204 settled[w.back()] = true;
205 Intersection& inter = _intersections[w.back()];
206 for (hash_map<string,StreetType>::const_iterator street = inter.connections.begin();
207 street != inter.connections.end(); ++street){
208 if (settled.find(street->first) == settled.end())
210 bool car = type == "cop-car";
211 if ( (car && (street->second == car || street->second == both)) ||
212 (!car && (street->second == foot || street->second == both))){
214 v.push_back(street->first);
222 return vector<string>();