7 using namespace __gnu_cxx;
9 struct FindCop : SPGoal{
11 const hash_map<string, Player>& _players;
12 FindCop(const hash_map<string, Player>& players, int limit = 0) : _players(players), _limit(limit){}
13 int operator()(const SPInfo* node) const{
14 if (_limit > 0 && node->cost > _limit)
16 for(hash_map<string, Player>::const_iterator player = _players.begin();
17 player != _players.end(); ++player){
18 if (player->second.type != robber && player->second.location == node->name){
26 string Robber::turn(){
27 hash_map<string,double> streets;
28 Intersection& inter = _intersections[_location];
29 for (hash_map<string,StreetType>::const_iterator street = inter.connections.begin();
30 street != inter.connections.end(); ++street){
31 if (street->second == car){
32 cerr << "Discarding: " << street->first << " since car is needed" << endl;
36 Intersection& conInter = _intersections[street->first];
38 if (conInter.type == bank){
39 cerr << "FOUND A BANK" << endl;
40 list<string> l = shortestPath(_location, _type, FindCop(_players, 3));
42 cerr << "Cop " << l.size() << " intersections away." << endl;
44 }else if (_banks[street->first] > 0){
45 cerr << "No cop close to bank" << endl;
52 int newx = conInter.x;
53 int newy = conInter.y;
54 for (hash_map<string, Player>::const_iterator player = _players.begin();
55 player != _players.end(); ++player){
56 if (player->first == _name)
59 int px = _intersections[player->second.location].x;
60 int py = _intersections[player->second.location].y;
62 double dist1 = sqrt(pow((curx-px),2.0)+pow((cury-py),2.0));
63 double dist2 = sqrt(pow((newx-px),2.0)+pow((newy-py),2.0));
64 /*cerr << "Original distance: " << dist1 << endl;
65 cerr << "New distance: " << dist2 << endl;
69 if (dist2 < 50 && dist2 < dist1)
72 if (player->second.type == cop_foot && dist2 <= 3)
74 else if (player->second.type == cop_car && dist2 <= 2)
80 cerr << "Street: " << street->first << " goodness: " << goodness << endl;
81 streets[street->first] = goodness;
83 streets[_oldLocation] /= 10;
85 for(hash_map<string,int>::const_iterator bank = _banks.begin();
86 bank != _banks.end(); ++bank){
87 //cerr << "Handling bank at: " << bank->first << endl;
88 if (bank->second > 0){
89 list<string> l = shortestPath(_location, _type, SimpleSPGoal(bank->first));
92 list<string>::iterator i = l.begin();
93 if (*++i == "53-and-kimbark")
94 cerr << "We should NOT find 53-and-kimbark here" << endl;
95 streets[*i] += bank->second/(pow(5.0,double(l.size())));
100 /*cerr << "Using route: ";
101 copy(v.begin(), v.end(), ostream_iterator<string>(cerr, " : "));
107 for (hash_map<string,double>::const_iterator dest = streets.begin();
108 dest != streets.end(); ++dest){
109 cerr << "Goodness: " << dest->second << endl;
110 if (dest->second > goodness){
111 cerr << "New Goodness: " << dest->second << endl;
112 goodness = dest->second;
113 destination = dest->first;
116 _oldLocation = _location;
123 Robber robber("robber");