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