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;
46 if (input == "game-over")
49 _type = _players[_name].type;
50 _location = _players[_name].location;
51 cerr << "New turn" << endl;
53 cerr << "Done with turn." << endl;
57 void Bot::getPlayers(){
61 _players[value<string>(input)].type = robber;
63 _players[value<string>(input)].type = cop_foot;
65 _players[value<string>(input)].type = cop_foot;
67 _players[value<string>(input)].type = cop_foot;
69 _players[value<string>(input)].type = cop_foot;
74 ( nod: loc node-tag coordinate coordinate eol )*
77 ( edg: loc loc edge-type eol )*
80 void Bot::buildGraph(){
86 cerr << "Getting intersections" << endl;
91 istringstream node(input);
94 Intersection& inter = _intersections[input];
98 else if (input == "hq")
100 else if (input == "robber-start")
101 inter.type = robber_start;
103 inter.type = ordinary;
108 cerr << "Number of intersections: " << _intersections.size() << endl;
111 if (input != "edg\\")
114 cerr << "Getting streets" << endl;
121 istringstream street(input);
129 //cerr << "Street between: " << from << " and " << to << " of type: " << type << endl;
131 _intersections[from].connections[to] = both;
132 Intersection& inter = _intersections[to];
133 if (inter.connections.find(from) == inter.connections.end())
134 inter.connections[from] = foot;
136 _intersections[from].connections[to] = car;
138 cerr << "Number of streets: " << streets << endl;
142 void Bot::updateWorld(){
145 _world = value<int>(input);
146 //cerr << "World: " << _world << endl;
149 _robbed = value<int>(input);
150 //cerr << "Robbed: " << _robbed << endl;
157 istringstream bank(input);
160 bank >> _banks[input];
162 //cerr << "Number of banks: " << _banks.size() << endl;
169 istringstream evidence(input);
174 _evidence[world] = input;
178 _smell = value<int>(input);
185 istringstream player(input);
188 //cerr << "Player: " << input << endl;
189 Player& pl = _players[input];
190 player >> pl.location;
192 pl.type = _playerTypes[input];
194 //cerr << "Number of players: " << _players.size() << endl;
198 void Bot::move(std::string location){
199 cerr << "Moving to: " << location << endl;
200 cout << "mov: " << location << " " << _playerTypeNames[_type] << endl;
204 T value(std::string input){
205 istringstream istr(input);
212 std::string Bot::turn(){
213 cerr << "Using stupid stand still Bot::turn" << endl;
218 bool operator()(const SPInfo* v1, const SPInfo* v2){
219 return v1->cost > v2->cost;
223 std::list<std::string> Bot::shortestPath(const std::string& from, PlayerType type, const SPGoal& goal, bool reverse){
225 //cerr << "New shortest path from: " << from << endl;
227 priority_queue<SPInfo*, vector<SPInfo* >, SPInfoComp > pq;
228 hash_map<string,SPInfo> nodes;
230 SPInfo* node = &nodes[from];
232 node->settled = false;
238 bool hascar = type == cop_car;
242 //cerr << "Vector with size: " << w.size() << endl;
243 //cerr << "Looking at: " << node->name << endl;
244 //copy(w.begin(), w.end(), ostream_iterator<string>(cerr, " : "));
251 front_insert_iterator<list<string> > ii(l);
258 node->settled = true;
260 Intersection& inter = _intersections[node->name];
261 for (hash_map<string,StreetType>::const_iterator street = inter.connections.begin();
262 street != inter.connections.end(); ++street){
263 hash_map<string,SPInfo>::iterator newNode = nodes.find(street->first);
264 bool travelStreet = false;
267 if (street->second != foot){
268 hash_map<string,StreetType>::const_iterator st = _intersections[street->first].connections.find(node->name);
269 if (st != _intersections[street->first].connections.end())
270 travelStreet = st->second != foot;
272 travelStreet = false;
276 travelStreet = street->second != foot;
278 travelStreet = street->second != car;
281 //cerr << "Adding street: " << street->first << endl;
283 if (newNode == nodes.end()){
284 n = &nodes[street->first];
285 n->name = street->first;
289 }else if (newNode->second.settled)
292 n = &newNode->second;
294 if (n->cost > node->cost + 1){
295 n->cost = node->cost + 1;
305 return list<string>();
308 SimpleSPGoal::SimpleSPGoal(std::string to):_to(to){
311 int SimpleSPGoal::operator()(const SPInfo* node) const{
312 if (node->name == _to)
317 FindPlayer::FindPlayer(const hash_map<string, Player>& players, PlayerType type, int limit) : _players(players), _type(type), _limit(limit){
320 int FindPlayer::operator()(const SPInfo* node) const{
321 if (_limit > 0 && node->cost >= _limit)
323 for(hash_map<string, Player>::const_iterator player = _players.begin();
324 player != _players.end(); ++player){
325 if (player->second.type == _type && player->second.location == node->name){