X-Git-Url: https://ruin.nu/git/?p=icfp05.git;a=blobdiff_plain;f=bot%2Fbot.cpp;h=6a486025c77ef869315e0e4f86e971e56e91bf9c;hp=8450a6321c0c462f99d4b142be4de931a27d78e5;hb=c2b823beca5d24afbac2c0489837eb7ec93bfbd3;hpb=f42b544842d9b9f21da3898225a70dec23c57a36 diff --git a/bot/bot.cpp b/bot/bot.cpp index 8450a63..6a48602 100644 --- a/bot/bot.cpp +++ b/bot/bot.cpp @@ -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; } @@ -193,6 +198,11 @@ void Bot::updateWorld(){ if (input == "ev/") break; istringstream evidence(input); + int world; + evidence >> input; + evidence >> input; + evidence >> world; + _evidence[world] = input; } getline(cin,input); @@ -234,20 +244,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 Bot::shortestPath(const std::string& from, const std::string& to, PlayerType type){ +std::list Bot::shortestPath(const std::string& from, PlayerType type, const SPGoal& goal){ + + //cerr << "New shortest path from: " << from << endl; priority_queue, SPInfoComp > pq; hash_map nodes; @@ -259,13 +264,18 @@ std::list 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(cerr, " : ")); - if (node->name == to){ + + g = goal(node); + if (g < 0) + break; + else if (g){ list l; front_insert_iterator > ii(l); do{ @@ -283,6 +293,7 @@ std::list 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];