]> ruin.nu Git - icfp05.git/blob - robbersrc/robber.cpp
commented out debug messages
[icfp05.git] / robbersrc / robber.cpp
1 #include "robber.h"
2 #include <iostream>
3 #include <iterator>
4 #include <queue>
5 #include <cmath>
6
7 using namespace std;
8 using namespace __gnu_cxx;
9
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;
17                         continue;
18                 }
19                 double goodness = 0;
20                 Intersection& conInter = _intersections[street->first];
21
22                 list<string> closestFootCop = shortestPath(street->first, cop_foot, FindPlayer(_players, cop_foot, 6), true);
23                 list<string> closestCarCop = shortestPath(street->first, cop_car, FindPlayer(_players, cop_car, 5), true);
24
25                 unsigned int closestCop = 0;
26                 bool copInCar = false;
27
28                 if (closestCarCop.size() < closestFootCop.size() && closestCarCop.size() > 0){
29                         closestCop = closestCarCop.size();
30                         copInCar = true;
31                 }else 
32                         closestCop = closestFootCop.size();
33
34                 if (closestCop > 0 && closestCop < 3){
35                         //cerr << "Cop " << closestCop << " intersections away." << endl;
36                         continue;
37                 }
38
39                 priority_queue<double> banks;
40                 for(hash_map<string,int>::const_iterator bank = _banks.begin();
41                                 bank != _banks.end(); ++bank){
42                         //cerr << "Handling bank at: " << bank->first << endl;
43                         if (bank->second > 0){
44                                 list<string> cop = shortestPath(bank->first, cop_car, FindPlayer(_players, cop_car, 3), true);
45                                 if (cop.size() > 0)
46                                         continue;
47                                 else{
48                                         cop = shortestPath(bank->first, cop_foot, FindPlayer(_players, cop_foot, 3), true);
49                                         if (cop.size() > 0)
50                                                 continue;
51                                 }
52                                 list<string> l = shortestPath(street->first, _type, SimpleSPGoal(bank->first));
53                                 if (l.size() < 1)
54                                         continue;
55                                 //list<string>::iterator i = l.begin();
56                                 //++i;
57                                 banks.push(bank->second/(pow(l.size(),4.0)));
58                         }
59                 }
60                 //sort(banks.begin(),banks.end(),greater<double>());
61
62                 for (unsigned int i = 0; i < 2 && banks.size() > 0;++i){
63                         goodness += banks.top();
64                         banks.pop();
65                 }
66
67                 //cerr << "Goodness before cop: " << goodness << endl;
68                 if (closestCop > 2){
69                         //cerr << "Cop " << closestCop << " intersections away." << endl;
70                         goodness *= 1 - 1/(copInCar ? closestCop : closestCop - 1);
71                 }
72                 //cerr << "Goodness after cop: " << goodness << endl;
73
74                 if (conInter.type == bank){
75                         //cerr << "FOUND A BANK" << endl;
76                         if (closestCop > 0 && closestCop < 4)
77                                 continue;
78                         else if (_banks[street->first] > 0){
79                                 //cerr << "No cop close to bank" << endl;
80                                 return street->first;
81                         }
82                 }
83                 
84                 //cerr << "Street: " << street->first << " goodness: " << goodness << endl;
85                 streets[street->first] = goodness;
86         }
87         streets[_oldLocation] /= 10;
88
89
90
91         /*cerr << "Using route: ";
92         copy(v.begin(), v.end(), ostream_iterator<string>(cerr, " : "));
93         cerr << endl;
94         */
95
96         //stand still if we can't find a better choice..
97         string destination = _location;
98         double goodness = 0;
99         for (hash_map<string,double>::const_iterator dest = streets.begin();
100                         dest != streets.end(); ++dest){
101                 //cerr << "Goodness: " << dest->second << endl;
102                 if (dest->second > goodness){
103                 //cerr << "New Goodness: " << dest->second << endl;
104                         goodness = dest->second;
105                         destination = dest->first;
106                 }
107         }
108         _oldLocation = _location;
109                 
110         return destination;
111         
112 }
113
114 int main(){
115         Robber robber("robber");
116         robber.play();
117
118         return 0;
119 }