From d7d9942fc9d1066670e166182e36791dfbf035d7 Mon Sep 17 00:00:00 2001 From: Michael Andreen Date: Sun, 26 Jun 2005 23:13:30 +0000 Subject: [PATCH] some restructuring --- bot/bot.cpp | 24 ++++++++++++++++++++++++ bot/bot.h | 17 ++++++++++------- robber/robber.cpp | 18 ------------------ 3 files changed, 34 insertions(+), 25 deletions(-) diff --git a/bot/bot.cpp b/bot/bot.cpp index 713f190..28e8004 100644 --- a/bot/bot.cpp +++ b/bot/bot.cpp @@ -304,3 +304,27 @@ std::list Bot::shortestPath(const std::string& from, PlayerType typ return list(); } + +SimpleSPGoal::SimpleSPGoal(std::string to):_to(to){ +} + +int SimpleSPGoal::operator()(const SPInfo* node) const{ + if (node->name == _to) + return 1; + return 0; +} + +FindPlayer::FindPlayer(const hash_map& players, PlayerType type, int limit) : _players(players), _type(type), _limit(limit){ +} + +int FindPlayer::operator()(const SPInfo* node) const{ + if (_limit > 0 && node->cost >= _limit) + return -1; + for(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; +} diff --git a/bot/bot.h b/bot/bot.h index 72d2d6b..731a106 100644 --- a/bot/bot.h +++ b/bot/bot.h @@ -101,13 +101,16 @@ class Bot { struct SimpleSPGoal : public SPGoal{ std::string _to; - SimpleSPGoal(std::string to):_to(to){}; - ~SimpleSPGoal(){} - int operator()(const SPInfo* node) const{ - if (node->name == _to) - return 1; - return 0; - } + SimpleSPGoal(std::string to); + int operator()(const SPInfo* node) const; +}; + +struct FindPlayer : SPGoal{ + 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; }; #endif diff --git a/robber/robber.cpp b/robber/robber.cpp index f586f6a..dbb287a 100644 --- a/robber/robber.cpp +++ b/robber/robber.cpp @@ -7,24 +7,6 @@ using namespace std; using namespace __gnu_cxx; -struct FindPlayer : SPGoal{ - int _limit; - const hash_map& _players; - PlayerType _type; - FindPlayer(const hash_map& players, PlayerType type, int limit = 0) : _players(players), _type(type), _limit(limit){} - int operator()(const SPInfo* node) const{ - if (_limit > 0 && node->cost >= _limit) - return -1; - for(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; - } -}; - string Robber::turn(){ hash_map streets; Intersection& inter = _intersections[_location]; -- 2.39.2