]> ruin.nu Git - icfp05.git/commitdiff
renamed dirs
authorMichael Andreen <harv@ruin.nu>
Sun, 26 Jun 2005 23:15:38 +0000 (23:15 +0000)
committerMichael Andreen <harv@ruin.nu>
Sun, 26 Jun 2005 23:15:38 +0000 (23:15 +0000)
16 files changed:
bot/bot.cpp [deleted file]
bot/bot.h [deleted file]
botsrc/bot.cpp [new file with mode: 0644]
botsrc/bot.h [new file with mode: 0644]
cop/cop.cpp [deleted file]
cop/cop.h [deleted file]
cop/cop.pro [deleted file]
copsrc/cop.cpp [new file with mode: 0644]
copsrc/cop.h [new file with mode: 0644]
copsrc/cop.pro [new file with mode: 0644]
robber/robber.cpp [deleted file]
robber/robber.h [deleted file]
robber/robber.pro [deleted file]
robbersrc/robber.cpp [new file with mode: 0644]
robbersrc/robber.h [new file with mode: 0644]
robbersrc/robber.pro [new file with mode: 0644]

diff --git a/bot/bot.cpp b/bot/bot.cpp
deleted file mode 100644 (file)
index 28e8004..0000000
+++ /dev/null
@@ -1,330 +0,0 @@
-#include <iostream>
-#include <sstream>
-#include <iterator>
-#include <queue>
-#include <vector>
-#include <utility>
-#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<string>(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<string>(input)].type = robber;
-       getline(cin, input);
-       _players[value<string>(input)].type = cop_foot;
-       getline(cin, input);
-       _players[value<string>(input)].type = cop_foot;
-       getline(cin, input);
-       _players[value<string>(input)].type = cop_foot;
-       getline(cin, input);
-       _players[value<string>(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<int>(input);
-       //cerr << "World: " << _world << endl;
-
-       getline(cin,input);
-       _robbed = value<int>(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<int>(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<class T>
-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<std::string> Bot::shortestPath(const std::string& from, PlayerType type, const SPGoal& goal, bool reverse){
-
-       //cerr << "New shortest path from: " << from << endl;
-       
-       priority_queue<SPInfo*, vector<SPInfo* >, SPInfoComp > pq;
-       hash_map<string,SPInfo> 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<string>(cerr, " : "));
-
-               g = goal(node);
-               if (g < 0)
-                       break;
-               else if (g){
-                       list<string> l;
-                       front_insert_iterator<list<string> > 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<string,StreetType>::const_iterator street = inter.connections.begin();
-                               street != inter.connections.end(); ++street){
-                       hash_map<string,SPInfo>::iterator newNode = nodes.find(street->first);
-                       bool travelStreet = false;
-                       if (hascar){
-                               if (reverse){
-                                       if (street->second != foot){
-                                               hash_map<string,StreetType>::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<string>();
-}
-
-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<string, Player>& 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<string, Player>::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 (file)
index 731a106..0000000
--- a/bot/bot.h
+++ /dev/null
@@ -1,116 +0,0 @@
-#ifndef __BOT_H__
-#define __BOT_H__
-
-#include <ext/hash_map>
-#include <list>
-#include <string>
-#include <locale>
-#include <map>
-// 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<CharT, Traits, Alloc> > {
-                       size_t operator()(const std::basic_string<CharT, Traits, Alloc>& s) const {
-
-                               const std::collate<CharT>& c = std::use_facet< std::collate<CharT> >(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<CharT, Traits, Alloc> > { //yes you need this version aswell!
-
-                       size_t operator()(const std::basic_string<CharT, Traits, Alloc>& s) const {
-
-                               const std::collate<CharT>& c = std::use_facet< std::collate<CharT> >(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<std::string,StreetType> connections;
-       IntersectionType type;
-       int x;
-       int y;
-};
-
-struct Player{
-       PlayerType type;
-       std::string location;
-};
-
-struct Bank{
-       std::string location;
-       int value;
-};
-
-template<class T>
-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<std::string> shortestPath(const std::string& from, PlayerType type, const SPGoal& goal, bool reverse = false);
-
-       __gnu_cxx::hash_map<std::string, Intersection> _intersections;
-       __gnu_cxx::hash_map<std::string, Player> _players;
-       __gnu_cxx::hash_map<std::string, int> _banks;
-       std::map<int, std::string> _evidence;
-       std::map<PlayerType, std::string> _playerTypeNames;
-       std::map<std::string, PlayerType> _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<std::string, Player>& _players;
-       PlayerType _type;
-       FindPlayer(const __gnu_cxx::hash_map<std::string, Player>& 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 (file)
index 0000000..28e8004
--- /dev/null
@@ -0,0 +1,330 @@
+#include <iostream>
+#include <sstream>
+#include <iterator>
+#include <queue>
+#include <vector>
+#include <utility>
+#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<string>(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<string>(input)].type = robber;
+       getline(cin, input);
+       _players[value<string>(input)].type = cop_foot;
+       getline(cin, input);
+       _players[value<string>(input)].type = cop_foot;
+       getline(cin, input);
+       _players[value<string>(input)].type = cop_foot;
+       getline(cin, input);
+       _players[value<string>(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<int>(input);
+       //cerr << "World: " << _world << endl;
+
+       getline(cin,input);
+       _robbed = value<int>(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<int>(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<class T>
+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<std::string> Bot::shortestPath(const std::string& from, PlayerType type, const SPGoal& goal, bool reverse){
+
+       //cerr << "New shortest path from: " << from << endl;
+       
+       priority_queue<SPInfo*, vector<SPInfo* >, SPInfoComp > pq;
+       hash_map<string,SPInfo> 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<string>(cerr, " : "));
+
+               g = goal(node);
+               if (g < 0)
+                       break;
+               else if (g){
+                       list<string> l;
+                       front_insert_iterator<list<string> > 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<string,StreetType>::const_iterator street = inter.connections.begin();
+                               street != inter.connections.end(); ++street){
+                       hash_map<string,SPInfo>::iterator newNode = nodes.find(street->first);
+                       bool travelStreet = false;
+                       if (hascar){
+                               if (reverse){
+                                       if (street->second != foot){
+                                               hash_map<string,StreetType>::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<string>();
+}
+
+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<string, Player>& 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<string, Player>::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 (file)
index 0000000..731a106
--- /dev/null
@@ -0,0 +1,116 @@
+#ifndef __BOT_H__
+#define __BOT_H__
+
+#include <ext/hash_map>
+#include <list>
+#include <string>
+#include <locale>
+#include <map>
+// 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<CharT, Traits, Alloc> > {
+                       size_t operator()(const std::basic_string<CharT, Traits, Alloc>& s) const {
+
+                               const std::collate<CharT>& c = std::use_facet< std::collate<CharT> >(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<CharT, Traits, Alloc> > { //yes you need this version aswell!
+
+                       size_t operator()(const std::basic_string<CharT, Traits, Alloc>& s) const {
+
+                               const std::collate<CharT>& c = std::use_facet< std::collate<CharT> >(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<std::string,StreetType> connections;
+       IntersectionType type;
+       int x;
+       int y;
+};
+
+struct Player{
+       PlayerType type;
+       std::string location;
+};
+
+struct Bank{
+       std::string location;
+       int value;
+};
+
+template<class T>
+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<std::string> shortestPath(const std::string& from, PlayerType type, const SPGoal& goal, bool reverse = false);
+
+       __gnu_cxx::hash_map<std::string, Intersection> _intersections;
+       __gnu_cxx::hash_map<std::string, Player> _players;
+       __gnu_cxx::hash_map<std::string, int> _banks;
+       std::map<int, std::string> _evidence;
+       std::map<PlayerType, std::string> _playerTypeNames;
+       std::map<std::string, PlayerType> _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<std::string, Player>& _players;
+       PlayerType _type;
+       FindPlayer(const __gnu_cxx::hash_map<std::string, Player>& 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 (file)
index f5a7f3f..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-#include "cop.h"
-#include <iostream>
-#include <iterator>
-#include <cmath>
-
-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<string,Player>::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 (file)
index 42cb778..0000000
--- a/cop/cop.h
+++ /dev/null
@@ -1,18 +0,0 @@
-#ifndef __COP_H__
-#define __COP_H__
-
-#include <bot.h>
-
-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 (file)
index 28849d8..0000000
+++ /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 (file)
index 0000000..f5a7f3f
--- /dev/null
@@ -0,0 +1,75 @@
+#include "cop.h"
+#include <iostream>
+#include <iterator>
+#include <cmath>
+
+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<string,Player>::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 (file)
index 0000000..42cb778
--- /dev/null
@@ -0,0 +1,18 @@
+#ifndef __COP_H__
+#define __COP_H__
+
+#include <bot.h>
+
+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 (file)
index 0000000..28849d8
--- /dev/null
@@ -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 (file)
index dbb287a..0000000
+++ /dev/null
@@ -1,110 +0,0 @@
-#include "robber.h"
-#include <iostream>
-#include <iterator>
-#include <queue>
-#include <cmath>
-
-using namespace std;
-using namespace __gnu_cxx;
-
-string Robber::turn(){
-       hash_map<string,double> streets;
-       Intersection& inter = _intersections[_location];
-       for (hash_map<string,StreetType>::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<string> closestFootCop = shortestPath(street->first, cop_foot, FindPlayer(_players, cop_foot, 6), true);
-               list<string> 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<double> banks;
-               for(hash_map<string,int>::const_iterator bank = _banks.begin();
-                               bank != _banks.end(); ++bank){
-                       //cerr << "Handling bank at: " << bank->first << endl;
-                       if (bank->second > 0){
-                               list<string> l = shortestPath(street->first, _type, SimpleSPGoal(bank->first));
-                               if (l.size() < 1)
-                                       continue;
-                               //list<string>::iterator i = l.begin();
-                               //++i;
-                               banks.push(bank->second/(pow(l.size(),4.0)));
-                       }
-               }
-               //sort(banks.begin(),banks.end(),greater<double>());
-
-               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<string>(cerr, " : "));
-       cerr << endl;
-       */
-
-       string destination = _location;
-       double goodness = 0;
-       for (hash_map<string,double>::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 (file)
index 3ba0871..0000000
+++ /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 (file)
index 2ad532c..0000000
+++ /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 (file)
index 0000000..dbb287a
--- /dev/null
@@ -0,0 +1,110 @@
+#include "robber.h"
+#include <iostream>
+#include <iterator>
+#include <queue>
+#include <cmath>
+
+using namespace std;
+using namespace __gnu_cxx;
+
+string Robber::turn(){
+       hash_map<string,double> streets;
+       Intersection& inter = _intersections[_location];
+       for (hash_map<string,StreetType>::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<string> closestFootCop = shortestPath(street->first, cop_foot, FindPlayer(_players, cop_foot, 6), true);
+               list<string> 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<double> banks;
+               for(hash_map<string,int>::const_iterator bank = _banks.begin();
+                               bank != _banks.end(); ++bank){
+                       //cerr << "Handling bank at: " << bank->first << endl;
+                       if (bank->second > 0){
+                               list<string> l = shortestPath(street->first, _type, SimpleSPGoal(bank->first));
+                               if (l.size() < 1)
+                                       continue;
+                               //list<string>::iterator i = l.begin();
+                               //++i;
+                               banks.push(bank->second/(pow(l.size(),4.0)));
+                       }
+               }
+               //sort(banks.begin(),banks.end(),greater<double>());
+
+               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<string>(cerr, " : "));
+       cerr << endl;
+       */
+
+       string destination = _location;
+       double goodness = 0;
+       for (hash_map<string,double>::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 (file)
index 0000000..3ba0871
--- /dev/null
@@ -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 (file)
index 0000000..2ad532c
--- /dev/null
@@ -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