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 list<string> l = shortestPath(street->first, _type, FindCop(_players, 5));
40 cerr << "Cop " << l.size() << " intersections away." << endl;
41 goodness *= 1 - 1/(6 - l.size());
44 if (conInter.type == bank){
45 cerr << "FOUND A BANK" << endl;
46 if (l.size() > 0 && l.size() < 4)
48 else if (_banks[street->first] != 0){
49 cerr << "No cop close to bank" << endl;
56 int newx = conInter.x;
57 int newy = conInter.y;
58 for (hash_map<string, Player>::const_iterator player = _players.begin();
59 player != _players.end(); ++player){
60 if (player->first == _name)
63 int px = _intersections[player->second.location].x;
64 int py = _intersections[player->second.location].y;
66 double dist1 = sqrt(pow((curx-px),2.0)+pow((cury-py),2.0));
67 double dist2 = sqrt(pow((newx-px),2.0)+pow((newy-py),2.0));
68 /*cerr << "Original distance: " << dist1 << endl;
69 cerr << "New distance: " << dist2 << endl;
73 if (dist2 < 50 && dist2 < dist1)
76 if (player->second.type == cop_foot && dist2 <= 3)
78 else if (player->second.type == cop_car && dist2 <= 2)
84 cerr << "Street: " << street->first << " goodness: " << goodness << endl;
85 streets[street->first] = goodness;
87 streets[_oldLocation] /= 10;
89 for(hash_map<string,int>::const_iterator bank = _banks.begin();
90 bank != _banks.end(); ++bank){
91 //cerr << "Handling bank at: " << bank->first << endl;
92 if (bank->second > 0){
93 list<string> l = shortestPath(_location, _type, SimpleSPGoal(bank->first));
96 list<string>::iterator i = l.begin();
97 if (*++i == "53-and-kimbark")
98 cerr << "We should NOT find 53-and-kimbark here" << endl;
99 streets[*i] += bank->second/(pow(5.0,double(l.size())));
104 /*cerr << "Using route: ";
105 copy(v.begin(), v.end(), ostream_iterator<string>(cerr, " : "));
111 for (hash_map<string,double>::const_iterator dest = streets.begin();
112 dest != streets.end(); ++dest){
113 cerr << "Goodness: " << dest->second << endl;
114 if (dest->second > goodness){
115 cerr << "New Goodness: " << dest->second << endl;
116 goodness = dest->second;
117 destination = dest->first;
120 _oldLocation = _location;
127 Robber robber("robber");