]> ruin.nu Git - icfp05.git/blob - robbersrc/robber.cpp
e800b6cd6ad6fc12ebdfdca61a4358b8b415f910
[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
12         //Ignore bribing for now
13         cout << "nobribe:" << endl;
14         string input;
15         getline(cin,input);
16
17         hash_map<string,double> streets;
18         Intersection& inter = _intersections[_location];
19         for (hash_map<string,StreetType>::const_iterator street = inter.connections.begin();
20                street != inter.connections.end(); ++street){
21                 if (street->second == car){
22                         //cerr << "Discarding: " << street->first << " since car is needed" << endl;
23                         continue;
24                 }
25                 //cerr << "Looking at street: " << street->first << endl;
26                 Intersection& conInter = _intersections[street->first];
27                 double goodness = conInter.connections.size();
28
29                 list<string> closestFootCop = shortestPath(street->first, cop_foot, FindPlayer(_players, cop_foot, 6), true);
30                 unsigned int closestCop = closestFootCop.size();
31                 bool copInCar = false;
32                 //cerr << "Cop on fot " << closestCop << " intersections away." << endl;
33
34                 if (closestCop > 0 && closestCop < 3)
35                         continue;
36
37                 list<string> closestCarCop = shortestPath(street->first, cop_car, FindPlayer(_players, cop_car, closestCop - 1 > 0 ? closestCop : 5), true);
38                 //cerr << "Cop in car " << closestCarCop.size() << " intersections away." << endl;
39
40                 if (closestCarCop.size() > 0){
41                         closestCop = closestCarCop.size();
42                         copInCar = true;
43                 }
44
45                 //cerr << "Cop " << closestCop << " intersections away." << endl;
46                 if (closestCop > 0 && closestCop < 3)
47                         continue;
48
49                 priority_queue<double> banks;
50                 for(hash_map<string,int>::const_iterator bank = _banks.begin();
51                                 bank != _banks.end(); ++bank){
52                         //cerr << "Handling bank at: " << bank->first << endl;
53                         if (bank->second > 0){
54                                 list<string> cop = shortestPath(bank->first, cop_car, FindPlayer(_players, cop_car, 3), true);
55                                 if (cop.size() > 0)
56                                         continue;
57                                 else{
58                                         cop = shortestPath(bank->first, cop_foot, FindPlayer(_players, cop_foot, 3), true);
59                                         if (cop.size() > 0)
60                                                 continue;
61                                 }
62                                 list<string> l = shortestPath(street->first, _type, SimpleSPGoal(bank->first));
63                                 if (l.size() < 1)
64                                         continue;
65                                 //list<string>::iterator i = l.begin();
66                                 //++i;
67                                 banks.push(bank->second/(pow(l.size(),4.0)));
68                         }
69                 }
70                 //sort(banks.begin(),banks.end(),greater<double>());
71
72                 for (unsigned int i = 0; i < 2 && banks.size() > 0;++i){
73                         goodness += banks.top();
74                         banks.pop();
75                 }
76
77                 //cerr << "Goodness before cop: " << goodness << endl;
78                 if (closestCop > 2){
79                         //cerr << "Cop " << closestCop << " intersections away." << endl;
80                         goodness *= 1 - 1/(copInCar ? closestCop : closestCop - 1);
81                 }
82                 //cerr << "Goodness after cop: " << goodness << endl;
83
84                 if (conInter.type == bank){
85                         //cerr << "FOUND A BANK" << endl;
86                         if (closestCop > 0 && closestCop < 4)
87                                 continue;
88                         else if (_banks[street->first] > 0){
89                                 //cerr << "No cop close to bank" << endl;
90                                 return street->first;
91                         }
92                 }
93                 
94                 //cerr << "Street: " << street->first << " goodness: " << goodness << endl;
95                 streets[street->first] = goodness;
96         }
97         streets[_oldLocation] /= 10;
98
99
100
101         /*cerr << "Using route: ";
102         copy(v.begin(), v.end(), ostream_iterator<string>(cerr, " : "));
103         cerr << endl;
104         */
105
106         //stand still if we can't find a better choice..
107         string destination = _location;
108         double goodness = 0;
109         for (hash_map<string,double>::const_iterator dest = streets.begin();
110                         dest != streets.end(); ++dest){
111                 //cerr << "Goodness: " << dest->second << endl;
112                 if (dest->second > goodness){
113                 //cerr << "New Goodness: " << dest->second << endl;
114                         goodness = dest->second;
115                         destination = dest->first;
116                 }
117         }
118         _oldLocation = _location;
119         //cerr << "Moving to: " << destination << endl;
120                 
121         return destination;
122         
123 }
124 void Robber::move(std::string location){
125         cout << "rmov\\" << endl;
126         Bot::move(location);
127         cout << "nobribe:" << endl;
128         cout << "rmov/" << endl;
129 }
130
131 int main(){
132         Robber robber("harv-robber");
133         robber.play();
134
135         return 0;
136 }