9 using namespace __gnu_cxx;
12 //cerr << "New turn" << endl;
16 //cerr << "Getting information " << endl;
25 if (input != "nowinner:"){
26 string winner = value<string>(input);
28 ++_winningPlans[winner];
34 void Cop::preGamePreparations(){
35 //cerr << "Preparing.." << endl;
36 _copTargets[_name].first = _robberLocation;
37 _copTargets[_name].second = cop_foot;
39 priority_queue<pair<int,string> > banks;
40 //cerr << "Number of banks: " << endl;
41 for(hash_map<string,int>::const_iterator bank = _banks.begin();
42 bank != _banks.end(); ++bank){
43 //cerr << "Finding bank: " << bank->first << endl;
44 list<string> bankRoute = shortestPath(_robberLocation, robber, SimpleSPGoal(bank->first));
45 //cerr << "Pushing bank" << endl;
46 banks.push(pair<int,string>(-bankRoute.size(), bank->first));
48 //cerr << "Done finding banks.." << endl;
49 priority_queue<pair<int,string> > banks2;
50 for (int i = 0; i < 4 && banks.size() > 0;++i){
51 const pair<int,string>& bank = banks.top();
52 //cerr << "Going to bank: " << bank.second << ", distance" << -bank.first << endl;
53 list<string> bankRouteFoot = shortestPath(_copHq, cop_foot, SimpleSPGoal(bank.second));
54 list<string> bankRouteCar = shortestPath(_copHq, cop_car, SimpleSPGoal(bank.second));
55 banks2.push(pair<int,string>(bankRouteCar.size() - bankRouteFoot.size(), bank.second));
58 for (hash_map<string,Player>::const_iterator player = _players.begin();
59 player != _players.end() && banks2.size() > 0; ++player){
60 if (player->first == _name || player->second.type == robber)
62 const pair<int,string>& bank = banks2.top();
63 _copTargets[player->first].first = bank.second;
64 //cerr << "Sending: " << player->first << " to: " << bank.second;
65 if (banks2.size() <= 2)
66 _copTargets[player->first].second = cop_car;
68 _copTargets[player->first].second = cop_foot;
69 //cerr << " on: " << _copTargets[player->first].second << endl;
70 _winningPlans[player->first] = 0;
75 void Cop::sendInformation(){
76 cout << "inf\\" << endl;
77 cout << "inf/" << endl;
80 void Cop::getInformation(){
83 if (false && _robberLocation.empty()){ //Disable for now, since it takes to long time, and does nothing
85 //TODO: Calculate smell
99 istringstream inf(input);
112 //TODO: Calculate possibilties
118 }while(input != "from/");
123 void Cop::sendPlan(){
124 //cerr << "Planning" << endl;
125 if (_robberLocation.empty()){
126 //Use information for plan.
129 //cerr << "Robber found at " << _robberLocation << endl;
130 _copTargets[_name].first = _robberLocation;
131 list<string> closestFootCop = shortestPath(_robberLocation, cop_foot, FindPlayer(_players, cop_foot), true);
132 list<string> closestCarCop = shortestPath(_robberLocation, cop_car, FindPlayer(_players, cop_car, closestFootCop.size() - 1), true);
133 PlayerType copType = cop_foot;
135 if (closestCarCop.size() > 0){
137 copLocation = closestCarCop.back();
139 copLocation = closestFootCop.back();
142 for (hash_map<string,Player>::const_iterator player = _players.begin();
143 player != _players.end(); ++player){
144 if (player->first == _name || player->second.type == robber)
146 if (player->second.type == copType && player->second.location == copLocation)
147 _copTargets[player->first].first = _robberLocation;
150 //cerr << "Sending plan." << endl;
151 cout << "plan\\" << endl;
152 for(hash_map<string, pair<string, PlayerType> >::iterator player = _copTargets.begin();
153 player != _copTargets.end(); ++player){
154 Player& pl = _players[player->first];
155 if (pl.type != player->second.second
156 && pl.location != _copHq)
157 player->second.second = pl.type;
158 list<string> playerRoute = shortestPath(pl.location, player->second.second, SimpleSPGoal(player->second.first));
159 if (playerRoute.size() > 1){
160 list<string>::iterator i = playerRoute.begin();
162 if (*i == _robberLocation || !(playerRoute.size() == 2 && _intersections[*i].type == bank)){
163 if (player->first == _name)
165 //cerr << "Sending " << player->first << " to " << *i << " by " << player->second.second << endl;
166 cout << "plan: " << player->first << " " << *i << " " << _playerTypeNames[player->second.second] << " " << _world+1 << endl;
171 cout << "plan/" << endl;
174 void Cop::getPlans(){
181 }while(input != "from/");
187 cout << "vote\\" << endl;
188 cout << "vote: " << _name << endl;
189 priority_queue<pair<int,string> > players;
190 for (hash_map<string,int>::const_iterator player = _winningPlans.begin();
191 player != _winningPlans.end(); ++player){
192 players.push(pair<int,string>(-player->second, player->first));
194 while (players.size() > 0){
195 const pair<int,string>& player = players.top();
196 cout << "vote: " << player.second << endl;
197 //cerr << "voted for " << player.second << " with " << player.first << " previously won plans" << endl;
200 cout << "vote/" << endl;