From f0bca5d0e69c0d1035c6b32b7d2c27e671f7060b Mon Sep 17 00:00:00 2001 From: Michael Andreen Date: Sat, 9 Jul 2005 16:12:10 +0000 Subject: [PATCH] initial change to new version --- botsrc/bot.cpp | 98 ++++++++++++++++++++++++++++++++++++++++++++++++-- botsrc/bot.h | 39 +++++++++++--------- copsrc/cop.cpp | 60 ++++++------------------------- copsrc/cop.h | 5 +-- 4 files changed, 130 insertions(+), 72 deletions(-) diff --git a/botsrc/bot.cpp b/botsrc/bot.cpp index e9950a6..10fb544 100644 --- a/botsrc/bot.cpp +++ b/botsrc/bot.cpp @@ -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(input); - //cerr << "World: " << _world << endl; + cerr << "World: " << _world << endl; getline(cin,input); _robbed = value(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 @@ -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 > 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 Bot::voteResult(){ + string input; + getline(cin,input); + if (input != "nowinner:"){ + string winner = value(input); + if (winner != _name) + ++_winningPlans[winner]; + } +} diff --git a/botsrc/bot.h b/botsrc/bot.h index 306ec7e..84f9de5 100644 --- a/botsrc/bot.h +++ b/botsrc/bot.h @@ -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 shortestPath(const std::string& from, PlayerType type, const SPGoal& goal, bool reverse = false); - __gnu_cxx::hash_map _intersections; - __gnu_cxx::hash_map _players; - __gnu_cxx::hash_map _banks; - std::map _evidence; - std::map _playerTypeNames; - std::map _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 _intersections; + __gnu_cxx::hash_map _players; + __gnu_cxx::hash_map _banks; + std::map _evidence; + std::map _playerTypeNames; + std::map _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 _winningPlans; }; class SimpleSPGoal : public SPGoal{ diff --git a/copsrc/cop.cpp b/copsrc/cop.cpp index fd40792..aed3aeb 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; @@ -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 > 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(){ diff --git a/copsrc/cop.h b/copsrc/cop.h index 3b1d3a1..6f8af75 100644 --- a/copsrc/cop.h +++ b/copsrc/cop.h @@ -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 > _copTargets; std::list<__gnu_cxx::hash_map > _maybeRobber; - __gnu_cxx::hash_map _winningPlans; std::string _robber; }; #endif -- 2.39.2