]> ruin.nu Git - icfp05.git/blobdiff - bot/bot.cpp
fixed priority queue and started to implement the robber algorithm, it needs tuning...
[icfp05.git] / bot / bot.cpp
index 2829030b3dfe4b26cc2652ffb667759892d7131e..1c2b4dccf9adaf079abcdb2038aecf96ebd24020 100644 (file)
@@ -8,9 +8,51 @@
 using namespace std;
 using namespace __gnu_cxx;
 
+struct VectComp{
+       bool operator()(const vector<string>& v1, const vector<string>& v2){
+               return v1.size() > v2.size();
+       }
+};
 Bot::Bot(string name, string type){
        _name = name;
        _type = type;
+
+       /*
+       priority_queue<vector<string>, vector<vector<string> >, VectComp> pq;
+
+       vector<string> 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<int>(input);
-       cerr << "World: " << _world << endl;
+       //cerr << "World: " << _world << endl;
 
        getline(cin,input);
        _robbed = value<int>(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<std::string> Bot::shortestPath(std::string from, std::string to, std::string type){
        
-       priority_queue<vector<string>, vector<vector<string> >, greater<vector<string> > > pq;
+       priority_queue<vector<string>, vector<vector<string> >, VectComp > pq;
 
        vector<string> v;
        v.push_back(from);
@@ -198,25 +240,31 @@ std::vector<std::string> Bot::shortestPath(std::string from, std::string to, std
        hash_map<string,bool> settled;
 
        while(!pq.empty()){
-               const vector<string>& w = pq.top();
+               const vector<string> 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<string>(cerr, " : "));
                if (w.back() == to)
                        return w;
                settled[w.back()] = true;
                Intersection& inter = _intersections[w.back()];
                for (hash_map<string,StreetType>::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<string>();