_name = value<string>(input);
cerr << "Got name: " << _name << endl;
- //robber and 5 cops
- getline(cin, input);
- _players[value<string>(input)].type = robber;
- getline(cin, input);
- _players[value<string>(input)].type = cop_foot;
- getline(cin, input);
- _players[value<string>(input)].type = cop_foot;
- getline(cin, input);
- _players[value<string>(input)].type = cop_foot;
- getline(cin, input);
- _players[value<string>(input)].type = cop_foot;
+ getPlayers();
cerr << "Got players, building graph." << endl;
getline(cin, input);
buildGraph();
- getline(cin, input);
while (true){
getline(cin, input);
updateWorld();
_type = _players[_name].type;
_location = _players[_name].location;
- getline(cin, input);
cerr << "New turn" << endl;
move(turn());
cerr << "Done with turn." << endl;
}
}
+void Bot::getPlayers(){
+ string input;
+ //robber and 5 cops
+ getline(cin, input);
+ _players[value<string>(input)].type = robber;
+ getline(cin, input);
+ _players[value<string>(input)].type = cop_foot;
+ getline(cin, input);
+ _players[value<string>(input)].type = cop_foot;
+ getline(cin, input);
+ _players[value<string>(input)].type = cop_foot;
+ getline(cin, input);
+ _players[value<string>(input)].type = cop_foot;
+}
+
/**
nod\ eol
( nod: loc node-tag coordinate coordinate eol )*
_intersections[from].connections[to] = car;
}
cerr << "Number of streets: " << streets << endl;
+ getline(cin, input);
}
void Bot::updateWorld(){
pl.type = _playerTypes[input];
}
//cerr << "Number of players: " << _players.size() << endl;
+ getline(cin, input);
}
void Bot::move(std::string location){
virtual int operator()(const SPInfo* node) const = 0;
};
-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;
- }
-};
-
class Bot {
public:
Bot(const std::string& name, PlayerType type);
void updateWorld();
virtual std::string turn() = 0;
void move(std::string location);
+ void getPlayers();
std::list<std::string> shortestPath(const std::string& from, PlayerType type, const SPGoal& goal);
__gnu_cxx::hash_map<std::string, Intersection> _intersections;
int _smell;
};
+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;
+ }
+};
+
#endif
using namespace std;
using namespace __gnu_cxx;
-struct FindCop : SPGoal{
+struct FindPlayer : SPGoal{
int _limit;
const hash_map<string, Player>& _players;
- FindCop(const hash_map<string, Player>& players, int limit = 0) : _players(players), _limit(limit){}
+ PlayerType _type;
+ FindPlayer(const hash_map<string, Player>& 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<string, Player>::const_iterator player = _players.begin();
player != _players.end(); ++player){
- if (player->second.type != robber && player->second.location == node->name){
+ if (player->second.type == _type && player->second.location == node->name){
return 1;
}
}
double goodness = 10;
Intersection& conInter = _intersections[street->first];
- list<string> l = shortestPath(street->first, _type, FindCop(_players, 5));
- if (l.size() > 0){
- cerr << "Cop " << l.size() << " intersections away." << endl;
- if (l.size() < 3)
+ list<string> closestFootCop = shortestPath(street->first, cop_foot, FindPlayer(_players, cop_foot, 5));
+ list<string> closestCarCop = shortestPath(street->first, cop_car, FindPlayer(_players, cop_car, 4));
+
+ unsigned int closestCop = 0;
+ bool copInCar = false;
+
+ if (closestFootCop.size() < closestCarCop.size() && closestFootCop.size() > 0)
+ closestCop = closestFootCop.size();
+ else {
+ closestCop = closestCarCop.size();
+ copInCar = true;
+ }
+
+ if (closestCop > 0){
+ cerr << "Cop " << closestCop << " intersections away." << endl;
+ if (closestCop < 3)
continue;
- goodness *= 1 - 1/l.size();
+ if (!copInCar)
+ --closestCop;
+ goodness *= 1 - 1/closestCop;
}
if (conInter.type == bank){
cerr << "FOUND A BANK" << endl;
- if (l.size() > 0 && l.size() < 4)
+ if (closestCop > 0 && closestCop < 4)
continue;
else if (_banks[street->first] > 0){
cerr << "No cop close to bank" << endl;