From: Michael Andreen Date: Sun, 26 Jun 2005 23:15:38 +0000 (+0000) Subject: renamed dirs X-Git-Url: https://ruin.nu/git/?p=icfp05.git;a=commitdiff_plain;h=e80a1fceda25988c576631be47a9b122126d8f53 renamed dirs --- diff --git a/bot/bot.cpp b/bot/bot.cpp deleted file mode 100644 index 28e8004..0000000 --- a/bot/bot.cpp +++ /dev/null @@ -1,330 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include "bot.h" - -using namespace std; -using namespace __gnu_cxx; - - -Bot::Bot(const string& name, PlayerType type){ - _name = name; - _type = type; - - _playerTypeNames[robber] = "robber"; - _playerTypeNames[cop_foot] = "cop-foot"; - _playerTypeNames[cop_car] = "cop-car"; - - _playerTypes["robber"] = robber; - _playerTypes["cop-foot"] = cop_foot; - _playerTypes["cop-car"] = cop_car; - -} - -void Bot::play(){ - cout << "reg: " << _name << " " << _playerTypeNames[_type] << endl; - - string input; - getline(cin, input); - if (input != "wsk\\") - return; - getline(cin, input); - _name = value(input); - cerr << "Got name: " << _name << endl; - - getPlayers(); - - cerr << "Got players, building graph." << endl; - getline(cin, input); - buildGraph(); - - while (true){ - getline(cin, input); - if (input == "game-over") - return; - updateWorld(); - _type = _players[_name].type; - _location = _players[_name].location; - cerr << "New turn" << endl; - move(turn()); - cerr << "Done with turn." << endl; - } -} - -void Bot::getPlayers(){ - string input; - //robber and 5 cops - getline(cin, input); - _players[value(input)].type = robber; - getline(cin, input); - _players[value(input)].type = cop_foot; - getline(cin, input); - _players[value(input)].type = cop_foot; - getline(cin, input); - _players[value(input)].type = cop_foot; - getline(cin, input); - _players[value(input)].type = cop_foot; -} - -/** - nod\ eol - ( nod: loc node-tag coordinate coordinate eol )* - nod/ eol - edg\ eol - ( edg: loc loc edge-type eol )* - edg/ eol -*/ -void Bot::buildGraph(){ - string input; - getline(cin, input); - if (input != "nod\\") - return; - - cerr << "Getting intersections" << endl; - while (true){ - getline(cin, input); - if (input == "nod/") - break; - istringstream node(input); - node >> input; - node >> input; - Intersection& inter = _intersections[input]; - 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; - } - - cerr << "Number of intersections: " << _intersections.size() << endl; - - getline(cin, input); - if (input != "edg\\") - return; - - cerr << "Getting streets" << endl; - int streets = 0; - while (true){ - getline(cin, input); - if (input == "edg/") - break; - ++streets; - istringstream street(input); - string from; - street >> from; - street >> from; - string to; - street >> to; - string type; - street >> type; - //cerr << "Street between: " << from << " and " << to << " of type: " << type << endl; - if (type == "foot"){ - _intersections[from].connections[to] = both; - Intersection& inter = _intersections[to]; - if (inter.connections.find(from) == inter.connections.end()) - inter.connections[from] = foot; - }else - _intersections[from].connections[to] = car; - } - cerr << "Number of streets: " << streets << endl; - getline(cin, input); -} - -void Bot::updateWorld(){ - string input; - getline(cin,input); - _world = value(input); - //cerr << "World: " << _world << endl; - - getline(cin,input); - _robbed = value(input); - //cerr << "Robbed: " << _robbed << endl; - - getline(cin,input); - while (true){ - getline(cin, input); - if (input == "bv/") - break; - istringstream bank(input); - bank >> input; - bank >> input; - bank >> _banks[input]; - } - //cerr << "Number of banks: " << _banks.size() << endl; - - getline(cin,input); - while (true){ - getline(cin, input); - if (input == "ev/") - break; - istringstream evidence(input); - int world; - evidence >> input; - evidence >> input; - evidence >> world; - _evidence[world] = input; - } - - getline(cin,input); - _smell = value(input); - - getline(cin,input); - while (true){ - getline(cin, input); - if (input == "pl/") - break; - istringstream player(input); - player >> input; - player >> input; - //cerr << "Player: " << input << endl; - Player& pl = _players[input]; - player >> pl.location; - player >> input; - pl.type = _playerTypes[input]; - } - //cerr << "Number of players: " << _players.size() << endl; - getline(cin, input); -} - -void Bot::move(std::string location){ - cerr << "Moving to: " << location << endl; - cout << "mov: " << location << " " << _playerTypeNames[_type] << endl; -} - -template -T value(std::string input){ - istringstream istr(input); - istr >> input; - T s; - istr >> s; - return s; -} - -std::string Bot::turn(){ - cerr << "Using stupid stand still Bot::turn" << endl; - return _location; -} - -struct SPInfoComp{ - bool operator()(const SPInfo* v1, const SPInfo* v2){ - return v1->cost > v2->cost; - } -}; - -std::list Bot::shortestPath(const std::string& from, PlayerType type, const SPGoal& goal, bool reverse){ - - //cerr << "New shortest path from: " << from << endl; - - priority_queue, SPInfoComp > pq; - hash_map nodes; - - SPInfo* node = &nodes[from]; - node->name = from; - node->settled = false; - node->parent = 0; - node->cost = 0; - pq.push(node); - - int g = 0; - bool hascar = type == cop_car; - 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) - break; - else if (g){ - list l; - front_insert_iterator > ii(l); - do{ - *ii++ = node->name; - node = node->parent; - }while (node != 0); - return l; - } - node->settled = true; - - Intersection& inter = _intersections[node->name]; - for (hash_map::const_iterator street = inter.connections.begin(); - street != inter.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; - }else - travelStreet = true; - }else - travelStreet = street->second != foot; - }else{ - travelStreet = street->second != car; - } - if (travelStreet){ - //cerr << "Adding street: " << street->first << endl; - SPInfo* n = 0; - if (newNode == nodes.end()){ - n = &nodes[street->first]; - n->name = street->first; - n->settled = false; - n->parent = 0; - n->cost = 10000; - }else if (newNode->second.settled) - continue; - else - n = &newNode->second; - - if (n->cost > node->cost + 1){ - n->cost = node->cost + 1; - n->parent = node; - pq.push(n); - } - } - - } - - } - - return list(); -} - -SimpleSPGoal::SimpleSPGoal(std::string to):_to(to){ -} - -int SimpleSPGoal::operator()(const SPInfo* node) const{ - if (node->name == _to) - return 1; - return 0; -} - -FindPlayer::FindPlayer(const hash_map& players, PlayerType type, int limit) : _players(players), _type(type), _limit(limit){ -} - -int FindPlayer::operator()(const SPInfo* node) const{ - if (_limit > 0 && node->cost >= _limit) - return -1; - for(hash_map::const_iterator player = _players.begin(); - player != _players.end(); ++player){ - if (player->second.type == _type && player->second.location == node->name){ - return 1; - } - } - return 0; -} diff --git a/bot/bot.h b/bot/bot.h deleted file mode 100644 index 731a106..0000000 --- a/bot/bot.h +++ /dev/null @@ -1,116 +0,0 @@ -#ifndef __BOT_H__ -#define __BOT_H__ - -#include -#include -#include -#include -#include -// These are needed to be able to use std::string as key in a hash_map. -namespace __gnu_cxx { - template< typename CharT, typename Traits, typename Alloc > - struct hash< std::basic_string > { - size_t operator()(const std::basic_string& s) const { - - const std::collate& c = std::use_facet< std::collate >(std::locale()); - - return c.hash(s.c_str(), s.c_str() + s.size()); - - } - - }; - - template< typename CharT, typename Traits, typename Alloc > - struct hash< const std::basic_string > { //yes you need this version aswell! - - size_t operator()(const std::basic_string& s) const { - - const std::collate& c = std::use_facet< std::collate >(std::locale()); - - return c.hash(s.c_str(), s.c_str() + s.size()); - } - - }; -}; - -enum StreetType{foot, car, both}; -enum PlayerType{robber, cop_foot, cop_car}; -enum IntersectionType{hq, bank, robber_start, ordinary}; - -struct Intersection{ - __gnu_cxx::hash_map connections; - IntersectionType type; - int x; - int y; -}; - -struct Player{ - PlayerType type; - std::string location; -}; - -struct Bank{ - std::string location; - int value; -}; - -template -T value(std::string input); - -struct SPInfo{ - std::string name; - bool settled; - SPInfo* parent; - int cost; -}; - - -struct SPGoal{ - virtual ~SPGoal(){} - virtual int operator()(const SPInfo* node) const = 0; -}; - -class Bot { - public: - Bot(const std::string& name, PlayerType type); - virtual ~Bot(){}; - - virtual void play(); - - protected: - void buildGraph(); - void updateWorld(); - virtual std::string turn() = 0; - void move(std::string location); - void getPlayers(); - std::list shortestPath(const std::string& from, PlayerType type, const SPGoal& goal, bool reverse = false); - - __gnu_cxx::hash_map _intersections; - __gnu_cxx::hash_map _players; - __gnu_cxx::hash_map _banks; - std::map _evidence; - std::map _playerTypeNames; - std::map _playerTypes; - std::string _name; - PlayerType _type; - std::string _location; - int _world; - int _robbed; - int _smell; -}; - -struct SimpleSPGoal : public SPGoal{ - std::string _to; - SimpleSPGoal(std::string to); - int operator()(const SPInfo* node) const; -}; - -struct FindPlayer : SPGoal{ - int _limit; - const __gnu_cxx::hash_map& _players; - PlayerType _type; - FindPlayer(const __gnu_cxx::hash_map& players, PlayerType type, int limit = 0); - int operator()(const SPInfo* node) const; -}; - -#endif diff --git a/botsrc/bot.cpp b/botsrc/bot.cpp new file mode 100644 index 0000000..28e8004 --- /dev/null +++ b/botsrc/bot.cpp @@ -0,0 +1,330 @@ +#include +#include +#include +#include +#include +#include +#include "bot.h" + +using namespace std; +using namespace __gnu_cxx; + + +Bot::Bot(const string& name, PlayerType type){ + _name = name; + _type = type; + + _playerTypeNames[robber] = "robber"; + _playerTypeNames[cop_foot] = "cop-foot"; + _playerTypeNames[cop_car] = "cop-car"; + + _playerTypes["robber"] = robber; + _playerTypes["cop-foot"] = cop_foot; + _playerTypes["cop-car"] = cop_car; + +} + +void Bot::play(){ + cout << "reg: " << _name << " " << _playerTypeNames[_type] << endl; + + string input; + getline(cin, input); + if (input != "wsk\\") + return; + getline(cin, input); + _name = value(input); + cerr << "Got name: " << _name << endl; + + getPlayers(); + + cerr << "Got players, building graph." << endl; + getline(cin, input); + buildGraph(); + + while (true){ + getline(cin, input); + if (input == "game-over") + return; + updateWorld(); + _type = _players[_name].type; + _location = _players[_name].location; + cerr << "New turn" << endl; + move(turn()); + cerr << "Done with turn." << endl; + } +} + +void Bot::getPlayers(){ + string input; + //robber and 5 cops + getline(cin, input); + _players[value(input)].type = robber; + getline(cin, input); + _players[value(input)].type = cop_foot; + getline(cin, input); + _players[value(input)].type = cop_foot; + getline(cin, input); + _players[value(input)].type = cop_foot; + getline(cin, input); + _players[value(input)].type = cop_foot; +} + +/** + nod\ eol + ( nod: loc node-tag coordinate coordinate eol )* + nod/ eol + edg\ eol + ( edg: loc loc edge-type eol )* + edg/ eol +*/ +void Bot::buildGraph(){ + string input; + getline(cin, input); + if (input != "nod\\") + return; + + cerr << "Getting intersections" << endl; + while (true){ + getline(cin, input); + if (input == "nod/") + break; + istringstream node(input); + node >> input; + node >> input; + Intersection& inter = _intersections[input]; + 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; + } + + cerr << "Number of intersections: " << _intersections.size() << endl; + + getline(cin, input); + if (input != "edg\\") + return; + + cerr << "Getting streets" << endl; + int streets = 0; + while (true){ + getline(cin, input); + if (input == "edg/") + break; + ++streets; + istringstream street(input); + string from; + street >> from; + street >> from; + string to; + street >> to; + string type; + street >> type; + //cerr << "Street between: " << from << " and " << to << " of type: " << type << endl; + if (type == "foot"){ + _intersections[from].connections[to] = both; + Intersection& inter = _intersections[to]; + if (inter.connections.find(from) == inter.connections.end()) + inter.connections[from] = foot; + }else + _intersections[from].connections[to] = car; + } + cerr << "Number of streets: " << streets << endl; + getline(cin, input); +} + +void Bot::updateWorld(){ + string input; + getline(cin,input); + _world = value(input); + //cerr << "World: " << _world << endl; + + getline(cin,input); + _robbed = value(input); + //cerr << "Robbed: " << _robbed << endl; + + getline(cin,input); + while (true){ + getline(cin, input); + if (input == "bv/") + break; + istringstream bank(input); + bank >> input; + bank >> input; + bank >> _banks[input]; + } + //cerr << "Number of banks: " << _banks.size() << endl; + + getline(cin,input); + while (true){ + getline(cin, input); + if (input == "ev/") + break; + istringstream evidence(input); + int world; + evidence >> input; + evidence >> input; + evidence >> world; + _evidence[world] = input; + } + + getline(cin,input); + _smell = value(input); + + getline(cin,input); + while (true){ + getline(cin, input); + if (input == "pl/") + break; + istringstream player(input); + player >> input; + player >> input; + //cerr << "Player: " << input << endl; + Player& pl = _players[input]; + player >> pl.location; + player >> input; + pl.type = _playerTypes[input]; + } + //cerr << "Number of players: " << _players.size() << endl; + getline(cin, input); +} + +void Bot::move(std::string location){ + cerr << "Moving to: " << location << endl; + cout << "mov: " << location << " " << _playerTypeNames[_type] << endl; +} + +template +T value(std::string input){ + istringstream istr(input); + istr >> input; + T s; + istr >> s; + return s; +} + +std::string Bot::turn(){ + cerr << "Using stupid stand still Bot::turn" << endl; + return _location; +} + +struct SPInfoComp{ + bool operator()(const SPInfo* v1, const SPInfo* v2){ + return v1->cost > v2->cost; + } +}; + +std::list Bot::shortestPath(const std::string& from, PlayerType type, const SPGoal& goal, bool reverse){ + + //cerr << "New shortest path from: " << from << endl; + + priority_queue, SPInfoComp > pq; + hash_map nodes; + + SPInfo* node = &nodes[from]; + node->name = from; + node->settled = false; + node->parent = 0; + node->cost = 0; + pq.push(node); + + int g = 0; + bool hascar = type == cop_car; + 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) + break; + else if (g){ + list l; + front_insert_iterator > ii(l); + do{ + *ii++ = node->name; + node = node->parent; + }while (node != 0); + return l; + } + node->settled = true; + + Intersection& inter = _intersections[node->name]; + for (hash_map::const_iterator street = inter.connections.begin(); + street != inter.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; + }else + travelStreet = true; + }else + travelStreet = street->second != foot; + }else{ + travelStreet = street->second != car; + } + if (travelStreet){ + //cerr << "Adding street: " << street->first << endl; + SPInfo* n = 0; + if (newNode == nodes.end()){ + n = &nodes[street->first]; + n->name = street->first; + n->settled = false; + n->parent = 0; + n->cost = 10000; + }else if (newNode->second.settled) + continue; + else + n = &newNode->second; + + if (n->cost > node->cost + 1){ + n->cost = node->cost + 1; + n->parent = node; + pq.push(n); + } + } + + } + + } + + return list(); +} + +SimpleSPGoal::SimpleSPGoal(std::string to):_to(to){ +} + +int SimpleSPGoal::operator()(const SPInfo* node) const{ + if (node->name == _to) + return 1; + return 0; +} + +FindPlayer::FindPlayer(const hash_map& players, PlayerType type, int limit) : _players(players), _type(type), _limit(limit){ +} + +int FindPlayer::operator()(const SPInfo* node) const{ + if (_limit > 0 && node->cost >= _limit) + return -1; + for(hash_map::const_iterator player = _players.begin(); + player != _players.end(); ++player){ + if (player->second.type == _type && player->second.location == node->name){ + return 1; + } + } + return 0; +} diff --git a/botsrc/bot.h b/botsrc/bot.h new file mode 100644 index 0000000..731a106 --- /dev/null +++ b/botsrc/bot.h @@ -0,0 +1,116 @@ +#ifndef __BOT_H__ +#define __BOT_H__ + +#include +#include +#include +#include +#include +// These are needed to be able to use std::string as key in a hash_map. +namespace __gnu_cxx { + template< typename CharT, typename Traits, typename Alloc > + struct hash< std::basic_string > { + size_t operator()(const std::basic_string& s) const { + + const std::collate& c = std::use_facet< std::collate >(std::locale()); + + return c.hash(s.c_str(), s.c_str() + s.size()); + + } + + }; + + template< typename CharT, typename Traits, typename Alloc > + struct hash< const std::basic_string > { //yes you need this version aswell! + + size_t operator()(const std::basic_string& s) const { + + const std::collate& c = std::use_facet< std::collate >(std::locale()); + + return c.hash(s.c_str(), s.c_str() + s.size()); + } + + }; +}; + +enum StreetType{foot, car, both}; +enum PlayerType{robber, cop_foot, cop_car}; +enum IntersectionType{hq, bank, robber_start, ordinary}; + +struct Intersection{ + __gnu_cxx::hash_map connections; + IntersectionType type; + int x; + int y; +}; + +struct Player{ + PlayerType type; + std::string location; +}; + +struct Bank{ + std::string location; + int value; +}; + +template +T value(std::string input); + +struct SPInfo{ + std::string name; + bool settled; + SPInfo* parent; + int cost; +}; + + +struct SPGoal{ + virtual ~SPGoal(){} + virtual int operator()(const SPInfo* node) const = 0; +}; + +class Bot { + public: + Bot(const std::string& name, PlayerType type); + virtual ~Bot(){}; + + virtual void play(); + + protected: + void buildGraph(); + void updateWorld(); + virtual std::string turn() = 0; + void move(std::string location); + void getPlayers(); + std::list shortestPath(const std::string& from, PlayerType type, const SPGoal& goal, bool reverse = false); + + __gnu_cxx::hash_map _intersections; + __gnu_cxx::hash_map _players; + __gnu_cxx::hash_map _banks; + std::map _evidence; + std::map _playerTypeNames; + std::map _playerTypes; + std::string _name; + PlayerType _type; + std::string _location; + int _world; + int _robbed; + int _smell; +}; + +struct SimpleSPGoal : public SPGoal{ + std::string _to; + SimpleSPGoal(std::string to); + int operator()(const SPInfo* node) const; +}; + +struct FindPlayer : SPGoal{ + int _limit; + const __gnu_cxx::hash_map& _players; + PlayerType _type; + FindPlayer(const __gnu_cxx::hash_map& players, PlayerType type, int limit = 0); + int operator()(const SPInfo* node) const; +}; + +#endif diff --git a/cop/cop.cpp b/cop/cop.cpp deleted file mode 100644 index f5a7f3f..0000000 --- a/cop/cop.cpp +++ /dev/null @@ -1,75 +0,0 @@ -#include "cop.h" -#include -#include -#include - -using namespace std; -using namespace __gnu_cxx; - -string Cop::turn(){ - string input; - - sendInformation(); - getInformation(); - - sendPlan(); - getPlans(); - - vote(); - - //Ignore vote - getline(cin,input); - - return _location; -} - -void Cop::sendInformation(){ - cout << "inf\\" << endl; - cout << "inf/" << endl; -} - -void Cop::getInformation(){ - string input; - - //ignore From-inform - do{ - getline(cin,input); - }while(input != "from/"); -} - -void Cop::sendPlan(){ - cout << "plan\\" << endl; - //cout << "plan: " << _name << endl; - cout << "plan/" << endl; -} - -void Cop::getPlans(){ - string input; - - //ignore From-plan - do{ - getline(cin,input); - }while(input != "from/"); - - -} - -void Cop::vote(){ - cout << "vote\\" << endl; - cout << "vote: " << _name << endl; - for (hash_map::const_iterator player = _players.begin(); - player != _players.end(); ++player){ - if (player->second.type != robber && player->first != _name){ - cout << "vote: " << player->first << endl; - cerr << "voted for " << player->first << " of type: " << player->second.type << endl; - } - } - cout << "vote/" << endl; -} - -int main(){ - Cop cop("cop"); - cop.play(); - - return 0; -} diff --git a/cop/cop.h b/cop/cop.h deleted file mode 100644 index 42cb778..0000000 --- a/cop/cop.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef __COP_H__ -#define __COP_H__ - -#include - -class Cop : public Bot { - public: - Cop(std::string name):Bot(name,cop_foot){}; - - std::string turn(); - protected: - void sendInformation(); - void getInformation(); - void sendPlan(); - void getPlans(); - void vote(); -}; -#endif diff --git a/cop/cop.pro b/cop/cop.pro deleted file mode 100644 index 28849d8..0000000 --- a/cop/cop.pro +++ /dev/null @@ -1,14 +0,0 @@ -###################################################################### -# Automatically generated by qmake (1.07a) Fri Jun 24 23:15:16 2005 -###################################################################### - -TEMPLATE = app -INCLUDEPATH += ../bot -CONFIG -= qt -CONFIG += debug -unix:LIBS += -lm - - -# Input -HEADERS += cop.h -SOURCES += cop.cpp ../bot/bot.cpp diff --git a/copsrc/cop.cpp b/copsrc/cop.cpp new file mode 100644 index 0000000..f5a7f3f --- /dev/null +++ b/copsrc/cop.cpp @@ -0,0 +1,75 @@ +#include "cop.h" +#include +#include +#include + +using namespace std; +using namespace __gnu_cxx; + +string Cop::turn(){ + string input; + + sendInformation(); + getInformation(); + + sendPlan(); + getPlans(); + + vote(); + + //Ignore vote + getline(cin,input); + + return _location; +} + +void Cop::sendInformation(){ + cout << "inf\\" << endl; + cout << "inf/" << endl; +} + +void Cop::getInformation(){ + string input; + + //ignore From-inform + do{ + getline(cin,input); + }while(input != "from/"); +} + +void Cop::sendPlan(){ + cout << "plan\\" << endl; + //cout << "plan: " << _name << endl; + cout << "plan/" << endl; +} + +void Cop::getPlans(){ + string input; + + //ignore From-plan + do{ + getline(cin,input); + }while(input != "from/"); + + +} + +void Cop::vote(){ + cout << "vote\\" << endl; + cout << "vote: " << _name << endl; + for (hash_map::const_iterator player = _players.begin(); + player != _players.end(); ++player){ + if (player->second.type != robber && player->first != _name){ + cout << "vote: " << player->first << endl; + cerr << "voted for " << player->first << " of type: " << player->second.type << endl; + } + } + cout << "vote/" << endl; +} + +int main(){ + Cop cop("cop"); + cop.play(); + + return 0; +} diff --git a/copsrc/cop.h b/copsrc/cop.h new file mode 100644 index 0000000..42cb778 --- /dev/null +++ b/copsrc/cop.h @@ -0,0 +1,18 @@ +#ifndef __COP_H__ +#define __COP_H__ + +#include + +class Cop : public Bot { + public: + Cop(std::string name):Bot(name,cop_foot){}; + + std::string turn(); + protected: + void sendInformation(); + void getInformation(); + void sendPlan(); + void getPlans(); + void vote(); +}; +#endif diff --git a/copsrc/cop.pro b/copsrc/cop.pro new file mode 100644 index 0000000..28849d8 --- /dev/null +++ b/copsrc/cop.pro @@ -0,0 +1,14 @@ +###################################################################### +# Automatically generated by qmake (1.07a) Fri Jun 24 23:15:16 2005 +###################################################################### + +TEMPLATE = app +INCLUDEPATH += ../bot +CONFIG -= qt +CONFIG += debug +unix:LIBS += -lm + + +# Input +HEADERS += cop.h +SOURCES += cop.cpp ../bot/bot.cpp diff --git a/robber/robber.cpp b/robber/robber.cpp deleted file mode 100644 index dbb287a..0000000 --- a/robber/robber.cpp +++ /dev/null @@ -1,110 +0,0 @@ -#include "robber.h" -#include -#include -#include -#include - -using namespace std; -using namespace __gnu_cxx; - -string Robber::turn(){ - hash_map streets; - Intersection& inter = _intersections[_location]; - for (hash_map::const_iterator street = inter.connections.begin(); - street != inter.connections.end(); ++street){ - if (street->second == car){ - cerr << "Discarding: " << street->first << " since car is needed" << endl; - continue; - } - double goodness = 0; - Intersection& conInter = _intersections[street->first]; - - list closestFootCop = shortestPath(street->first, cop_foot, FindPlayer(_players, cop_foot, 6), true); - list closestCarCop = shortestPath(street->first, cop_car, FindPlayer(_players, cop_car, 5), true); - - unsigned int closestCop = 0; - bool copInCar = false; - - if (closestCarCop.size() < closestFootCop.size() && closestCarCop.size() > 0){ - closestCop = closestCarCop.size(); - copInCar = true; - }else - closestCop = closestFootCop.size(); - - if (closestCop > 0 && closestCop < 3){ - cerr << "Cop " << closestCop << " intersections away." << endl; - continue; - } - - priority_queue banks; - for(hash_map::const_iterator bank = _banks.begin(); - bank != _banks.end(); ++bank){ - //cerr << "Handling bank at: " << bank->first << endl; - if (bank->second > 0){ - list l = shortestPath(street->first, _type, SimpleSPGoal(bank->first)); - if (l.size() < 1) - continue; - //list::iterator i = l.begin(); - //++i; - banks.push(bank->second/(pow(l.size(),4.0))); - } - } - //sort(banks.begin(),banks.end(),greater()); - - for (unsigned int i = 0; i < 2 && banks.size() > 0;++i){ - goodness += banks.top(); - banks.pop(); - } - - cerr << "Goodness before cop: " << goodness << endl; - if (closestCop > 2){ - cerr << "Cop " << closestCop << " intersections away." << endl; - goodness *= 1 - 1/(copInCar ? closestCop : closestCop - 1); - } - cerr << "Goodness after cop: " << goodness << endl; - - if (conInter.type == bank){ - cerr << "FOUND A BANK" << endl; - if (closestCop > 0 && closestCop < 4) - continue; - else if (_banks[street->first] > 0){ - cerr << "No cop close to bank" << endl; - return street->first; - } - } - - cerr << "Street: " << street->first << " goodness: " << goodness << endl; - streets[street->first] = goodness; - } - streets[_oldLocation] /= 10; - - - - /*cerr << "Using route: "; - copy(v.begin(), v.end(), ostream_iterator(cerr, " : ")); - cerr << endl; - */ - - string destination = _location; - double goodness = 0; - for (hash_map::const_iterator dest = streets.begin(); - dest != streets.end(); ++dest){ - cerr << "Goodness: " << dest->second << endl; - if (dest->second > goodness){ - cerr << "New Goodness: " << dest->second << endl; - goodness = dest->second; - destination = dest->first; - } - } - _oldLocation = _location; - - return destination; - -} - -int main(){ - Robber robber("robber"); - robber.play(); - - return 0; -} diff --git a/robber/robber.h b/robber/robber.h deleted file mode 100644 index 3ba0871..0000000 --- a/robber/robber.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef __ROBBER_H__ -#define __ROBBER_H__ - -#include "bot.h" - -class Robber : public Bot { - public: - Robber(std::string name):Bot(name,robber){}; - - std::string turn(); - - protected: - std::string _oldLocation; - std::string _maybeNextLocation; -}; -#endif diff --git a/robber/robber.pro b/robber/robber.pro deleted file mode 100644 index 2ad532c..0000000 --- a/robber/robber.pro +++ /dev/null @@ -1,14 +0,0 @@ -###################################################################### -# Automatically generated by qmake (1.07a) Fri Jun 24 23:15:16 2005 -###################################################################### - -TEMPLATE = app -INCLUDEPATH += ../bot -CONFIG -= qt -CONFIG += debug -unix:LIBS += -lm - - -# Input -HEADERS += robber.h ../bot/bot.h -SOURCES += robber.cpp ../bot/bot.cpp diff --git a/robbersrc/robber.cpp b/robbersrc/robber.cpp new file mode 100644 index 0000000..dbb287a --- /dev/null +++ b/robbersrc/robber.cpp @@ -0,0 +1,110 @@ +#include "robber.h" +#include +#include +#include +#include + +using namespace std; +using namespace __gnu_cxx; + +string Robber::turn(){ + hash_map streets; + Intersection& inter = _intersections[_location]; + for (hash_map::const_iterator street = inter.connections.begin(); + street != inter.connections.end(); ++street){ + if (street->second == car){ + cerr << "Discarding: " << street->first << " since car is needed" << endl; + continue; + } + double goodness = 0; + Intersection& conInter = _intersections[street->first]; + + list closestFootCop = shortestPath(street->first, cop_foot, FindPlayer(_players, cop_foot, 6), true); + list closestCarCop = shortestPath(street->first, cop_car, FindPlayer(_players, cop_car, 5), true); + + unsigned int closestCop = 0; + bool copInCar = false; + + if (closestCarCop.size() < closestFootCop.size() && closestCarCop.size() > 0){ + closestCop = closestCarCop.size(); + copInCar = true; + }else + closestCop = closestFootCop.size(); + + if (closestCop > 0 && closestCop < 3){ + cerr << "Cop " << closestCop << " intersections away." << endl; + continue; + } + + priority_queue banks; + for(hash_map::const_iterator bank = _banks.begin(); + bank != _banks.end(); ++bank){ + //cerr << "Handling bank at: " << bank->first << endl; + if (bank->second > 0){ + list l = shortestPath(street->first, _type, SimpleSPGoal(bank->first)); + if (l.size() < 1) + continue; + //list::iterator i = l.begin(); + //++i; + banks.push(bank->second/(pow(l.size(),4.0))); + } + } + //sort(banks.begin(),banks.end(),greater()); + + for (unsigned int i = 0; i < 2 && banks.size() > 0;++i){ + goodness += banks.top(); + banks.pop(); + } + + cerr << "Goodness before cop: " << goodness << endl; + if (closestCop > 2){ + cerr << "Cop " << closestCop << " intersections away." << endl; + goodness *= 1 - 1/(copInCar ? closestCop : closestCop - 1); + } + cerr << "Goodness after cop: " << goodness << endl; + + if (conInter.type == bank){ + cerr << "FOUND A BANK" << endl; + if (closestCop > 0 && closestCop < 4) + continue; + else if (_banks[street->first] > 0){ + cerr << "No cop close to bank" << endl; + return street->first; + } + } + + cerr << "Street: " << street->first << " goodness: " << goodness << endl; + streets[street->first] = goodness; + } + streets[_oldLocation] /= 10; + + + + /*cerr << "Using route: "; + copy(v.begin(), v.end(), ostream_iterator(cerr, " : ")); + cerr << endl; + */ + + string destination = _location; + double goodness = 0; + for (hash_map::const_iterator dest = streets.begin(); + dest != streets.end(); ++dest){ + cerr << "Goodness: " << dest->second << endl; + if (dest->second > goodness){ + cerr << "New Goodness: " << dest->second << endl; + goodness = dest->second; + destination = dest->first; + } + } + _oldLocation = _location; + + return destination; + +} + +int main(){ + Robber robber("robber"); + robber.play(); + + return 0; +} diff --git a/robbersrc/robber.h b/robbersrc/robber.h new file mode 100644 index 0000000..3ba0871 --- /dev/null +++ b/robbersrc/robber.h @@ -0,0 +1,16 @@ +#ifndef __ROBBER_H__ +#define __ROBBER_H__ + +#include "bot.h" + +class Robber : public Bot { + public: + Robber(std::string name):Bot(name,robber){}; + + std::string turn(); + + protected: + std::string _oldLocation; + std::string _maybeNextLocation; +}; +#endif diff --git a/robbersrc/robber.pro b/robbersrc/robber.pro new file mode 100644 index 0000000..2ad532c --- /dev/null +++ b/robbersrc/robber.pro @@ -0,0 +1,14 @@ +###################################################################### +# Automatically generated by qmake (1.07a) Fri Jun 24 23:15:16 2005 +###################################################################### + +TEMPLATE = app +INCLUDEPATH += ../bot +CONFIG -= qt +CONFIG += debug +unix:LIBS += -lm + + +# Input +HEADERS += robber.h ../bot/bot.h +SOURCES += robber.cpp ../bot/bot.cpp