]> ruin.nu Git - icfp05.git/commitdiff
changed the shortest path algorithm to support reverse search
authorMichael Andreen <harv@ruin.nu>
Sun, 26 Jun 2005 22:34:21 +0000 (22:34 +0000)
committerMichael Andreen <harv@ruin.nu>
Sun, 26 Jun 2005 22:34:21 +0000 (22:34 +0000)
bot/bot.cpp
bot/bot.h
robber/robber.cpp

index 7605cf1ebd473c8b9b373c4c3fc9fc0a19caa185..713f1905657d4e16ac594297c57ac58a232e8597 100644 (file)
@@ -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<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();
-
-*/
 
 }
 
@@ -255,7 +220,7 @@ struct SPInfoComp{
        }
 };
 
-std::list<std::string> Bot::shortestPath(const std::string& from, PlayerType type, const SPGoal& goal){
+std::list<std::string> 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<std::string> 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<std::string> Bot::shortestPath(const std::string& from, PlayerType typ
                for (hash_map<string,StreetType>::const_iterator street = inter.connections.begin();
                                street != inter.connections.end(); ++street){
                        hash_map<string,SPInfo>::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<string,StreetType>::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()){
index d01ec114853e118456235efea29b4650d8d268c5..72d2d6bd7a88888bd3f9367dc3c783beac2c435b 100644 (file)
--- a/bot/bot.h
+++ b/bot/bot.h
@@ -83,7 +83,7 @@ class Bot {
                virtual std::string turn() = 0;
                void move(std::string location);
                void getPlayers();
-               std::list<std::string> shortestPath(const std::string& from, PlayerType type, const SPGoal& goal);
+               std::list<std::string> shortestPath(const std::string& from, PlayerType type, const SPGoal& goal, bool reverse = false);
 
        __gnu_cxx::hash_map<std::string, Intersection> _intersections;
        __gnu_cxx::hash_map<std::string, Player> _players;
index 0e0a265a1e26daaf0fd6da99f0d2126922a9ed88..4bc04000f79ff21efba4c7ba2d6e62eb1818fad1 100644 (file)
@@ -36,8 +36,8 @@ string Robber::turn(){
                double goodness = 0;
                Intersection& conInter = _intersections[street->first];
 
-               list<string> closestFootCop = shortestPath(street->first, cop_foot, FindPlayer(_players, cop_foot, 6));
-               list<string> closestCarCop = shortestPath(street->first, cop_car, FindPlayer(_players, cop_car, 5));
+               list<string> closestFootCop = shortestPath(street->first, cop_foot, FindPlayer(_players, cop_foot, 6), true);
+               list<string> closestCarCop = shortestPath(street->first, cop_car, FindPlayer(_players, cop_car, 5), true);
 
                unsigned int closestCop = 0;
                bool copInCar = false;