]> ruin.nu Git - icfp05.git/blob - robber/robber.cpp
more sane shortest path implementation and more tuning of the robber algorithm
[icfp05.git] / robber / robber.cpp
1 #include "robber.h"
2 #include <iostream>
3 #include <iterator>
4 #include <cmath>
5
6 using namespace std;
7 using namespace __gnu_cxx;
8
9 string Robber::turn(){
10         hash_map<string,double> streets;
11         Intersection& inter = _intersections[_location];
12         for (hash_map<string,StreetType>::const_iterator street = inter.connections.begin();
13                street != inter.connections.end(); ++street){
14                 double goodness = 10;
15                 int curx = _intersections[_location].x;
16                 int cury = _intersections[_location].y;
17
18                 int newx = _intersections[street->first].x;
19                 int newy = _intersections[street->first].y;
20                 for (hash_map<string, Player>::const_iterator player = _players.begin();
21                                 player != _players.end(); ++player){
22                         if (player->first == _name)
23                                 continue;
24
25                         int px = _intersections[player->second.location].x;
26                         int py = _intersections[player->second.location].y;
27
28                         double dist1 = sqrt(pow((curx-px),2.0)+pow((cury-py),2.0));
29                         double dist2 = sqrt(pow((newx-px),2.0)+pow((newy-py),2.0));
30                         /*cerr << "Original distance: " << dist1 << endl;
31                         cerr << "New distance: " << dist2 << endl;
32                         */
33
34
35                         if (dist2 < 50 && dist2 < dist1)
36                                 goodness *= 0.95;
37
38                         if (player->second.type == cop_foot && dist2 <= 3)
39                                 goodness /= 100;
40                         else if (player->second.type == cop_car && dist2 <= 2)
41                                 goodness /= 100;
42
43
44                 }
45                 
46                 cerr << "Street: " << street->first << " goodness: " << goodness << endl;
47                 streets[street->first] = goodness;
48         }
49         streets[_oldLocation] /= 10;
50
51         for(hash_map<string,int>::const_iterator bank = _banks.begin();
52                         bank != _banks.end(); ++bank){
53                 //cerr << "Handling bank at: " << bank->first << endl;
54                 if (bank->second > 0){
55                         list<string> l = shortestPath(_location, bank->first,_type);
56                         if (l.size() < 1)
57                                 continue;
58                         list<string>::iterator i = l.begin();
59                         streets[*++i] += bank->second/(pow(5.0,double(l.size())));
60
61                 }
62         }
63
64         /*cerr << "Using route: ";
65         copy(v.begin(), v.end(), ostream_iterator<string>(cerr, " : "));
66         cerr << endl;
67         */
68
69         string destination;
70         double goodness = 0;
71         for (hash_map<string,double>::const_iterator dest = streets.begin();
72                         dest != streets.end(); ++dest){
73                 cerr << "Goodness: " << dest->second << endl;
74                 if (dest->second > goodness){
75                 cerr << "New Goodness: " << dest->second << endl;
76                         goodness = dest->second;
77                         destination = dest->first;
78                 }
79         }
80         _oldLocation = _location;
81                 
82         return destination;
83         
84 }
85
86 int main(){
87         Robber robber("robber");
88         robber.play();
89
90         return 0;
91 }