From d3bca66246f3489aa03d5e0fa7d10ca62511c11d Mon Sep 17 00:00:00 2001 From: Michael Andreen Date: Tue, 28 Jun 2005 15:44:21 +0000 Subject: [PATCH] shortest path optimized --- botsrc/bot.cpp | 27 +++++++++++++++------------ robbersrc/robbersrc.pro | 2 +- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/botsrc/bot.cpp b/botsrc/bot.cpp index 7635f13..e9950a6 100644 --- a/botsrc/bot.cpp +++ b/botsrc/bot.cpp @@ -248,12 +248,11 @@ std::list Bot::shortestPath(const std::string& from, PlayerType typ int g = 0; bool hascar = type == cop_car; + ; + SPInfo* n = 0; while(!pq.empty()){ node = pq.top(); pq.pop(); - //cerr << "Vector with size: " << w.size() << endl; - //cerr << "Looking at: " << node->name << endl; - //copy(w.begin(), w.end(), ostream_iterator(cerr, " : ")); g = goal(node); if (g < 0) @@ -269,19 +268,24 @@ std::list Bot::shortestPath(const std::string& from, PlayerType typ } node->settled = true; - Intersection& inter = _intersections[node->name]; - for (hash_map::const_iterator street = inter.connections.begin(); - street != inter.connections.end(); ++street){ + hash_map::const_iterator intersection = _intersections.find(node->name); + if (intersection == _intersections.end()){ //Sanity check, should never be true.. + cerr << "BUG: Could not find intersection: " << node->name << endl; + continue; + } + for (hash_map::const_iterator street = intersection->second.connections.begin(); + street != intersection->second.connections.end(); ++street){ hash_map::iterator newNode = nodes.find(street->first); bool travelStreet = false; if (hascar){ if (reverse){ if (street->second != foot){ - hash_map::const_iterator st = _intersections[street->first].connections.find(node->name); - if (st != _intersections[street->first].connections.end()) - travelStreet = st->second != foot; - else - travelStreet = false; + hash_map::const_iterator newInter = _intersections.find(street->first); + if (newInter != _intersections.end()){ + hash_map::const_iterator st = newInter->second.connections.find(node->name); + if (st != newInter->second.connections.end()) + travelStreet = st->second != foot; + } }else travelStreet = true; }else @@ -291,7 +295,6 @@ std::list Bot::shortestPath(const std::string& from, PlayerType typ } if (travelStreet){ //cerr << "Adding street: " << street->first << endl; - SPInfo* n = 0; if (newNode == nodes.end()){ n = &nodes[street->first]; n->name = street->first; diff --git a/robbersrc/robbersrc.pro b/robbersrc/robbersrc.pro index 525f42b..1e0d738 100644 --- a/robbersrc/robbersrc.pro +++ b/robbersrc/robbersrc.pro @@ -8,7 +8,7 @@ CONFIG -= qt #CONFIG += debug unix:LIBS += -lm TARGET = ../robber -QMAKE_CFLAGS_RELEASE += -march=athlon-xp +#QMAKE_CXXFLAGS_RELEASE += -march=athlon-xp -g # Input -- 2.39.2