]> ruin.nu Git - icfp05.git/blob - robber/robber.cpp
some restructuring
[icfp05.git] / robber / 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> l = shortestPath(street->first, _type, SimpleSPGoal(bank->first));
45                                 if (l.size() < 1)
46                                         continue;
47                                 //list<string>::iterator i = l.begin();
48                                 //++i;
49                                 banks.push(bank->second/(pow(l.size(),4.0)));
50                         }
51                 }
52                 //sort(banks.begin(),banks.end(),greater<double>());
53
54                 for (unsigned int i = 0; i < 2 && banks.size() > 0;++i){
55                         goodness += banks.top();
56                         banks.pop();
57                 }
58
59                 cerr << "Goodness before cop: " << goodness << endl;
60                 if (closestCop > 2){
61                         cerr << "Cop " << closestCop << " intersections away." << endl;
62                         goodness *= 1 - 1/(copInCar ? closestCop : closestCop - 1);
63                 }
64                 cerr << "Goodness after cop: " << goodness << endl;
65
66                 if (conInter.type == bank){
67                         cerr << "FOUND A BANK" << endl;
68                         if (closestCop > 0 && closestCop < 4)
69                                 continue;
70                         else if (_banks[street->first] > 0){
71                                 cerr << "No cop close to bank" << endl;
72                                 return street->first;
73                         }
74                 }
75                 
76                 cerr << "Street: " << street->first << " goodness: " << goodness << endl;
77                 streets[street->first] = goodness;
78         }
79         streets[_oldLocation] /= 10;
80
81
82
83         /*cerr << "Using route: ";
84         copy(v.begin(), v.end(), ostream_iterator<string>(cerr, " : "));
85         cerr << endl;
86         */
87
88         string destination = _location;
89         double goodness = 0;
90         for (hash_map<string,double>::const_iterator dest = streets.begin();
91                         dest != streets.end(); ++dest){
92                 cerr << "Goodness: " << dest->second << endl;
93                 if (dest->second > goodness){
94                 cerr << "New Goodness: " << dest->second << endl;
95                         goodness = dest->second;
96                         destination = dest->first;
97                 }
98         }
99         _oldLocation = _location;
100                 
101         return destination;
102         
103 }
104
105 int main(){
106         Robber robber("robber");
107         robber.play();
108
109         return 0;
110 }