]> ruin.nu Git - icfp05.git/blob - robber/robber.cpp
fixed priority queue and started to implement the robber algorithm, it needs tuning...
[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 = 100;
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                         if (dist2 > dist1)
35                                 goodness *= 4;
36                         else
37                                 goodness /= 4;
38
39                         if (player->second.type == "cop-foot" && dist2 <= 3)
40                                 goodness /= 10;
41                         else if (player->second.type == "cop-car" && dist2 <= 2)
42                                 goodness /= 10;
43
44
45                 }
46                 streets[street->first] = goodness;
47         }
48
49         for(hash_map<string,int>::const_iterator bank = _banks.begin();
50                         bank != _banks.end(); ++bank){
51                 //cerr << "Handling bank at: " << bank->first << endl;
52                 if (bank->second > 0){
53                         vector<string> v = shortestPath(_location, bank->first,_type);
54                         if (v.size() < 2)
55                                 continue;
56                         streets[v[1]] *= bank->second/v.size();
57                         
58                 }
59         }
60         /*cerr << "Using route: ";
61         copy(v.begin(), v.end(), ostream_iterator<string>(cerr, " : "));
62         cerr << endl;
63         */
64
65         string destination;
66         double goodness = 0;
67         for (hash_map<string,double>::const_iterator dest = streets.begin();
68                         dest != streets.end(); ++dest){
69                 cerr << "Goodness: " << dest->second << endl;
70                 if (dest->second > goodness){
71                 cerr << "New Goodness: " << dest->second << endl;
72                         goodness = dest->second;
73                         destination = dest->first;
74                 }
75         }
76                 
77         return destination;
78         
79 }
80
81 int main(){
82         Robber robber("robber");
83         robber.play();
84
85         return 0;
86 }