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);
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;
__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