8 using namespace __gnu_cxx;
10 string Robber::turn(){
11 hash_map<string,double> streets;
12 Intersection& inter = _intersections[_location];
13 for (hash_map<string,StreetType>::const_iterator street = inter.connections.begin();
14 street != inter.connections.end(); ++street){
15 if (street->second == car){
16 //cerr << "Discarding: " << street->first << " since car is needed" << endl;
20 Intersection& conInter = _intersections[street->first];
22 list<string> closestFootCop = shortestPath(street->first, cop_foot, FindPlayer(_players, cop_foot, 6), true);
23 unsigned int closestCop = closestFootCop.size();
24 //cerr << "Cop on fot " << closestCop << " intersections away." << endl;
25 bool copInCar = false;
26 list<string> closestCarCop = shortestPath(street->first, cop_car, FindPlayer(_players, cop_car, closestCop > 0 ? closestCop : 5), true);
27 //cerr << "Cop in car " << closestCarCop.size() << " intersections away." << endl;
30 if (closestCarCop.size() > 0){
31 closestCop = closestCarCop.size();
35 if (closestCop > 0 && closestCop < 3){
36 //cerr << "Cop " << closestCop << " intersections away." << endl;
40 priority_queue<double> banks;
41 for(hash_map<string,int>::const_iterator bank = _banks.begin();
42 bank != _banks.end(); ++bank){
43 //cerr << "Handling bank at: " << bank->first << endl;
44 if (bank->second > 0){
45 list<string> cop = shortestPath(bank->first, cop_car, FindPlayer(_players, cop_car, 3), true);
49 cop = shortestPath(bank->first, cop_foot, FindPlayer(_players, cop_foot, 3), true);
53 list<string> l = shortestPath(street->first, _type, SimpleSPGoal(bank->first));
56 //list<string>::iterator i = l.begin();
58 banks.push(bank->second/(pow(l.size(),4.0)));
61 //sort(banks.begin(),banks.end(),greater<double>());
63 for (unsigned int i = 0; i < 2 && banks.size() > 0;++i){
64 goodness += banks.top();
68 //cerr << "Goodness before cop: " << goodness << endl;
70 //cerr << "Cop " << closestCop << " intersections away." << endl;
71 goodness *= 1 - 1/(copInCar ? closestCop : closestCop - 1);
73 //cerr << "Goodness after cop: " << goodness << endl;
75 if (conInter.type == bank){
76 //cerr << "FOUND A BANK" << endl;
77 if (closestCop > 0 && closestCop < 4)
79 else if (_banks[street->first] > 0){
80 //cerr << "No cop close to bank" << endl;
85 //cerr << "Street: " << street->first << " goodness: " << goodness << endl;
86 streets[street->first] = goodness;
88 streets[_oldLocation] /= 10;
92 /*cerr << "Using route: ";
93 copy(v.begin(), v.end(), ostream_iterator<string>(cerr, " : "));
97 //stand still if we can't find a better choice..
98 string destination = _location;
100 for (hash_map<string,double>::const_iterator dest = streets.begin();
101 dest != streets.end(); ++dest){
102 //cerr << "Goodness: " << dest->second << endl;
103 if (dest->second > goodness){
104 //cerr << "New Goodness: " << dest->second << endl;
105 goodness = dest->second;
106 destination = dest->first;
109 _oldLocation = _location;
110 //cerr << "Moving to: " << destination << endl;
117 Robber robber("harv-robber");