X-Git-Url: https://ruin.nu/git/?p=icfp05.git;a=blobdiff_plain;f=bot%2Fbot.cpp;h=28e8004a2167997f2b5a8bbe629a486ac03f6711;hp=7605cf1ebd473c8b9b373c4c3fc9fc0a19caa185;hb=d7d9942fc9d1066670e166182e36791dfbf035d7;hpb=0fbd9bca7cd5cd937f306753f895cfe642dd9e6d diff --git a/bot/bot.cpp b/bot/bot.cpp index 7605cf1..28e8004 100644 --- a/bot/bot.cpp +++ b/bot/bot.cpp @@ -21,41 +21,6 @@ Bot::Bot(const string& name, PlayerType type){ _playerTypes["robber"] = robber; _playerTypes["cop-foot"] = cop_foot; _playerTypes["cop-car"] = cop_car; - /* - priority_queue, vector >, VectComp> pq; - - vector v; - v.push_back("hej"); - pq.push(v); - v.push_back("hå"); - pq.push(v); - v.push_back("blaha"); - pq.push(v); - v.clear(); - v.push_back("hej hå"); - pq.push(v); - v.clear(); - v.push_back("hejsan"); - pq.push(v); - v.push_back("what?"); - pq.push(v); - v.push_back("blaha"); - pq.push(v); - - cerr << "Size: " << pq.top().size() << " " << pq.top()[0] << endl; - pq.pop(); - cerr << "Size: " << pq.top().size() << " " << pq.top()[0] << endl; - pq.pop(); - cerr << "Size: " << pq.top().size() << " " << pq.top()[0] << endl; - pq.pop(); - cerr << "Size: " << pq.top().size() << " " << pq.top()[0] << endl; - pq.pop(); - cerr << "Size: " << pq.top().size() << " " << pq.top()[0] << endl; - pq.pop(); - cerr << "Size: " << pq.top().size() << " " << pq.top()[0] << endl; - pq.pop(); - -*/ } @@ -255,7 +220,7 @@ struct SPInfoComp{ } }; -std::list Bot::shortestPath(const std::string& from, PlayerType type, const SPGoal& goal){ +std::list Bot::shortestPath(const std::string& from, PlayerType type, const SPGoal& goal, bool reverse){ //cerr << "New shortest path from: " << from << endl; @@ -270,6 +235,7 @@ std::list Bot::shortestPath(const std::string& from, PlayerType typ pq.push(node); int g = 0; + bool hascar = type == cop_car; while(!pq.empty()){ node = pq.top(); pq.pop(); @@ -295,9 +261,23 @@ std::list Bot::shortestPath(const std::string& from, PlayerType typ for (hash_map::const_iterator street = inter.connections.begin(); street != inter.connections.end(); ++street){ hash_map::iterator newNode = nodes.find(street->first); - bool hascar = type == cop_car; - if ( (hascar && (street->second == car || street->second == both)) || - (!hascar && (street->second == foot || street->second == both))){ + bool travelStreet = false; + if (hascar){ + if (reverse){ + if (street->second != foot){ + hash_map::const_iterator st = _intersections[street->first].connections.find(node->name); + if (st != _intersections[street->first].connections.end()) + travelStreet = st->second != foot; + else + travelStreet = false; + }else + travelStreet = true; + }else + travelStreet = street->second != foot; + }else{ + travelStreet = street->second != car; + } + if (travelStreet){ //cerr << "Adding street: " << street->first << endl; SPInfo* n = 0; if (newNode == nodes.end()){ @@ -324,3 +304,27 @@ std::list Bot::shortestPath(const std::string& from, PlayerType typ return list(); } + +SimpleSPGoal::SimpleSPGoal(std::string to):_to(to){ +} + +int SimpleSPGoal::operator()(const SPInfo* node) const{ + if (node->name == _to) + return 1; + return 0; +} + +FindPlayer::FindPlayer(const hash_map& players, PlayerType type, int limit) : _players(players), _type(type), _limit(limit){ +} + +int FindPlayer::operator()(const SPInfo* node) const{ + if (_limit > 0 && node->cost >= _limit) + return -1; + for(hash_map::const_iterator player = _players.begin(); + player != _players.end(); ++player){ + if (player->second.type == _type && player->second.location == node->name){ + return 1; + } + } + return 0; +}