7 using namespace __gnu_cxx;
9 struct FindCop : SPGoal{
11 const hash_map<string, Player>& _players;
12 FindCop(const hash_map<string, Player>& players, int limit = 0) : _players(players), _limit(limit){}
13 int operator()(const SPInfo* node) const{
14 if (_limit > 0 && node->cost >= _limit)
16 for(hash_map<string, Player>::const_iterator player = _players.begin();
17 player != _players.end(); ++player){
18 if (player->second.type != robber && player->second.location == node->name){
26 string Robber::turn(){
27 hash_map<string,double> streets;
28 Intersection& inter = _intersections[_location];
29 for (hash_map<string,StreetType>::const_iterator street = inter.connections.begin();
30 street != inter.connections.end(); ++street){
31 if (street->second == car){
32 cerr << "Discarding: " << street->first << " since car is needed" << endl;
36 Intersection& conInter = _intersections[street->first];
38 list<string> l = shortestPath(street->first, _type, FindCop(_players, 5));
40 cerr << "Cop " << l.size() << " intersections away." << endl;
43 goodness *= 1 - 1/l.size();
46 if (conInter.type == bank){
47 cerr << "FOUND A BANK" << endl;
48 if (l.size() > 0 && l.size() < 4)
50 else if (_banks[street->first] > 0){
51 cerr << "No cop close to bank" << endl;
58 for(hash_map<string,int>::const_iterator bank = _banks.begin();
59 bank != _banks.end(); ++bank){
60 //cerr << "Handling bank at: " << bank->first << endl;
61 if (bank->second > 0){
62 list<string> l = shortestPath(street->first, _type, SimpleSPGoal(bank->first));
65 list<string>::iterator i = l.begin();
67 banks.push_back(bank->second/(pow(l.size(),2.0)));
70 sort(banks.begin(),banks.end());
71 for (unsigned int i = 0; i < 2 && i < banks.size();++i)
73 cerr << "Street: " << street->first << " goodness: " << goodness << endl;
74 streets[street->first] = goodness;
76 streets[_oldLocation] /= 10;
80 /*cerr << "Using route: ";
81 copy(v.begin(), v.end(), ostream_iterator<string>(cerr, " : "));
87 for (hash_map<string,double>::const_iterator dest = streets.begin();
88 dest != streets.end(); ++dest){
89 cerr << "Goodness: " << dest->second << endl;
90 if (dest->second > goodness){
91 cerr << "New Goodness: " << dest->second << endl;
92 goodness = dest->second;
93 destination = dest->first;
96 _oldLocation = _location;
103 Robber robber("robber");