X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=copsrc%2Fcop.cpp;h=411c11122365b89e0d16a5c3fa01fcd9b765357d;hb=HEAD;hp=fd40792bfc10151d5416a7360d33beb2a131a3a4;hpb=a76a0b3a94ab89c98135829d163a5fd303398f98;p=icfp05.git diff --git a/copsrc/cop.cpp b/copsrc/cop.cpp index fd40792..411c111 100644 --- a/copsrc/cop.cpp +++ b/copsrc/cop.cpp @@ -8,29 +8,6 @@ using namespace std; using namespace __gnu_cxx; -string Cop::turn(){ - //cerr << "New turn" << endl; - string input; - - sendInformation(); - //cerr << "Getting information " << endl; - getInformation(); - - sendPlan(); - getPlans(); - - vote(); - - getline(cin,input); - if (input != "nowinner:"){ - string winner = value(input); - if (winner != _name) - ++_winningPlans[winner]; - } - - return _location; -} - void Cop::preGamePreparations(){ //cerr << "Preparing.." << endl; _copTargets[_name].first = _robberLocation; @@ -57,7 +34,7 @@ void Cop::preGamePreparations(){ } for (hash_map::const_iterator player = _players.begin(); player != _players.end(); ++player){ - cerr << "Inital plan for player: " << player->first << endl; + //cerr << "Inital plan for player: " << player->first << endl; if (player->second.type == robber){ _robber = player->first; continue; @@ -228,7 +205,7 @@ int Cop::maybeAtNeighbor(const Intersection& intersection){ void Cop::sendPlan(){ //cerr << "Planning" << endl; - string secondLocation = _robberLocation; + list locations; if (_robberLocation.empty()){ priority_queue > positions; for (hash_map::iterator location = _maybeRobber.front().begin(); @@ -239,37 +216,44 @@ void Cop::sendPlan(){ } if (positions.size() > 0){ _robberLocation = positions.top().second; - cerr << "Sending myself to: " << _robberLocation << ", probability of robber: " << positions.top().first << endl; + //cerr << "Sending myself to: " << _robberLocation << ", probability of robber: " << positions.top().first << endl; } - if (positions.size() > 1){ + for (int i = 0; i < 2 && positions.size() > 1; ++i ){ positions.pop(); - secondLocation = positions.top().second; - cerr << "Sending another cop to: " << secondLocation << ", probability of robber: " << positions.top().first << endl; + locations.push_back(positions.top().second); + //cerr << "Sending another cop to: " << locations.back() << ", probability of robber: " << positions.top().first << endl; } + }else{ + locations.push_back(_robberLocation); + locations.push_back(_robberLocation); } if (!_robberLocation.empty()){ //cerr << "Robber found at " << _robberLocation << endl; _copTargets[_name].first = _robberLocation; - - if (!secondLocation.empty()){ - list closestFootCop = shortestPath(_robberLocation, cop_foot, FindPlayer(_players, cop_foot), true); - list closestCarCop = shortestPath(_robberLocation, cop_car, FindPlayer(_players, cop_car, closestFootCop.size() - 1), true); - PlayerType copType = cop_foot; - string copLocation; - if (closestCarCop.size() > 0){ - copType = cop_car; - copLocation = closestCarCop.back(); - }else - copLocation = closestFootCop.back(); - - + + vector busyCops; + busyCops.push_back(_name); + while (locations.size() > 0){ + string cop; + int dist = 1000000; for (hash_map::const_iterator player = _players.begin(); - player != _players.end(); ++player){ - if (player->first == _name || player->second.type == robber) + player != _players.end();++player){ + if (player->second.type == robber || find(busyCops.begin(), busyCops.end(), player->first) != busyCops.end()) continue; - if (player->second.type == copType && player->second.location == copLocation) - _copTargets[player->first].first = _robberLocation; + list l = shortestPath(player->second.location, player->second.type,SimpleSPGoal(locations.front(), dist-1)); + if (l.size() > 0 && l.size() < dist){ + dist = l.size(); + cop = player->first; + if (dist == 1) + break; + } + } + if (!cop.empty()){ + //cerr << "Sending " << cop << " to " << locations.front() << endl; + _copTargets[cop].first = locations.front(); + busyCops.push_back(cop); } + locations.pop_front(); } } //cerr << "Sending plan." << endl; @@ -296,33 +280,15 @@ void Cop::sendPlan(){ cout << "plan/" << endl; } -void Cop::getPlans(){ - string input; - - - //ignore From-plan - do{ - getline(cin,input); - }while(input != "from/"); - - -} - -void Cop::vote(){ - cout << "vote\\" << endl; - cout << "vote: " << _name << endl; - priority_queue > players; - for (hash_map::const_iterator player = _winningPlans.begin(); - player != _winningPlans.end(); ++player){ - players.push(pair(-player->second, player->first)); - } - while (players.size() > 0){ - const pair& player = players.top(); - cout << "vote: " << player.second << endl; - //cerr << "voted for " << player.second << " with " << player.first << " previously won plans" << endl; - players.pop(); - } - cout << "vote/" << endl; +void Cop::move(std::string location){ + cout << "cmov\\" << endl; + cout << "straight-arrow:" << endl; + cout << "mov\\" << endl; + Bot::move(location); + cout << "mov/" << endl; + cout << "acc\\" << endl; + cout << "acc/" << endl; + cout << "cmov/" << endl; } int main(){ @@ -331,3 +297,5 @@ int main(){ return 0; } + +#include "../botsrc/shortestPath.cpp"