#include "robber.h" #include "graph.h" using namespace std; int findBestMove(World &w, vector< vector > &carMap, vector< vector > &footMap, vector< vector > &robberMap); void Robber::floyds() { int N = w.car.size(); carMap.resize(N); footMap.resize(N); robberMap.resize(N); for (int i = 0; i < N; ++i) { carMap[i].resize(N); footMap[i].resize(N); robberMap[i].resize(N); } makeMatrix(w.car, carMap, w.car.size()); makeMatrix(w.foot, footMap, w.foot.size()); // Do Floyd-Warshall on them floyd(carMap, carMap.size()); floyd(footMap, footMap.size()); for (int i=0; i adjNodes = w.foot[w.robber.first]; for (int i = 0; i < adjNodes.size(); ++i) { if (adjNodes[i] == proposedMove) return true; // yeah, we can move here } return false; } int main() { initParse(); Robber r; sendRegister( "Robin_Banks", ROBBER ); recvWorld(r.w); r.floyds(); // MAIN LOOP while (recvTurn(r.w)) { int godfather; // FIXME remove all of the locals vector garbage; vector crap; vector< vector > morecrap; sendInform(garbage); recvInform(morecrap); sendPlan(garbage); recvPlan(morecrap); vector v(1, r.w.robberId); sendVote(v); godfather = recvVote(); sendBribe(false); crap = recvOfferedCops(); #ifdef DEBUG debug << "Selecting move" << endl; #endif int proposedMove = r.makeMove(); if (r.validateMove(proposedMove) == false) { // Should keep the current location sendRobberMove( r.w.robber.first, ROBBER, r.w.robberId, false, crap ); } else { sendRobberMove( proposedMove, ROBBER, r.w.robberId, false, crap ); } } return 0; } /* Really simple robber: if there's a safe path to a bank, go there. * If not, pick the bank that has highest police distance from the path * there. If all the banks are staked out, move in the direction that maximizes * distance from police. */ int Robber::makeMove() { debug << "findBestMove" << endl; int move; int numBanks = w.bankPos.size(); int curPos = w.robber.first; copsInfo cops; cops.numCops = COPS; debug << "Tracking cops" << endl; for (int i=0; i maxdist) { maxdist = thisdist; bestmove = move; } } if (maxdist > 0 && move != -1) return bestmove; // All the banks are staked out. Pick the move that leads away from // police the most debug << "Running away" << endl; maxdist = 0; for (unsigned int i=0; i maxdist) { maxdist = thisdist; bestmove = move; } } if (bestmove == -1) bestmove = curPos; return bestmove; }