X-Git-Url: https://ruin.nu/git/%3CTMPL_VAR%20NAME=PAGE%3E?a=blobdiff_plain;f=botsrc%2Fbot.cpp;h=411d933ee50d7bab0ab689b320a753d464cb3f06;hb=7ea4f9f073009ba9a6bbf2fec398b0742f798658;hp=e9950a6ac3e810f33c90b2bda3606c4668fd5ecd;hpb=d3bca66246f3489aa03d5e0fa7d10ca62511c11d;p=icfp05.git diff --git a/botsrc/bot.cpp b/botsrc/bot.cpp index e9950a6..411d933 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; } @@ -139,10 +155,19 @@ void Bot::buildGraph(){ if (type == "foot"){ _intersections[from].connections[to] = both; Intersection& inter = _intersections[to]; - if (inter.connections.find(from) == inter.connections.end()) + hash_map::iterator conn = inter.connections.find(from); + if (conn == inter.connections.end()) inter.connections[from] = foot; - }else - _intersections[from].connections[to] = car; + else if (conn->second == car) + inter.connections[from] = both; + }else{ + Intersection& inter = _intersections[from]; + hash_map::iterator conn = inter.connections.find(to); + if (conn == inter.connections.end()) + inter.connections[from] = car; + else if (conn->second == foot) + inter.connections[from] = both; + } } //cerr << "Number of streets: " << streets << endl; getline(cin, input); @@ -157,6 +182,30 @@ void Bot::updateWorld(){ 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 +258,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 @@ -222,7 +271,7 @@ T value(std::string input){ } std::string Bot::turn(){ - cerr << "Using stupid stand still Bot::turn" << endl; + //cerr << "Using stupid stand still Bot::turn" << endl; return _location; } @@ -320,10 +369,12 @@ std::list Bot::shortestPath(const std::string& from, PlayerType typ return list(); } -SimpleSPGoal::SimpleSPGoal(std::string to):_to(to){ +SimpleSPGoal::SimpleSPGoal(const std::string& to, int limit):_to(to), _limit(limit){ } int SimpleSPGoal::operator()(const SPInfo* node) const{ + if (_limit > 0 && node->cost >= _limit) + return -1; if (node->name == _to) return 1; return 0; @@ -343,3 +394,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]; + } +}