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;
254 //cerr << "Vector with size: " << w.size() << endl;
255 //cerr << "Looking at: " << node->name << endl;
256 //copy(w.begin(), w.end(), ostream_iterator<string>(cerr, " : "));
263 front_insert_iterator<list<string> > ii(l);
270 node->settled = true;
272 Intersection& inter = _intersections[node->name];
273 for (hash_map<string,StreetType>::const_iterator street = inter.connections.begin();
274 street != inter.connections.end(); ++street){
275 hash_map<string,SPInfo>::iterator newNode = nodes.find(street->first);
276 bool travelStreet = false;
279 if (street->second != foot){
280 hash_map<string,StreetType>::const_iterator st = _intersections[street->first].connections.find(node->name);
281 if (st != _intersections[street->first].connections.end())
282 travelStreet = st->second != foot;
284 travelStreet = false;
288 travelStreet = street->second != foot;
290 travelStreet = street->second != car;
293 //cerr << "Adding street: " << street->first << endl;
295 if (newNode == nodes.end()){
296 n = &nodes[street->first];
297 n->name = street->first;
301 }else if (newNode->second.settled)
304 n = &newNode->second;
306 if (n->cost > node->cost + 1){
307 n->cost = node->cost + 1;
317 return list<string>();
320 SimpleSPGoal::SimpleSPGoal(std::string to):_to(to){
323 int SimpleSPGoal::operator()(const SPInfo* node) const{
324 if (node->name == _to)
329 FindPlayer::FindPlayer(const hash_map<string, Player>& players, PlayerType type, int limit) : _players(players), _type(type), _limit(limit){
332 int FindPlayer::operator()(const SPInfo* node) const{
333 if (_limit > 0 && node->cost >= _limit)
335 for(hash_map<string, Player>::const_iterator player = _players.begin();
336 player != _players.end(); ++player){
337 if (player->second.type == _type && player->second.location == node->name){