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")
51 _type = _players[_name].type;
52 _location = _players[_name].location;
53 //cerr << "New turn" << endl;
55 //cerr << "Done with turn." << endl;
59 void Bot::getPlayers(){
63 _players[value<string>(input)].type = robber;
65 _players[value<string>(input)].type = cop_foot;
67 _players[value<string>(input)].type = cop_foot;
69 _players[value<string>(input)].type = cop_foot;
71 _players[value<string>(input)].type = cop_foot;
76 ( nod: loc node-tag coordinate coordinate eol )*
79 ( edg: loc loc edge-type eol )*
82 void Bot::buildGraph(){
88 //cerr << "Getting intersections" << endl;
93 istringstream node(input);
97 Intersection& inter = _intersections[name];
103 else if (input == "hq"){
107 else if (input == "robber-start"){
108 inter.type = robber_start;
109 _robberLocation = name;
112 inter.type = ordinary;
117 //cerr << "Number of intersections: " << _intersections.size() << endl;
120 if (input != "edg\\")
123 //cerr << "Getting streets" << endl;
130 istringstream street(input);
138 //cerr << "Street between: " << from << " and " << to << " of type: " << type << endl;
140 _intersections[from].connections[to] = both;
141 Intersection& inter = _intersections[to];
142 if (inter.connections.find(from) == inter.connections.end())
143 inter.connections[from] = foot;
145 _intersections[from].connections[to] = car;
147 //cerr << "Number of streets: " << streets << endl;
151 void Bot::updateWorld(){
154 _world = value<int>(input);
155 //cerr << "World: " << _world << endl;
158 _robbed = value<int>(input);
159 //cerr << "Robbed: " << _robbed << endl;
166 istringstream bank(input);
169 bank >> _banks[input];
171 //cerr << "Number of banks: " << _banks.size() << endl;
178 istringstream evidence(input);
183 _evidence[world] = input;
187 _smell = value<int>(input);
189 _robberLocation = "";
195 istringstream player(input);
198 //cerr << "Player: " << input << endl;
199 Player& pl = _players[input];
200 player >> pl.location;
202 pl.type = _playerTypes[input];
203 if (pl.type == robber)
204 _robberLocation = pl.location;
206 //cerr << "Number of players: " << _players.size() << endl;
210 void Bot::move(std::string location){
211 //cerr << "Moving to: " << location << endl;
212 cout << "mov: " << location << " " << _playerTypeNames[_type] << endl;
216 T value(std::string input){
217 istringstream istr(input);
224 std::string Bot::turn(){
225 cerr << "Using stupid stand still Bot::turn" << endl;
230 bool operator()(const SPInfo* v1, const SPInfo* v2){
231 return v1->cost > v2->cost;
235 std::list<std::string> Bot::shortestPath(const std::string& from, PlayerType type, const SPGoal& goal, bool reverse){
237 //cerr << "New shortest path from: " << from << endl;
239 priority_queue<SPInfo*, vector<SPInfo* >, SPInfoComp > pq;
240 hash_map<string,SPInfo> nodes;
242 SPInfo* node = &nodes[from];
244 node->settled = false;
250 bool hascar = type == cop_car;
262 front_insert_iterator<list<string> > ii(l);
269 node->settled = true;
271 hash_map<string,Intersection>::const_iterator intersection = _intersections.find(node->name);
272 if (intersection == _intersections.end()){ //Sanity check, should never be true..
273 cerr << "BUG: Could not find intersection: " << node->name << endl;
276 for (hash_map<string,StreetType>::const_iterator street = intersection->second.connections.begin();
277 street != intersection->second.connections.end(); ++street){
278 hash_map<string,SPInfo>::iterator newNode = nodes.find(street->first);
279 bool travelStreet = false;
282 if (street->second != foot){
283 hash_map<string,Intersection>::const_iterator newInter = _intersections.find(street->first);
284 if (newInter != _intersections.end()){
285 hash_map<string,StreetType>::const_iterator st = newInter->second.connections.find(node->name);
286 if (st != newInter->second.connections.end())
287 travelStreet = st->second != foot;
292 travelStreet = street->second != foot;
294 travelStreet = street->second != car;
297 //cerr << "Adding street: " << street->first << endl;
298 if (newNode == nodes.end()){
299 n = &nodes[street->first];
300 n->name = street->first;
304 }else if (newNode->second.settled)
307 n = &newNode->second;
309 if (n->cost > node->cost + 1){
310 n->cost = node->cost + 1;
320 return list<string>();
323 SimpleSPGoal::SimpleSPGoal(std::string to):_to(to){
326 int SimpleSPGoal::operator()(const SPInfo* node) const{
327 if (node->name == _to)
332 FindPlayer::FindPlayer(const hash_map<string, Player>& players, PlayerType type, int limit) : _players(players), _type(type), _limit(limit){
335 int FindPlayer::operator()(const SPInfo* node) const{
336 if (_limit > 0 && node->cost >= _limit)
338 for(hash_map<string, Player>::const_iterator player = _players.begin();
339 player != _players.end(); ++player){
340 if (player->second.type == _type && player->second.location == node->name){