X-Git-Url: https://ruin.nu/git/?p=icfp05.git;a=blobdiff_plain;f=botsrc%2Fbot.h;h=62f25569fd2f3f57089fc8d58733675bfee1a605;hp=731a106a4a1dbcc847ee41f2fd65da03c1ac96dd;hb=ea7c6c2755a89718e1396c1c3f8061886861ff4c;hpb=e80a1fceda25988c576631be47a9b122126d8f53 diff --git a/botsrc/bot.h b/botsrc/bot.h index 731a106..62f2556 100644 --- a/botsrc/bot.h +++ b/botsrc/bot.h @@ -64,12 +64,6 @@ struct SPInfo{ int cost; }; - -struct SPGoal{ - virtual ~SPGoal(){} - virtual int operator()(const SPInfo* node) const = 0; -}; - class Bot { public: Bot(const std::string& name, PlayerType type); @@ -80,37 +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 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; + template + std::list shortestPath(const std::string& from, PlayerType type, const Goal& goal, const Cost& cost, bool reverse = false) const; + template + std::list shortestPath(const std::string& from, PlayerType type, const Goal& goal, bool reverse = false) const; + + __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; + std::string _robberLocation; + std::string _copHq; + __gnu_cxx::hash_map _winningPlans; }; -struct SimpleSPGoal : public SPGoal{ + +class SimpleSPGoal{ std::string _to; - SimpleSPGoal(std::string to); - int operator()(const SPInfo* node) const; + int _limit; + public: + 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; + } + }; -struct FindPlayer : SPGoal{ +class FindPlayer{ 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; + public: + 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