]> ruin.nu Git - icfp05.git/blobdiff - botsrc/bot.h
initial implementation of new robber
[icfp05.git] / botsrc / bot.h
index ee236ee1e0519056ad9d70cb0aef978d0538775b..62f25569fd2f3f57089fc8d58733675bfee1a605 100644 (file)
@@ -64,13 +64,6 @@ struct SPInfo{
        int cost;
 };
 
-
-class SPGoal{
-       public:
-       virtual ~SPGoal(){}
-       virtual int operator()(const SPInfo* node) const = 0;
-};
-
 class Bot {
        public:
                Bot(const std::string& name, PlayerType type);
@@ -81,39 +74,81 @@ class Bot {
        protected:
                void buildGraph();
                void updateWorld();
-               virtual std::string turn() = 0;
-               void move(std::string location);
+               virtual std::string turn();
+               virtual void preGamePreparations(){};
+               virtual void move(std::string location);
+               virtual void sendInformation();
+               virtual void getInformation();
+               virtual void sendPlan();
+               virtual void getPlans();
+               virtual void vote();
+               virtual void voteResult();
                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;
+               template<class Goal, class Cost>
+               std::list<std::string> shortestPath(const std::string& from, PlayerType type, const Goal& goal, const Cost& cost, bool reverse = false) const;
+               template<class Goal>
+               std::list<std::string> shortestPath(const std::string& from, PlayerType type, const Goal& goal, bool reverse = false) const;
+
+               __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;
+               std::string _robberLocation;
+               std::string _copHq;
+               __gnu_cxx::hash_map<std::string, int> _winningPlans;
 };
 
-class SimpleSPGoal : public SPGoal{
+
+class SimpleSPGoal{
        std::string _to;
-       SimpleSPGoal(std::string to);
+       int _limit;
        public:
-       int operator()(const SPInfo* node) const;
+       SimpleSPGoal(const std::string& to, int limit = 0):_to(to), _limit(limit){
+       }
+       inline int operator()(const SPInfo* node) const{
+               if (_limit > 0 && node->cost >= _limit)
+                       return -1;
+               if (node->name == _to)
+                       return 1;
+               return 0;
+       }
+
 };
 
-class FindPlayer : SPGoal{
+class FindPlayer{
        int _limit;
        const __gnu_cxx::hash_map<std::string, Player>& _players;
        PlayerType _type;
        public:
-       FindPlayer(const __gnu_cxx::hash_map<std::string, Player>& players, PlayerType type, int limit = 0);
-       int operator()(const SPInfo* node) const;
+       FindPlayer(const __gnu_cxx::hash_map<std::string, Player>& players, PlayerType type, int limit = 0): _players(players), _type(type), _limit(limit){
+       }
+       inline int operator()(const SPInfo* node) const{
+               if (_limit > 0 && node->cost >= _limit)
+                       return -1;
+               for(__gnu_cxx::hash_map<std::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;
+       }
+
 };
 
+struct SPInfoComp{
+       inline bool operator()(const SPInfo* v1, const SPInfo* v2){
+               return v1->cost > v2->cost;
+       }
+};
+
+
 #endif