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;
25 priority_queue<vector<string>, vector<vector<string> >, VectComp> pq;
35 v.push_back("hej hå");
38 v.push_back("hejsan");
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;
53 cerr << "Size: " << pq.top().size() << " " << pq.top()[0] << endl;
55 cerr << "Size: " << pq.top().size() << " " << pq.top()[0] << endl;
63 cout << "reg: " << _name << " " << _playerTypeNames[_type] << endl;
70 _name = value<string>(input);
71 cerr << "Got name: " << _name << endl;
75 cerr << "Got players, building graph." << endl;
81 if (input == "game-over")
84 _type = _players[_name].type;
85 _location = _players[_name].location;
86 cerr << "New turn" << endl;
88 cerr << "Done with turn." << endl;
92 void Bot::getPlayers(){
96 _players[value<string>(input)].type = robber;
98 _players[value<string>(input)].type = cop_foot;
100 _players[value<string>(input)].type = cop_foot;
102 _players[value<string>(input)].type = cop_foot;
104 _players[value<string>(input)].type = cop_foot;
109 ( nod: loc node-tag coordinate coordinate eol )*
112 ( edg: loc loc edge-type eol )*
115 void Bot::buildGraph(){
118 if (input != "nod\\")
121 cerr << "Getting intersections" << endl;
126 istringstream node(input);
129 Intersection& inter = _intersections[input];
133 else if (input == "hq")
135 else if (input == "robber-start")
136 inter.type = robber_start;
138 inter.type = ordinary;
143 cerr << "Number of intersections: " << _intersections.size() << endl;
146 if (input != "edg\\")
149 cerr << "Getting streets" << endl;
156 istringstream street(input);
164 //cerr << "Street between: " << from << " and " << to << " of type: " << type << endl;
166 _intersections[from].connections[to] = both;
167 Intersection& inter = _intersections[to];
168 if (inter.connections.find(from) == inter.connections.end())
169 inter.connections[from] = foot;
171 _intersections[from].connections[to] = car;
173 cerr << "Number of streets: " << streets << endl;
177 void Bot::updateWorld(){
180 _world = value<int>(input);
181 //cerr << "World: " << _world << endl;
184 _robbed = value<int>(input);
185 //cerr << "Robbed: " << _robbed << endl;
192 istringstream bank(input);
195 bank >> _banks[input];
197 //cerr << "Number of banks: " << _banks.size() << endl;
204 istringstream evidence(input);
209 _evidence[world] = input;
213 _smell = value<int>(input);
220 istringstream player(input);
223 //cerr << "Player: " << input << endl;
224 Player& pl = _players[input];
225 player >> pl.location;
227 pl.type = _playerTypes[input];
229 //cerr << "Number of players: " << _players.size() << endl;
233 void Bot::move(std::string location){
234 cerr << "Moving to: " << location << endl;
235 cout << "mov: " << location << " " << _playerTypeNames[_type] << endl;
239 T value(std::string input){
240 istringstream istr(input);
247 std::string Bot::turn(){
248 cerr << "Using stupid stand still Bot::turn" << endl;
253 bool operator()(const SPInfo* v1, const SPInfo* v2){
254 return v1->cost > v2->cost;
258 std::list<std::string> Bot::shortestPath(const std::string& from, PlayerType type, const SPGoal& goal){
260 //cerr << "New shortest path from: " << from << endl;
262 priority_queue<SPInfo*, vector<SPInfo* >, SPInfoComp > pq;
263 hash_map<string,SPInfo> nodes;
265 SPInfo* node = &nodes[from];
267 node->settled = false;
276 //cerr << "Vector with size: " << w.size() << endl;
277 //cerr << "Looking at: " << node->name << endl;
278 //copy(w.begin(), w.end(), ostream_iterator<string>(cerr, " : "));
285 front_insert_iterator<list<string> > ii(l);
292 node->settled = true;
294 Intersection& inter = _intersections[node->name];
295 for (hash_map<string,StreetType>::const_iterator street = inter.connections.begin();
296 street != inter.connections.end(); ++street){
297 hash_map<string,SPInfo>::iterator newNode = nodes.find(street->first);
298 bool hascar = type == cop_car;
299 if ( (hascar && (street->second == car || street->second == both)) ||
300 (!hascar && (street->second == foot || street->second == both))){
301 //cerr << "Adding street: " << street->first << endl;
303 if (newNode == nodes.end()){
304 n = &nodes[street->first];
305 n->name = street->first;
309 }else if (newNode->second.settled)
312 n = &newNode->second;
314 if (n->cost > node->cost + 1){
315 n->cost = node->cost + 1;
325 return list<string>();