9 using namespace __gnu_cxx;
12 bool operator()(const vector<string>& v1, const vector<string>& v2){
13 return v1.size() > v2.size();
16 Bot::Bot(string name, string type){
21 priority_queue<vector<string>, vector<vector<string> >, VectComp> pq;
31 v.push_back("hej hå");
34 v.push_back("hejsan");
41 cerr << "Size: " << pq.top().size() << " " << pq.top()[0] << endl;
43 cerr << "Size: " << pq.top().size() << " " << pq.top()[0] << endl;
45 cerr << "Size: " << pq.top().size() << " " << pq.top()[0] << endl;
47 cerr << "Size: " << pq.top().size() << " " << pq.top()[0] << endl;
49 cerr << "Size: " << pq.top().size() << " " << pq.top()[0] << endl;
51 cerr << "Size: " << pq.top().size() << " " << pq.top()[0] << endl;
59 cout << "reg: " << _name << " " << _type << endl;
66 _name = value<string>(input);
67 cerr << "Got name: " << _name << endl;
71 _players[value<string>(input)].type = "robber";
73 _players[value<string>(input)].type = "cop-foot";
75 _players[value<string>(input)].type = "cop-foot";
77 _players[value<string>(input)].type = "cop-foot";
79 _players[value<string>(input)].type = "cop-foot";
81 cerr << "Got players, building graph." << endl;
88 if (input == "game-over")
91 _type = _players[_name].type;
92 _location = _players[_name].location;
94 cerr << "New turn" << endl;
96 cerr << "Done with turn." << endl;
105 ( nod: loc node-tag coordinate coordinate eol )*
108 ( edg: loc loc edge-type eol )*
111 void Bot::buildGraph(){
114 if (input != "nod\\")
117 cerr << "Getting intersections" << endl;
122 istringstream node(input);
125 Intersection& inter = _intersections[input];
131 cerr << "Number of intersections: " << _intersections.size() << endl;
134 if (input != "edg\\")
137 cerr << "Getting streets" << endl;
144 istringstream street(input);
152 cerr << "Street between: " << from << " and " << to << " of type: " << type << endl;
154 _intersections[from].connections[to] = both;
155 Intersection& inter = _intersections[to];
156 if (inter.connections.find(from) == inter.connections.end())
157 inter.connections[from] = foot;
159 _intersections[from].connections[to] = car;
161 cerr << "Number of streets: " << streets << endl;
164 void Bot::updateWorld(){
167 _world = value<int>(input);
168 //cerr << "World: " << _world << endl;
171 _robbed = value<int>(input);
172 //cerr << "Robbed: " << _robbed << endl;
179 istringstream bank(input);
182 bank >> _banks[input];
184 //cerr << "Number of banks: " << _banks.size() << endl;
191 istringstream evidence(input);
195 _smell = value<int>(input);
202 istringstream player(input);
205 //cerr << "Player: " << input << endl;
206 Player& pl = _players[input];
207 player >> pl.location;
210 //cerr << "Number of players: " << _players.size() << endl;
213 void Bot::move(std::string location){
214 cerr << "Moving to: " << location << endl;
215 cout << "mov: " << location << " " << _type << endl;
219 T value(std::string input){
220 istringstream istr(input);
227 std::string Bot::turn(){
228 cerr << "Using stupid stand still Bot::turn" << endl;
232 std::vector<std::string> Bot::shortestPath(std::string from, std::string to, std::string type){
234 priority_queue<vector<string>, vector<vector<string> >, VectComp > pq;
240 hash_map<string,bool> settled;
243 const vector<string> w = pq.top();
245 //cerr << "Vector with size: " << w.size() << endl;
246 //cerr << "Looking at: " << w.back() << endl;
247 //copy(w.begin(), w.end(), ostream_iterator<string>(cerr, " : "));
250 settled[w.back()] = true;
251 Intersection& inter = _intersections[w.back()];
252 for (hash_map<string,StreetType>::const_iterator street = inter.connections.begin();
253 street != inter.connections.end(); ++street){
254 if (settled.find(street->first) != settled.end())
256 //cerr << "Adding: " << street->first << endl;
257 bool hascar = type == "cop-car";
258 if ( (hascar && (street->second == car || street->second == both)) ||
259 (!hascar && (street->second == foot || street->second == both))){
262 v.push_back(street->first);
270 return vector<string>();