]> ruin.nu Git - icfp05.git/blob - robbersrc/robber.cpp
abf638b1c1f0c9f4107d3e3f415207bcd5d391b6
[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                 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;
28
29
30                 if (closestCarCop.size() > 0){
31                         closestCop = closestCarCop.size();
32                         copInCar = true;
33                 }
34
35                 if (closestCop > 0 && closestCop < 3){
36                         //cerr << "Cop " << closestCop << " intersections away." << endl;
37                         continue;
38                 }
39
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);
46                                 if (cop.size() > 0)
47                                         continue;
48                                 else{
49                                         cop = shortestPath(bank->first, cop_foot, FindPlayer(_players, cop_foot, 3), true);
50                                         if (cop.size() > 0)
51                                                 continue;
52                                 }
53                                 list<string> l = shortestPath(street->first, _type, SimpleSPGoal(bank->first));
54                                 if (l.size() < 1)
55                                         continue;
56                                 //list<string>::iterator i = l.begin();
57                                 //++i;
58                                 banks.push(bank->second/(pow(l.size(),4.0)));
59                         }
60                 }
61                 //sort(banks.begin(),banks.end(),greater<double>());
62
63                 for (unsigned int i = 0; i < 2 && banks.size() > 0;++i){
64                         goodness += banks.top();
65                         banks.pop();
66                 }
67
68                 //cerr << "Goodness before cop: " << goodness << endl;
69                 if (closestCop > 2){
70                         //cerr << "Cop " << closestCop << " intersections away." << endl;
71                         goodness *= 1 - 1/(copInCar ? closestCop : closestCop - 1);
72                 }
73                 //cerr << "Goodness after cop: " << goodness << endl;
74
75                 if (conInter.type == bank){
76                         //cerr << "FOUND A BANK" << endl;
77                         if (closestCop > 0 && closestCop < 4)
78                                 continue;
79                         else if (_banks[street->first] > 0){
80                                 //cerr << "No cop close to bank" << endl;
81                                 return street->first;
82                         }
83                 }
84                 
85                 //cerr << "Street: " << street->first << " goodness: " << goodness << endl;
86                 streets[street->first] = goodness;
87         }
88         streets[_oldLocation] /= 10;
89
90
91
92         /*cerr << "Using route: ";
93         copy(v.begin(), v.end(), ostream_iterator<string>(cerr, " : "));
94         cerr << endl;
95         */
96
97         //stand still if we can't find a better choice..
98         string destination = _location;
99         double goodness = 0;
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;
107                 }
108         }
109         _oldLocation = _location;
110         //cerr << "Moving to: " << destination << endl;
111                 
112         return destination;
113         
114 }
115
116 int main(){
117         Robber robber("harv-robber");
118         robber.play();
119
120         return 0;
121 }