]> ruin.nu Git - icfp05.git/blob - newrobber/robber.cpp
new robber is good
[icfp05.git] / newrobber / 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         cerr << "New turn" << endl;
16         getline(cin,input);
17         _time = clock();
18
19         cerr << "Starting to calculate shortest path" << endl;
20         list<string> l = shortestPath(_location, robber,*this, *this);
21         _oldLocation = _location;
22         if (l.size() > 0){
23                 cerr << "Found a route" << endl;
24                 list<string>::iterator i = l.begin();
25                 _location = *++i;
26         }
27         cerr << "Moving to: " << _location << endl;
28         return _location;
29 }
30
31 int Robber::operator()(const SPInfo* node) const{
32         //cerr << "Goal for " << node->name << endl;
33         hash_map<string,int>::const_iterator bank = _banks.find(node->name);
34         if (bank != _banks.end() && bank->second > 0)
35                 return 1;
36         if ((clock()-_time)/CLOCKS_PER_SEC > 2.4)
37                 return 1;
38         return 0;
39 }
40
41 int Robber::cost(const std::string& from, const std::string& to) const{
42
43         //cerr << "Calculating cost between " << from << " and " << to << endl;
44         hash_map<string,Intersection>::const_iterator conInter =  _intersections.find(to);
45         if (conInter == _intersections.end())
46                 return 1000000; //Should never happen
47
48         int cost = 1;
49
50         int max = 10;
51         list<string> closestFootCop = shortestPath(to, cop_foot, FindPlayer(_players, cop_foot, max), true);
52         unsigned int closestCop = closestFootCop.size();
53         bool copInCar = false;
54         cerr << "Cop on fot " << closestCop << " intersections away: ";
55         copy(closestFootCop.begin(), closestFootCop.end(), ostream_iterator<string>(cerr, " : "));
56         cerr << endl;
57
58         if (closestCop > 0)
59                 max = closestCop;
60
61         if (max > 1){
62                 list<string> closestCarCop = shortestPath(to, cop_car, FindPlayer(_players, cop_car, max - 1), true);
63                 cerr << "Cop in car " << closestCarCop.size() << " intersections away." << endl;
64
65                 if (closestCarCop.size() > 0){
66                         closestCop = closestCarCop.size();
67                         copInCar = true;
68                 }
69         }
70
71         //cerr << "Cop " << closestCop << " intersections away." << endl;
72         if (closestCop > 0 && closestCop < 4)
73                 return 100;
74
75         cerr << "cost before cop: " << cost << endl;
76         if (closestCop > 2){
77                 cerr << "Cop " << closestCop << " intersections away." << endl;
78                 cost += 12 - (copInCar ? closestCop : closestCop - 1);
79         }
80         cerr << "cost after cop: " << cost << endl;
81
82         if (conInter->second.type == bank){
83                 //cerr << "FOUND A BANK" << endl;
84                 if (closestCop > 0 && closestCop < 4)
85                         return 1000;
86                 else if (_banks.find(to)->second > 0){
87                         //cerr << "No cop close to bank" << endl;
88                         return 1;
89                 }
90         }
91
92         if (to == _oldLocation)
93                 cost *= 2;
94         cerr << "Street: " << to << " cost: " << cost << endl;
95
96         return cost;
97 }
98
99 void Robber::move(std::string location){
100         cout << "rmov\\" << endl;
101         Bot::move(location);
102         cout << "nobribe:" << endl;
103         cout << "rmov/" << endl;
104 }
105
106 int main(){
107         Robber robber("harv-robber");
108         robber.play();
109
110         return 0;
111 }
112
113 #include "../botsrc/shortestPath.cpp"