]> ruin.nu Git - icfp05.git/commitdiff
tuning and restructuring
authorMichael Andreen <harv@ruin.nu>
Sun, 26 Jun 2005 17:07:40 +0000 (17:07 +0000)
committerMichael Andreen <harv@ruin.nu>
Sun, 26 Jun 2005 17:07:40 +0000 (17:07 +0000)
bot/bot.cpp
bot/bot.h
robber/robber.cpp

index 181b423d44c82e714aca3f84a82c882d78c77604..7605cf1ebd473c8b9b373c4c3fc9fc0a19caa185 100644 (file)
@@ -70,22 +70,11 @@ void Bot::play(){
        _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);
@@ -94,13 +83,27 @@ void Bot::play(){
                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 )*        
@@ -168,6 +171,7 @@ void Bot::buildGraph(){
                        _intersections[from].connections[to] = car;
        }
        cerr << "Number of streets: " << streets << endl;
+       getline(cin, input);
 }
 
 void Bot::updateWorld(){
@@ -223,6 +227,7 @@ void Bot::updateWorld(){
                pl.type = _playerTypes[input];
        }
        //cerr << "Number of players: " << _players.size() << endl;
+       getline(cin, input);
 }
 
 void Bot::move(std::string location){
index efe373f77ed5c26890e19d2cd2360310636559fd..d01ec114853e118456235efea29b4650d8d268c5 100644 (file)
--- a/bot/bot.h
+++ b/bot/bot.h
@@ -70,17 +70,6 @@ struct SPGoal{
        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);
@@ -93,6 +82,7 @@ class Bot {
                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;
@@ -109,4 +99,15 @@ class Bot {
        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
index 52e00de1fc50775d37093db9373e234976a66c3f..8a11defe6862b6616967fe11269f2924bccb58ad 100644 (file)
@@ -6,16 +6,17 @@
 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;
                        }
                }
@@ -35,17 +36,31 @@ string Robber::turn(){
                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;