#include #include #include #include "parse.h" #define DEBUG using namespace std; struct Trans { map sc; vector cs; int getId(string s) { return sc[s]; } int size() { return cs.size(); } string getName(int i) { return cs[i]; } int add(string s) { cs.push_back(s); sc[s] = cs.size()-1; return sc[s]; } int operator[](string s) { return sc[s]; } string operator[](int i) { return cs[i]; } }; Trans loc; Trans bot; Trans bank; Trans ptypes; void initParse() { ptypes.add("cop-foot"); ptypes.add("cop-car"); ptypes.add("robber"); } #ifdef DUMP_TO_FILE ofstream debug; #endif void sendRegister( string bot, ptype type ) { cout << "reg: " << bot << " " << ptypes[type] << endl; } void recvWorld( World& world ) { string s, robName, botName, myName, locName, destName, tag, type; int c,r; cin >> s; // wsk-start cin >> s >> myName; #ifdef DUMP_TO_FILE debug = ofstream( (myName+".out").c_str(), ofstream::out ); #endif cin >> s >> robName; for (int i=0; i> s >> botName; bot.add(botName); world.cops.push_back( pair(0,COP_FOOT) ); } world.dcInfo.resize(COPS); world.robberId = bot.add(robName); world.me = bot[myName]; cin >> s; // nod-start cin >> s; world.maxCoord = 0; while (s == "nod:") { cin >> locName >> tag >> c >> r; loc.add( locName ); if (c > world.maxCoord) world.maxCoord = c; if (r > world.maxCoord) world.maxCoord = r; world.coords.push_back( pair(c,r) ); world.car.push_back( vector(0,0) ); world.foot.push_back( vector(0,0) ); if (tag == "bank") { bank.add( locName ); world.bankMoney.push_back(0); world.bankPos.push_back(loc.getId(locName)); } else if (tag == "hq") { world.hq = loc.getId(locName); } else if (tag == "robber-start") { world.robberStartPos = loc.getId(locName); } cin >> s; } // nod-end world.mCar = vector< vector >( world.car.size(), vector( world.car.size(), false ) ); world.mFoot = vector< vector >( world.car.size(), vector( world.car.size(), false ) ); cin >> s; // edg-start cin >> s; while (s == "edg:") { cin >> locName >> destName >> type; if ( type == "car" ) { world.car[loc.getId(locName)].push_back(loc.getId(destName)); world.mCar[loc[locName]][loc[destName]] = true; } else { world.car[loc.getId(locName)].push_back(loc.getId(destName)); world.mCar[loc[locName]][loc[destName]] = true; if ( !world.mFoot[loc[locName]][loc[destName]] ) { world.foot[loc.getId(locName)].push_back(loc.getId(destName)); world.foot[loc.getId(destName)].push_back(loc.getId(locName)); } world.mFoot[loc[locName]][loc[destName]] = true; world.mFoot[loc[destName]][loc[locName]] = true; } cin >> s; } // edg-end cin >> s; // wsk-end } bool recvTurn( World& world ) { #ifdef DEBUG debug << __FUNCTION__ << endl; #endif string s, locName, botName, type; int val; cin >> s; // wor-start or game-over #ifdef DEBUG debug << "Receiving " << s << endl; #endif if (s != "wor\\" || s == "accused:") // game also ends if we're accused and dirty return false; cin >> s >> world.n; // wor: n cin >> s >> world.loot; // rbd: n cin >> s; // dc-start cin >> s; while (s == "dc:") { cin >> s; world.dcInfo[bot[s]] = CERTAIN; cin >> s; } // dc-end cin >> s; // sc-start cin >> s; world.borgInfo.clear(); world.borgInfo.resize(COPS); for (int i=0; i> controllingBot >> controlledBot; owner = bot.getId(controllingBot); owned = bot.getId(controlledBot); world.borgInfo[owner].insert(owned); world.borgInfo[owned].clear(); if (owner == world.me) // score! world.myBorg.insert(owned); if (owned == world.me) // oh shit world.myBorg.clear(); cin >> s; } // sc-end /* We should do something with this, probably... */ cin >> s; // fac-start cin >> s; while (s == "fac:") { string accuser, accusee; int wID; cin >> accuser >> accusee >> wID; cin >> s; } // fac-end cin >> s; // bv-start cin >> s; while (s == "bv:") { cin >> locName >> val; world.bankMoney[bank.getId(locName)] = val; cin >> s; } // bv-end cin >> s; // ev-start cin >> s; while (s == "ev:") { cin >> locName >> val; world.evidence.push_back( pair( loc.getId(locName), val ) ); cin >> s; } // ev-end cin >> s >> world.smell; cin >> s; // pl-start cin >> s; world.robberPosKnown = false; world.robberCertain = 0; while (s == "pl:") { cin >> botName >> locName >> type; int botId = bot.getId(botName); if (type == "robber") // it is the robber { world.robberPosKnown = true; world.robberCertain = world.n; world.robber.first = loc.getId(locName); world.robber.second = ROBBER; } else { world.cops[botId].first = loc.getId(locName); world.cops[botId].second = (type == "cop-foot") ? COP_FOOT : COP_CAR; world.moveHist.push_back(world.cops); } cin >> s; } // pl-end cin >> s; // wor-end #ifdef DEBUG debug << "Received world state" << endl; #endif return true; } void sendRobberMove( int where, ptype type, int whoami, bool bribedLastTurn, vector& copsForBribe ) { cout << "rmov\\" << endl; /*** move ***/ #ifdef DEBUG debug << "mov: " << loc[where] << " " << ptypes[type] << " " << bot[whoami] << endl; #endif cout << "mov: " << loc[where] << " " << ptypes[type] << " " << bot[whoami] << endl; /*** bribe-result ***/ if (!bribedLastTurn) { cout << "nobribe:" << endl; } else { // FIXME: push or choose decision needs to be made here bool pushing = false; // makeDecision(); if (pushing) { int botToPush, location; cout << "psh: " << botToPush << " " << location << endl; } else { // pick from copsForBribe, right now, I just output all of them // -- this is not a bug, this is a feature we'll keep it cout << "chc\\" << endl; for (unsigned int i = 0; i < copsForBribe.size(); ++i) { cout << "chc: " << bot[copsForBribe[i]] << endl; } cout << "chc/" << endl; } } cout << "rmov/" << endl; } void sendCleanCopMove( vector& moveList, vector &accuse) { cout << "cmov\\" << endl; /*** offer ***/ // Here, make a decision on whether we wanna be back-stabbers or not bool willBackstab = false; // backstab decision here please if (willBackstab) { cout << "turncoat:" << endl; } else { cout << "straight-arrow:" << endl; } /*** move-msg ***/ cout << "mov\\" << endl; // Move the borg for (unsigned int i = 0; i < moveList.size(); ++i) { // Cop brain should process all the moves and give us a list cout << "mov: " << loc[moveList[i].locId] << " " << ptypes[moveList[i].type] << " " << bot[moveList[i].botId] << endl; } cout << "mov/" << endl; /*** acc[usations] ***/ cout << "acc\\" << endl; for (unsigned int i = 0; i < accuse.size(); ++i) { cout << "acc: " << bot[accuse[i]] << endl; } cout << "acc/" << endl; cout << "cmov/" << endl; } void sendDirtyCopMove( vector& moveList) { /*** move-msg ***/ cout << "mov\\" << endl; // Move the borg for (unsigned int i = 0; i < moveList.size(); ++i) { // Cop brain should process all the moves and give us a list cout << "mov: " << loc[moveList[i].locId] << " " << ptypes[moveList[i].type] << " " << bot[moveList[i].botId] << endl; } cout << "mov/" << endl; } void sendBribe(bool amBribing) // must pass in whether we chose to bribe or not { amBribing ? cout << "bribe:" << endl : cout << "nobribe:" << endl; } vector recvOfferedCops() { vector copsForBribe; string s; int botID; cin >> s; // nottelling: or ofc-start if (s == "nottelling:") return copsForBribe; // none, sucka cin >> s; while (s == "ofc:") { cin >> botID; copsForBribe.push_back(botID); cin >> s; } cin >> s; // ofc-end return copsForBribe; } void sendInform( const vector& info ) { cout << "inf\\" << endl; for (unsigned int i=0; i >& info ) { string s, botName, locName, type; int val, cert; cin >> s; // from-start from\ from: botName inf\ inf: inf/ from: cin >> s; while (s == "from:") { cin >> botName; int botId = bot[botName]; vector g; cin >> s; // inf-start cin >> s; while (s == "inf:") { cin >> botName >> locName >> type >> val >> cert; g.push_back( guess( bot[botName], loc[locName], (ptype)ptypes[type], val, cert ) ); cin >> s; } // inf-end if ( botId >= 0 && (unsigned int)botId < info.size() ) info[botId] = g; cin >> s; } // from-end } void sendPlan( vector& info ) { cout << "plan\\" << endl; for (unsigned int i=0; i >& plan ) { string s, botName, locName, type; int val; cin >> s; // from-start cin >> s; while (s == "from:") { cin >> botName; int botId = bot.getId(botName); vector g; cin >> s; // plan-start cin >> s; while (s == "plan:") { cin >> botName >> locName >> type >> val; g.push_back( guess( bot.getId(botName), loc.getId(locName), (ptype)ptypes[type], val ) ); cin >> s; } // plan-end if ( botId >= 0 && (unsigned int)botId < plan.size() ) plan[botId] = g; cin >> s; } // from-end } void sendVote( vector& votes ) { cout << "vote\\" << endl; for (unsigned int i=0; i> s; if (s == "nowinner:") return -1; cin >> s; return bot[s]; } string getLocName(int locID) { return loc.getName(locID); } int getLocID(string locName) { return loc.getId(locName); } set World::smellyNodes(vector > pureFootMap) { set adj; for (set::iterator I = myBorg.begin(); I != myBorg.end(); I++) { if ( cops[*I].second == COP_CAR ) { for (unsigned int i=0; i