]> ruin.nu Git - icfp05.git/blob - newrobber/robber.cpp
initial implementation of new robber
[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         if (node->cost > 10 || (clock()-_time)/CLOCKS_PER_SEC > 2.4)
34                 return 1;
35         return 0;
36 }
37
38 int Robber::cost(const std::string& from, const std::string& to) const{
39
40         //cerr << "Calculating cost between " << from << " and " << to << endl;
41         hash_map<string,Intersection>::const_iterator conInter =  _intersections.find(to);
42         if (conInter == _intersections.end())
43                 return 1000000; //Should never happen
44
45         int cost = 1;
46
47         list<string> closestFootCop = shortestPath(to, cop_foot, FindPlayer(_players, cop_foot, 10), true);
48         unsigned int closestCop = closestFootCop.size();
49         bool copInCar = false;
50         //cerr << "Cop on fot " << closestCop << " intersections away." << endl;
51
52         if (closestCop > 0 && closestCop < 3)
53                 return 100;
54
55         list<string> closestCarCop = shortestPath(to, cop_car, FindPlayer(_players, cop_car, closestCop - 1 > 0 ? closestCop : 5), true);
56         //cerr << "Cop in car " << closestCarCop.size() << " intersections away." << endl;
57
58         if (closestCarCop.size() > 0){
59                 closestCop = closestCarCop.size();
60                 copInCar = true;
61         }
62
63         //cerr << "Cop " << closestCop << " intersections away." << endl;
64         if (closestCop > 0 && closestCop < 3)
65                 return 100;
66
67         //cerr << "Goodness before cop: " << goodness << endl;
68         if (closestCop > 2){
69                 //cerr << "Cop " << closestCop << " intersections away." << endl;
70                 cost += 8 - (copInCar ? closestCop : closestCop - 1);
71         }
72         //cerr << "Goodness after cop: " << goodness << endl;
73
74         if (conInter->second.type == bank){
75                 //cerr << "FOUND A BANK" << endl;
76                 if (closestCop > 0 && closestCop < 4)
77                         return 1000;
78                 else if (_banks.find(to)->second > 0){
79                         //cerr << "No cop close to bank" << endl;
80                         return 1;
81                 }
82         }
83
84         if (to == _oldLocation)
85                 cost *= 2;
86         cerr << "Street: " << to << " cost: " << cost << endl;
87
88         return cost;
89 }
90
91 void Robber::move(std::string location){
92         cout << "rmov\\" << endl;
93         Bot::move(location);
94         cout << "nobribe:" << endl;
95         cout << "rmov/" << endl;
96 }
97
98 int main(){
99         Robber robber("harv-robber");
100         robber.play();
101
102         return 0;
103 }
104
105 #include "../botsrc/shortestPath.cpp"