]> ruin.nu Git - icfp05.git/blobdiff - bot/bot.cpp
made the shortest path algorithm more modular and tuned the robber more
[icfp05.git] / bot / bot.cpp
index 8450a6321c0c462f99d4b142be4de931a27d78e5..dd516328979baf7ea150909a1c69d0f85f20f287 100644 (file)
@@ -101,9 +101,6 @@ void Bot::play(){
        }
 }
 
-Bot::~Bot(){
-}
-
 /**
                                nod\ eol        
                                ( nod: loc node-tag coordinate coordinate eol )*        
@@ -127,7 +124,15 @@ void Bot::buildGraph(){
                node >> input;
                node >> input;
                Intersection& inter = _intersections[input];
-               node >> inter.type;
+               node >> input;
+               if (input == "bank")
+                       inter.type = bank;
+               else if (input == "hq")
+                       inter.type = hq;
+               else if (input == "robber-start")
+                       inter.type = robber_start;
+               else
+                       inter.type = ordinary;
                node >> inter.x;
                node >> inter.y;
        }
@@ -234,20 +239,15 @@ std::string Bot::turn(){
        return _location;
 }
 
-struct SPInfo{
-       string name;
-       bool settled;
-       SPInfo* parent;
-       int cost;
-};
-
 struct SPInfoComp{
        bool operator()(const SPInfo* v1, const SPInfo* v2){
                return v1->cost > v2->cost;
        }
 };
 
-std::list<std::string> Bot::shortestPath(const std::string& from, const std::string& to, PlayerType type){
+std::list<std::string> Bot::shortestPath(const std::string& from, PlayerType type, const SPGoal& goal){
+
+       //cerr << "New shortest path from: " << from << endl;
        
        priority_queue<SPInfo*, vector<SPInfo* >, SPInfoComp > pq;
        hash_map<string,SPInfo> nodes;
@@ -259,13 +259,18 @@ std::list<std::string> Bot::shortestPath(const std::string& from, const std::str
        node->cost = 0;
        pq.push(node);
 
+       int g = 0;
        while(!pq.empty()){
                node = pq.top();
                pq.pop();
                //cerr << "Vector with size: " << w.size() << endl;
-               //cerr << "Looking at: " << w.back() << endl;
+               //cerr << "Looking at: " << node->name << endl;
                //copy(w.begin(), w.end(), ostream_iterator<string>(cerr, " : "));
-               if (node->name == to){
+
+               g = goal(node);
+               if (g < 0)
+                       break;
+               else if (g){
                        list<string> l;
                        front_insert_iterator<list<string> > ii(l);
                        do{
@@ -283,6 +288,7 @@ std::list<std::string> Bot::shortestPath(const std::string& from, const std::str
                        bool hascar = type == cop_car;
                        if ( (hascar &&  (street->second == car || street->second == both)) ||
                                        (!hascar && (street->second == foot || street->second == both))){
+                               //cerr << "Adding street: " << street->first << endl;
                                SPInfo* n = 0;
                                if (newNode == nodes.end()){
                                        n = &nodes[street->first];