7 using namespace __gnu_cxx;
9 struct FindPlayer : SPGoal{
11 const hash_map<string, Player>& _players;
13 FindPlayer(const hash_map<string, Player>& players, PlayerType type, int limit = 0) : _players(players), _type(type), _limit(limit){}
14 int operator()(const SPInfo* node) const{
15 if (_limit > 0 && node->cost >= _limit)
17 for(hash_map<string, Player>::const_iterator player = _players.begin();
18 player != _players.end(); ++player){
19 if (player->second.type == _type && player->second.location == node->name){
27 string Robber::turn(){
28 hash_map<string,double> streets;
29 Intersection& inter = _intersections[_location];
30 for (hash_map<string,StreetType>::const_iterator street = inter.connections.begin();
31 street != inter.connections.end(); ++street){
32 if (street->second == car){
33 cerr << "Discarding: " << street->first << " since car is needed" << endl;
37 Intersection& conInter = _intersections[street->first];
39 list<string> closestFootCop = shortestPath(street->first, cop_foot, FindPlayer(_players, cop_foot, 5));
40 list<string> closestCarCop = shortestPath(street->first, cop_car, FindPlayer(_players, cop_car, 4));
42 unsigned int closestCop = 0;
43 bool copInCar = false;
45 if (closestFootCop.size() < closestCarCop.size() && closestFootCop.size() > 0)
46 closestCop = closestFootCop.size();
48 closestCop = closestCarCop.size();
53 cerr << "Cop " << closestCop << " intersections away." << endl;
58 goodness *= 1 - 1/closestCop;
61 if (conInter.type == bank){
62 cerr << "FOUND A BANK" << endl;
63 if (closestCop > 0 && closestCop < 4)
65 else if (_banks[street->first] > 0){
66 cerr << "No cop close to bank" << endl;
73 for(hash_map<string,int>::const_iterator bank = _banks.begin();
74 bank != _banks.end(); ++bank){
75 //cerr << "Handling bank at: " << bank->first << endl;
76 if (bank->second > 0){
77 list<string> l = shortestPath(street->first, _type, SimpleSPGoal(bank->first));
80 list<string>::iterator i = l.begin();
82 banks.push_back(bank->second/(pow(l.size(),2.0)));
85 sort(banks.begin(),banks.end());
86 for (unsigned int i = 0; i < 2 && i < banks.size();++i)
88 cerr << "Street: " << street->first << " goodness: " << goodness << endl;
89 streets[street->first] = goodness;
91 streets[_oldLocation] /= 10;
95 /*cerr << "Using route: ";
96 copy(v.begin(), v.end(), ostream_iterator<string>(cerr, " : "));
102 for (hash_map<string,double>::const_iterator dest = streets.begin();
103 dest != streets.end(); ++dest){
104 cerr << "Goodness: " << dest->second << endl;
105 if (dest->second > goodness){
106 cerr << "New Goodness: " << dest->second << endl;
107 goodness = dest->second;
108 destination = dest->first;
111 _oldLocation = _location;
118 Robber robber("robber");