X-Git-Url: https://ruin.nu/git/?p=icfp05.git;a=blobdiff_plain;f=botsrc%2Fbot.cpp;fp=botsrc%2Fbot.cpp;h=10fb5447952d3e4bd58c21e80af169cb2fbf7e6e;hp=e9950a6ac3e810f33c90b2bda3606c4668fd5ecd;hb=f0bca5d0e69c0d1035c6b32b7d2c27e671f7060b;hpb=42e51f90d84089aa6ecf4b84939bd57b89fe125e 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]; + } +}