#include #include #include #include "parse.h" using namespace std; #undef DEBUG #ifdef DEBUG void printMap( string mapName, vector< vector > &map, int N ) { debug << "Map: " << mapName << endl; for (int i=0; i > &listmap, vector< vector > &map, int N) { // Initialize the maps to MAXDISTANCE everywhere for (int i=0; i > &map, int N) { for (int k=0; k map[i][k].dist + map[k][j].dist) { map[i][j].dist = map[i][k].dist + map[k][j].dist; map[i][j].numPaths = map[i][k].numPaths; for (int l=0; l > &carMap, vector< vector > &footMap, int N, int hq) { for (int i=0; i carMap[i][hq].dist + footMap[hq][j].dist) { carMap[i][j].dist = carMap[i][hq].dist + footMap[hq][j].dist; carMap[i][j].numPaths = carMap[i][hq].numPaths; for (int l=0; l footMap[i][hq].dist + carMap[hq][j].dist) { footMap[i][j].dist = footMap[i][hq].dist + carMap[hq][j].dist; footMap[i][j].numPaths = footMap[i][hq].numPaths; for (int l=0; l > &robberMap, vector< vector > &carMap, vector< vector > &footMap, int curPos, int dest, copsInfo cops, int &firstNode, int depth = 0) { #ifdef DEBUG debug << __FUNCTION__ << ": branching factor=" << robberMap[curPos][dest].numPaths << endl; #endif int garbage; for (int i=0; i > &robberMap, vector< vector > &carMap, vector< vector > &footMap, int curPos, int dest, copsInfo cops, int &firstNode) { int garbage; int minDistFromHere = MAXDISTANCE; for (int i=0; i maxmin); { maxmin = temp; firstNode = robberMap[curPos][dest].initPath[i]; } } return (minDistFromHere < maxmin ? minDistFromHere : maxmin); } /* The cop tries to intercept the robber on his way from one place to another. * Returns the move to make such that the cop ends up on the same node as * the robber assuming that the robber takes the shortest path. */ int interceptRobber(vector< vector > &robberMap, vector< vector > &copMap, int copPos, int robberPos, int target) { for (int pos=robberPos; pos!=target; pos=robberMap[pos][target].initPath[0]) { if (robberMap[robberPos][pos].dist >= copMap[copPos][pos].dist) return copMap[copPos][pos].initPath[0]; } // shouldn't get here??? -keir assert(0); return 0; } /* Look for a path from orig to dest with a set of disallowed nodes. */ int findClearPath(int orig, vector& targets, World &w, vector > &map, vector& badNodes, vector &moveSeq, int numTries) { if (targets[orig]) return 0; vector dontGoThere = badNodes; dontGoThere[orig] = true; queue nodeQ, lengthQ; queue > routeQ; for (unsigned int i=0; i()); routeQ.back().push_back(map[orig][i]); lengthQ.push(1); dontGoThere[map[orig][i]] = true; } while (!nodeQ.empty()) { int curNode = nodeQ.front(); if (targets[curNode]) { numTries--; if (numTries <= 0) { moveSeq = routeQ.front(); return lengthQ.front(); } } for (unsigned int i=0; i newRoute = routeQ.front(); newRoute.push_back(map[curNode][i]); routeQ.push(newRoute); lengthQ.push(lengthQ.front()+1); dontGoThere[map[curNode][i]] = true; } nodeQ.pop(); lengthQ.pop(); routeQ.pop(); } // Can't get through! return -1; } /* Marks nodes around a certain node w/ a certain range as bad */ void markNodes(int center, vector& nodeMarks, vector > &map, int range) { // cerr << "markNodes, center=" << center << " range=" << range << endl; if (range == 0) { nodeMarks[center] = true; return; } for (unsigned int i=0; i intersectNodes(set &set1, set &set2) { set retval; set::iterator I2; for (set::iterator I=set1.begin(); I != set1.end(); ++I) { I2 = set2.find(*I); if (I2 != set2.end()) retval.insert(*I); } return retval; } void markNodesSet(int center, set &nodeMarks, vector > &map, int range) { if (range == 0) { nodeMarks.insert(center); return; } for (unsigned int i=0; i& targets, World &w, vector > &map) { if (targets.find(orig) != targets.end()) return true; for (unsigned int i=0; i