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, 6));
40 list<string> closestCarCop = shortestPath(street->first, cop_car, FindPlayer(_players, cop_car, 5));
42 unsigned int closestCop = 0;
43 bool copInCar = false;
45 if (closestCarCop.size() < closestFootCop.size() && closestCarCop.size() > 0){
46 closestCop = closestCarCop.size();
49 closestCop = closestFootCop.size();
51 if (closestCop > 0 && closestCop < 3){
52 cerr << "Cop " << closestCop << " intersections away." << endl;
57 for(hash_map<string,int>::const_iterator bank = _banks.begin();
58 bank != _banks.end(); ++bank){
59 //cerr << "Handling bank at: " << bank->first << endl;
60 if (bank->second > 0){
61 list<string> l = shortestPath(street->first, _type, SimpleSPGoal(bank->first));
64 //list<string>::iterator i = l.begin();
66 banks.push_back(bank->second/(pow(l.size(),4.0)));
69 sort(banks.begin(),banks.end(),greater<double>());
71 for (unsigned int i = 0; i < 2 && i < banks.size();++i)
74 cerr << "Goodness before cop: " << goodness << endl;
76 cerr << "Cop " << closestCop << " intersections away." << endl;
77 goodness *= 1 - 1/(copInCar ? closestCop : closestCop - 1);
79 cerr << "Goodness after cop: " << goodness << endl;
81 if (conInter.type == bank){
82 cerr << "FOUND A BANK" << endl;
83 if (closestCop > 0 && closestCop < 4)
85 else if (_banks[street->first] > 0){
86 cerr << "No cop close to bank" << endl;
91 cerr << "Street: " << street->first << " goodness: " << goodness << endl;
92 streets[street->first] = goodness;
94 streets[_oldLocation] /= 10;
98 /*cerr << "Using route: ";
99 copy(v.begin(), v.end(), ostream_iterator<string>(cerr, " : "));
103 string destination = _location;
105 for (hash_map<string,double>::const_iterator dest = streets.begin();
106 dest != streets.end(); ++dest){
107 cerr << "Goodness: " << dest->second << endl;
108 if (dest->second > goodness){
109 cerr << "New Goodness: " << dest->second << endl;
110 goodness = dest->second;
111 destination = dest->first;
114 _oldLocation = _location;
121 Robber robber("robber");