X-Git-Url: https://ruin.nu/git/?p=icfp05.git;a=blobdiff_plain;f=botsrc%2Fbot.h;h=aad7473d6d24de7c004f10a19b7374b11ee6529d;hp=aab4e831ea021ccbd610ae1c7a0e558aeaafaf69;hb=aae26492dc1712e3f4783223df158ff5aa65d975;hpb=8b5e24a0d19af8af51155da4a5c8515bb3b8a7ee diff --git a/botsrc/bot.h b/botsrc/bot.h index aab4e83..aad7473 100644 --- a/botsrc/bot.h +++ b/botsrc/bot.h @@ -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 shortestPath(const std::string& from, PlayerType type, const SPGoal& goal, bool reverse = false); + template + std::list shortestPath(const std::string& from, PlayerType type, const Goal& goal, bool reverse = false); __gnu_cxx::hash_map _intersections; __gnu_cxx::hash_map _players; @@ -110,21 +104,48 @@ class Bot { __gnu_cxx::hash_map _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& _players; PlayerType _type; public: - FindPlayer(const __gnu_cxx::hash_map& players, PlayerType type, int limit = 0); - int operator()(const SPInfo* node) const; + FindPlayer(const __gnu_cxx::hash_map& 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::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