]> ruin.nu Git - icfp05.git/commitdiff
initial change to new version
authorMichael Andreen <harv@ruin.nu>
Sat, 9 Jul 2005 16:12:10 +0000 (16:12 +0000)
committerMichael Andreen <harv@ruin.nu>
Sat, 9 Jul 2005 16:12:10 +0000 (16:12 +0000)
botsrc/bot.cpp
botsrc/bot.h
copsrc/cop.cpp
copsrc/cop.h

index e9950a6ac3e810f33c90b2bda3606c4668fd5ecd..10fb5447952d3e4bd58c21e80af169cb2fbf7e6e 100644 (file)
@@ -47,10 +47,26 @@ void Bot::play(){
                getline(cin, input);
                if (input == "game-over")
                        return;
+               cerr << input << endl;
+               cerr << "Updating world" << endl;
                updateWorld();
+               cerr << "Done updating world" << endl;
                _type = _players[_name].type;
                _location = _players[_name].location;
                //cerr << "New turn" << endl;
+               //
+               string input;
+
+               sendInformation();
+               //cerr << "Getting information " << endl;
+               getInformation();
+
+               sendPlan();
+               getPlans();
+
+               vote();
+               voteResult();
+
                move(turn());
                //cerr << "Done with turn." << endl;
        }
@@ -149,14 +165,40 @@ void Bot::buildGraph(){
 }
 
 void Bot::updateWorld(){
+       cerr << "Entered updateWorld function" << endl;
        string input;
        getline(cin,input);
+       cerr << input << endl;
        _world = value<int>(input);
-       //cerr << "World: " << _world << endl;
+       cerr << "World: " << _world << endl;
 
        getline(cin,input);
        _robbed = value<int>(input);
        //cerr << "Robbed: " << _robbed << endl;
+       //
+       getline(cin,input);
+       while (true){
+               getline(cin, input);
+               if (input == "dc/")
+                       break;
+               istringstream dirtyCop(input);
+       }
+
+       getline(cin,input);
+       while (true){
+               getline(cin, input);
+               if (input == "sc/")
+                       break;
+               istringstream controlledCop(input);
+       }
+
+       getline(cin,input);
+       while (true){
+               getline(cin, input);
+               if (input == "fac/")
+                       break;
+               istringstream falseAccusation(input);
+       }
 
        getline(cin,input);
        while (true){
@@ -209,7 +251,7 @@ void Bot::updateWorld(){
 
 void Bot::move(std::string location){
        //cerr << "Moving to: " << location << endl;
-       cout << "mov: " << location << " " << _playerTypeNames[_type] << endl;
+       cout << "mov: " << location << " " << _playerTypeNames[_type] << " " << _name << endl;
 }
 
 template<class T>
@@ -343,3 +385,55 @@ int FindPlayer::operator()(const SPInfo* node) const{
        }
        return 0;
 }
+
+void Bot::sendInformation(){
+       cout << "inf\\" << endl;
+       cout << "inf/" << endl;
+}
+
+void Bot::getInformation(){
+       string input;
+       do{
+               getline(cin,input);
+       }while(input != "from/");
+}
+
+void Bot::sendPlan(){
+       cout << "plan\\" << endl;
+       cout << "plan/" << endl;
+}
+
+void Bot::getPlans(){
+       string input;
+       //ignore From-plan
+       do{
+               getline(cin,input);
+       }while(input != "from/");
+}
+
+void Bot::vote(){
+       cout << "vote\\" << endl;
+       cout << "vote: " << _name << endl;
+       priority_queue<pair<int,string> > players;
+       for (hash_map<string,int>::const_iterator player = _winningPlans.begin();
+                       player != _winningPlans.end(); ++player){
+               players.push(pair<int,string>(-player->second, player->first));
+       }
+       while (players.size() > 0){
+               const pair<int,string>& 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 Bot::voteResult(){
+       string input;
+       getline(cin,input);
+       if (input != "nowinner:"){
+               string winner = value<string>(input);
+               if (winner != _name)
+                       ++_winningPlans[winner];
+       }
+}
index 306ec7ef52fb9c64f6ab52bf62f09c0a0bdd8030..84f9de58f4d149d0859d898f7338da5fedd555c6 100644 (file)
@@ -81,26 +81,33 @@ class Bot {
        protected:
                void buildGraph();
                void updateWorld();
-               virtual std::string turn() = 0;
+               virtual std::string turn();
                virtual void preGamePreparations(){};
-               void move(std::string location);
+               virtual void move(std::string location);
+               virtual void sendInformation();
+               virtual void getInformation();
+               virtual void sendPlan();
+               virtual void getPlans();
+               virtual void vote();
+               virtual void voteResult();
                void getPlayers();
                std::list<std::string> shortestPath(const std::string& from, PlayerType type, const SPGoal& goal, bool reverse = false);
 
-       __gnu_cxx::hash_map<std::string, Intersection> _intersections;
-       __gnu_cxx::hash_map<std::string, Player> _players;
-       __gnu_cxx::hash_map<std::string, int> _banks;
-       std::map<int, std::string> _evidence;
-       std::map<PlayerType, std::string> _playerTypeNames;
-       std::map<std::string, PlayerType> _playerTypes;
-       std::string _name;
-       PlayerType _type;
-       std::string _location;
-       int _world;
-       int _robbed;
-       int _smell;
-       std::string _robberLocation;
-       std::string _copHq;
+               __gnu_cxx::hash_map<std::string, Intersection> _intersections;
+               __gnu_cxx::hash_map<std::string, Player> _players;
+               __gnu_cxx::hash_map<std::string, int> _banks;
+               std::map<int, std::string> _evidence;
+               std::map<PlayerType, std::string> _playerTypeNames;
+               std::map<std::string, PlayerType> _playerTypes;
+               std::string _name;
+               PlayerType _type;
+               std::string _location;
+               int _world;
+               int _robbed;
+               int _smell;
+               std::string _robberLocation;
+               std::string _copHq;
+               __gnu_cxx::hash_map<std::string, int> _winningPlans;
 };
 
 class SimpleSPGoal : public SPGoal{
index fd40792bfc10151d5416a7360d33beb2a131a3a4..aed3aeb2b963d9aa6120370dcaa7ee84f56ed34e 100644 (file)
@@ -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<string>(input);
-               if (winner != _name)
-                       ++_winningPlans[winner];
-       }
-
-       return _location;
-}
-
 void Cop::preGamePreparations(){
        //cerr << "Preparing.." << endl;
        _copTargets[_name].first = _robberLocation;
@@ -148,6 +125,7 @@ void Cop::sendInformation(){
                        location != maybeRobber.end(); ++location){
                if (location->second > 0)
                        location->second /= possibilities;
+               cerr << "World: " << _world << endl;;
                cout << "inf: " << _robber << " " << location->first << " " << _playerTypeNames[robber] << " "
                        << _world << " " << location->second << endl;
        }
@@ -296,33 +274,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<pair<int,string> > players;
-       for (hash_map<string,int>::const_iterator player = _winningPlans.begin();
-                       player != _winningPlans.end(); ++player){
-               players.push(pair<int,string>(-player->second, player->first));
-       }
-       while (players.size() > 0){
-               const pair<int,string>& 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(){
index 3b1d3a13e93a453cdf9f607802b8ed0bda36da21..6f8af753ae1e19dcb6c502b3832b5b01780e88cd 100644 (file)
@@ -8,19 +8,16 @@ class Cop : public Bot {
        public:
                Cop(std::string name):Bot(name,cop_foot){};
                
-               std::string turn();
        protected:
                virtual void preGamePreparations();
                void sendInformation();
                void getInformation();
                void sendPlan();
-               void getPlans();
-               void vote();
+               void move(std::string location);
                int maybeAtNeighbor(const Intersection& intersection);
 
                __gnu_cxx::hash_map<std::string, std::pair<std::string, PlayerType> > _copTargets;
                std::list<__gnu_cxx::hash_map<std::string, int> > _maybeRobber;
-               __gnu_cxx::hash_map<std::string, int> _winningPlans;
                std::string _robber;
 };
 #endif