9 using namespace __gnu_cxx;
11 void Cop::preGamePreparations(){
12 //cerr << "Preparing.." << endl;
13 _copTargets[_name].first = _robberLocation;
14 _copTargets[_name].second = cop_foot;
16 priority_queue<pair<int,string> > banks;
17 //cerr << "Number of banks: " << endl;
18 for(hash_map<string,int>::const_iterator bank = _banks.begin();
19 bank != _banks.end(); ++bank){
20 //cerr << "Finding bank: " << bank->first << endl;
21 list<string> bankRoute = shortestPath(_robberLocation, robber, SimpleSPGoal(bank->first));
22 //cerr << "Pushing bank" << endl;
23 banks.push(pair<int,string>(-bankRoute.size(), bank->first));
25 //cerr << "Done finding banks.." << endl;
26 priority_queue<pair<int,string> > banks2;
27 for (int i = 0; i < 4 && banks.size() > 0;++i){
28 const pair<int,string>& bank = banks.top();
29 //cerr << "Going to bank: " << bank.second << ", distance" << -bank.first << endl;
30 list<string> bankRouteFoot = shortestPath(_copHq, cop_foot, SimpleSPGoal(bank.second));
31 list<string> bankRouteCar = shortestPath(_copHq, cop_car, SimpleSPGoal(bank.second));
32 banks2.push(pair<int,string>(bankRouteCar.size() - bankRouteFoot.size(), bank.second));
35 for (hash_map<string,Player>::const_iterator player = _players.begin();
36 player != _players.end(); ++player){
37 //cerr << "Inital plan for player: " << player->first << endl;
38 if (player->second.type == robber){
39 _robber = player->first;
41 }else if (banks2.size() <= 0 || player->first == _name)
44 const pair<int,string>& bank = banks2.top();
45 _copTargets[player->first].first = bank.second;
46 //cerr << "Sending: " << player->first << " to: " << bank.second;
47 if (banks2.size() <= 2)
48 _copTargets[player->first].second = cop_car;
50 _copTargets[player->first].second = cop_foot;
51 //cerr << " on: " << _copTargets[player->first].second << endl;
52 _winningPlans[player->first] = 0;
55 _maybeRobber.push_back(hash_map<string,int>());
58 void Cop::sendInformation(){
59 _maybeRobber.push_back(hash_map<string,int>());
60 hash_map<string,int>& maybeRobber = _maybeRobber.back();
61 int possibilities = 0;
62 if (_robberLocation.empty()){
64 hash_map<string, Intersection>::const_iterator intersection = _intersections.find(_location);
66 for (hash_map<string,StreetType>::const_iterator adj = intersection->second.connections.begin();
67 adj != intersection->second.connections.end(); ++adj){
70 hash_map<string,int>::iterator location = maybeRobber.find(adj->first);
71 if (location == maybeRobber.end()){
72 hash_map<string, Intersection>::const_iterator intersection = _intersections.find(adj->first);
73 int neigh = maybeAtNeighbor(intersection->second);
75 maybeRobber[adj->first] = 100 + neigh;
78 maybeRobber[adj->first] = -100;
82 maybeRobber[adj->first] = -100;
83 hash_map<string, Intersection>::const_iterator intersection = _intersections.find(adj->first);
84 for (hash_map<string,StreetType>::const_iterator adj = intersection->second.connections.begin();
85 adj != intersection->second.connections.end(); ++adj){
86 hash_map<string,int>::iterator location = maybeRobber.find(adj->first);
87 if (location == maybeRobber.end()){
89 maybeRobber[adj->first] = -100;
91 hash_map<string, Intersection>::const_iterator intersection = _intersections.find(adj->first);
92 int neigh = maybeAtNeighbor(intersection->second);
94 maybeRobber[adj->first] = 100 + neigh;
98 maybeRobber[adj->first] = -100;
105 maybeRobber[_robberLocation] = 100;
107 hash_map<string, Intersection>::const_iterator intersection = _intersections.find(_location);
109 for (hash_map<string,StreetType>::const_iterator adj = intersection->second.connections.begin();
110 adj != intersection->second.connections.end(); ++adj){
111 maybeRobber[adj->first] = -100;
112 for (hash_map<string,StreetType>::const_iterator adj = intersection->second.connections.begin();
113 adj != intersection->second.connections.end(); ++adj){
114 hash_map<string,int>::iterator location = maybeRobber.find(adj->first);
115 if (location != maybeRobber.end())
116 maybeRobber[adj->first] = -100;
123 cout << "inf\\" << endl;
124 for (hash_map<string,int>::iterator location = maybeRobber.begin();
125 location != maybeRobber.end(); ++location){
126 if (location->second > 0)
127 location->second /= possibilities;
128 cout << "inf: " << _robber << " " << location->first << " " << _playerTypeNames[robber] << " "
129 << _world << " " << location->second << endl;
131 cout << "inf/" << endl;
134 void Cop::getInformation(){
136 if (_robberLocation.empty()){
137 hash_map<string,int>& maybeRobber = _maybeRobber.back();
140 if (input == "from/")
150 istringstream inf(input);
158 if (type != _playerTypeNames[robber])
167 hash_map<string,int>::iterator location = maybeRobber.find(loc);
168 if (location == maybeRobber.end()){
169 hash_map<string, Intersection>::const_iterator intersection = _intersections.find(loc);
170 if (intersection != _intersections.end())
171 continue; //The intersection doesn't exist, so ignore it.
172 int neigh = maybeAtNeighbor(intersection->second);
174 maybeRobber[loc] = certainty + neigh;
176 maybeRobber[loc] = -200;
177 }else if (location->second > 0)
178 location->second += certainty;
184 }while(input != "from/");
186 _maybeRobber.pop_front();
190 int Cop::maybeAtNeighbor(const Intersection& intersection){
191 int possibility = -1;
192 for (hash_map<string,StreetType>::const_iterator adj = intersection.connections.begin();
193 adj != intersection.connections.end(); ++adj){
194 hash_map<string,int>::iterator oldLoc = _maybeRobber.front().find(adj->first);
195 if (oldLoc == _maybeRobber.front().end() || oldLoc->second > 0){
196 if (possibility < 0){
199 if (oldLoc != _maybeRobber.front().end())
200 possibility += oldLoc->second;
206 void Cop::sendPlan(){
207 //cerr << "Planning" << endl;
208 list<string> locations;
209 if (_robberLocation.empty()){
210 priority_queue<pair<int,string> > positions;
211 for (hash_map<string,int>::iterator location = _maybeRobber.front().begin();
212 location != _maybeRobber.front().end(); ++location){
213 if (location->second > 0)
214 positions.push(pair<int,string>(location->second,location->first));
217 if (positions.size() > 0){
218 _robberLocation = positions.top().second;
219 cerr << "Sending myself to: " << _robberLocation << ", probability of robber: " << positions.top().first << endl;
221 for (int i = 0; i < 2 && positions.size() > 1; ++i ){
223 locations.push_back(positions.top().second);
224 cerr << "Sending another cop to: " << locations.back() << ", probability of robber: " << positions.top().first << endl;
227 locations.push_back(_robberLocation);
228 locations.push_back(_robberLocation);
230 if (!_robberLocation.empty()){
231 //cerr << "Robber found at " << _robberLocation << endl;
232 _copTargets[_name].first = _robberLocation;
234 vector<string> busyCops;
235 busyCops.push_back(_name);
236 while (locations.size() > 0){
239 for (hash_map<string,Player>::const_iterator player = _players.begin();
240 player != _players.end();++player){
241 if (player->second.type == robber || find(busyCops.begin(), busyCops.end(), player->first) != busyCops.end())
243 list<string> l = shortestPath(player->second.location, player->second.type,SimpleSPGoal(locations.front(), dist-1));
244 if (l.size() > 0 && l.size() < dist){
252 cerr << "Sending " << cop << " to " << locations.front() << endl;
253 _copTargets[cop].first = locations.front();
254 busyCops.push_back(cop);
256 locations.pop_front();
259 //cerr << "Sending plan." << endl;
260 cout << "plan\\" << endl;
261 for(hash_map<string, pair<string, PlayerType> >::iterator player = _copTargets.begin();
262 player != _copTargets.end(); ++player){
263 Player& pl = _players[player->first];
264 if (pl.type != player->second.second
265 && pl.location != _copHq)
266 player->second.second = pl.type;
267 list<string> playerRoute = shortestPath(pl.location, player->second.second, SimpleSPGoal(player->second.first));
268 if (playerRoute.size() > 1){
269 list<string>::iterator i = playerRoute.begin();
271 if (*i == _robberLocation || !(playerRoute.size() == 2 && _intersections[*i].type == bank)){
272 if (player->first == _name)
274 //cerr << "Sending " << player->first << " to " << *i << " by " << player->second.second << endl;
275 cout << "plan: " << player->first << " " << *i << " " << _playerTypeNames[player->second.second] << " " << _world+1 << endl;
280 cout << "plan/" << endl;
283 void Cop::move(std::string location){
284 cout << "cmov\\" << endl;
285 cout << "straight-arrow:" << endl;
286 cout << "mov\\" << endl;
288 cout << "mov/" << endl;
289 cout << "acc\\" << endl;
290 cout << "acc/" << endl;
291 cout << "cmov/" << endl;