8 using namespace __gnu_cxx;
10 struct FindPlayer : SPGoal{
12 const hash_map<string, Player>& _players;
14 FindPlayer(const hash_map<string, Player>& players, PlayerType type, int limit = 0) : _players(players), _type(type), _limit(limit){}
15 int operator()(const SPInfo* node) const{
16 if (_limit > 0 && node->cost >= _limit)
18 for(hash_map<string, Player>::const_iterator player = _players.begin();
19 player != _players.end(); ++player){
20 if (player->second.type == _type && player->second.location == node->name){
28 string Robber::turn(){
29 hash_map<string,double> streets;
30 Intersection& inter = _intersections[_location];
31 for (hash_map<string,StreetType>::const_iterator street = inter.connections.begin();
32 street != inter.connections.end(); ++street){
33 if (street->second == car){
34 cerr << "Discarding: " << street->first << " since car is needed" << endl;
38 Intersection& conInter = _intersections[street->first];
40 list<string> closestFootCop = shortestPath(street->first, cop_foot, FindPlayer(_players, cop_foot, 6), true);
41 list<string> closestCarCop = shortestPath(street->first, cop_car, FindPlayer(_players, cop_car, 5), true);
43 unsigned int closestCop = 0;
44 bool copInCar = false;
46 if (closestCarCop.size() < closestFootCop.size() && closestCarCop.size() > 0){
47 closestCop = closestCarCop.size();
50 closestCop = closestFootCop.size();
52 if (closestCop > 0 && closestCop < 3){
53 cerr << "Cop " << closestCop << " intersections away." << endl;
57 priority_queue<double> banks;
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(bank->second/(pow(l.size(),4.0)));
70 //sort(banks.begin(),banks.end(),greater<double>());
72 for (unsigned int i = 0; i < 2 && banks.size() > 0;++i){
73 goodness += banks.top();
77 cerr << "Goodness before cop: " << goodness << endl;
79 cerr << "Cop " << closestCop << " intersections away." << endl;
80 goodness *= 1 - 1/(copInCar ? closestCop : closestCop - 1);
82 cerr << "Goodness after cop: " << goodness << endl;
84 if (conInter.type == bank){
85 cerr << "FOUND A BANK" << endl;
86 if (closestCop > 0 && closestCop < 4)
88 else if (_banks[street->first] > 0){
89 cerr << "No cop close to bank" << endl;
94 cerr << "Street: " << street->first << " goodness: " << goodness << endl;
95 streets[street->first] = goodness;
97 streets[_oldLocation] /= 10;
101 /*cerr << "Using route: ";
102 copy(v.begin(), v.end(), ostream_iterator<string>(cerr, " : "));
106 string destination = _location;
108 for (hash_map<string,double>::const_iterator dest = streets.begin();
109 dest != streets.end(); ++dest){
110 cerr << "Goodness: " << dest->second << endl;
111 if (dest->second > goodness){
112 cerr << "New Goodness: " << dest->second << endl;
113 goodness = dest->second;
114 destination = dest->first;
117 _oldLocation = _location;
124 Robber robber("robber");