]> ruin.nu Git - icfp05.git/blobdiff - botsrc/bot.h
templates
[icfp05.git] / botsrc / bot.h
index aab4e831ea021ccbd610ae1c7a0e558aeaafaf69..aad7473d6d24de7c004f10a19b7374b11ee6529d 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);
@@ -91,7 +84,8 @@ class Bot {
                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);
+               template<class Goal>
+               std::list<std::string> shortestPath(const std::string& from, PlayerType type, const Goal& goal, bool reverse = false);
 
                __gnu_cxx::hash_map<std::string, Intersection> _intersections;
                __gnu_cxx::hash_map<std::string, Player> _players;
@@ -110,21 +104,48 @@ class Bot {
                __gnu_cxx::hash_map<std::string, int> _winningPlans;
 };
 
-class SimpleSPGoal : public SPGoal{
+class SimpleSPGoal{
        std::string _to;
        int _limit;
        public:
-       SimpleSPGoal(const std::string& to, int limit = 0);
-       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 : public 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