X-Git-Url: https://ruin.nu/git/?p=icfp05.git;a=blobdiff_plain;f=bot%2Fbot.cpp;h=1c2b4dccf9adaf079abcdb2038aecf96ebd24020;hp=2829030b3dfe4b26cc2652ffb667759892d7131e;hb=c587459e89e9d1123425df5b42a367e7bf439e64;hpb=9363db6b1b8322c4f424ce44db173f251336066e diff --git a/bot/bot.cpp b/bot/bot.cpp index 2829030..1c2b4dc 100644 --- a/bot/bot.cpp +++ b/bot/bot.cpp @@ -8,9 +8,51 @@ using namespace std; using namespace __gnu_cxx; +struct VectComp{ + bool operator()(const vector& v1, const vector& v2){ + return v1.size() > v2.size(); + } +}; Bot::Bot(string name, string type){ _name = name; _type = type; + + /* + 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(); + +*/ + } void Bot::play(){ @@ -123,11 +165,11 @@ void Bot::updateWorld(){ string input; getline(cin,input); _world = value(input); - cerr << "World: " << _world << endl; + //cerr << "World: " << _world << endl; getline(cin,input); _robbed = value(input); - cerr << "Robbed: " << _robbed << endl; + //cerr << "Robbed: " << _robbed << endl; getline(cin,input); while (true){ @@ -139,7 +181,7 @@ void Bot::updateWorld(){ bank >> input; bank >> _banks[input]; } - cerr << "Number of banks: " << _banks.size() << endl; + //cerr << "Number of banks: " << _banks.size() << endl; getline(cin,input); while (true){ @@ -160,12 +202,12 @@ void Bot::updateWorld(){ istringstream player(input); player >> input; player >> input; - cerr << "Player: " << input << endl; + //cerr << "Player: " << input << endl; Player& pl = _players[input]; player >> pl.location; player >> pl.type; } - cerr << "Number of players: " << _players.size() << endl; + //cerr << "Number of players: " << _players.size() << endl; } void Bot::move(std::string location){ @@ -189,7 +231,7 @@ std::string Bot::turn(){ std::vector Bot::shortestPath(std::string from, std::string to, std::string type){ - priority_queue, vector >, greater > > pq; + priority_queue, vector >, VectComp > pq; vector v; v.push_back(from); @@ -198,25 +240,31 @@ std::vector Bot::shortestPath(std::string from, std::string to, std hash_map settled; while(!pq.empty()){ - const vector& w = pq.top(); + const vector w = pq.top(); + pq.pop(); + //cerr << "Vector with size: " << w.size() << endl; + //cerr << "Looking at: " << w.back() << endl; + //copy(w.begin(), w.end(), ostream_iterator(cerr, " : ")); if (w.back() == to) return w; settled[w.back()] = true; Intersection& inter = _intersections[w.back()]; for (hash_map::const_iterator street = inter.connections.begin(); street != inter.connections.end(); ++street){ - if (settled.find(street->first) == settled.end()) + if (settled.find(street->first) != settled.end()) continue; - bool car = type == "cop-car"; - if ( (car && (street->second == car || street->second == both)) || - (!car && (street->second == foot || street->second == both))){ + //cerr << "Adding: " << street->first << endl; + bool hascar = type == "cop-car"; + if ( (hascar && (street->second == car || street->second == both)) || + (!hascar && (street->second == foot || street->second == both))){ + v = w; v.push_back(street->first); pq.push(v); } + } - pq.pop(); } return vector();