]> ruin.nu Git - icfp05.git/commitdiff
base class got enough for robber implementation
authorMichael Andreen <harv@ruin.nu>
Fri, 24 Jun 2005 21:10:10 +0000 (21:10 +0000)
committerMichael Andreen <harv@ruin.nu>
Fri, 24 Jun 2005 21:10:10 +0000 (21:10 +0000)
bot/bot.cpp
bot/bot.h

index c7af4a6f902f22e4736e5e8c8ee8d2465eb3ffe5..8946d03f6feba2764407b3f0dedd7174a6c0acc6 100644 (file)
@@ -19,20 +19,163 @@ void Bot::play(){
        if (input != "wsk\\")
                return;
        getline(cin, input);
-       _name = tokenizeString(input)[1];
+       _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";
+
+       cerr << "Got players, building graph." << endl;
+       getline(cin, input);
        buildGraph();
-       updateWorld();
-       turn();
+       getline(cin, input);
+
+       while (true){
+               getline(cin, input);
+               if (input == "game-over")
+                       return;
+               updateWorld();
+               _type = _players[_name].type;
+               _location = _players[_name].location;
+               getline(cin, input);
+               move(turn());
+       }
+}
+
+Bot::~Bot(){
 }
 
+/**
+                               nod\ eol        
+                               ( nod: loc node-tag coordinate coordinate eol )*        
+                               nod/ eol        
+                               edg\ eol        
+                               ( edg: loc loc edge-type eol )* 
+                               edg/ eol        
+*/
 void Bot::buildGraph(){
+       string input;
+       getline(cin, input);
+       if (input != "nod\\")
+               return;
+
+       cerr << "Getting intersections" << endl;
+       while (true){
+               getline(cin, input);
+               if (input == "nod/")
+                       break;
+               istringstream node(input);
+               node >> input;
+               node >> input;
+               Intersection& inter = _intersections[input];
+               node >> inter.type;
+               node >> inter.x;
+               node >> inter.y;
+       }
 
+       cerr << "Number of intersections: " << _intersections.size() << endl;
+
+       getline(cin, input);
+       if (input != "edg\\")
+               return;
+
+       cerr << "Getting streets" << endl;
+       int streets = 0;
+       while (true){
+               getline(cin, input);
+               if (input == "edg/")
+                       break;
+               ++streets;
+               istringstream street(input);
+               string from;
+               street >> from;
+               string to;
+               street >> to;
+               string type;
+               street >> type;
+               if (type == "foot"){
+                       _intersections[from].connections[to] = both;
+                       Intersection& inter = _intersections[to];
+                       if (inter.connections.find(from) == inter.connections.end())
+                               inter.connections[from] = foot;
+               }else
+                       _intersections[from].connections[to] = car;
+       }
+       cerr << "Number of streets: " << streets << endl;
 }
 
-std::vector<std::string> tokenizeString(std::string input){
+void Bot::updateWorld(){
+       string input;
+       getline(cin,input);
+       _world = value<int>(input);
+       cerr << "World: " << _world << endl;
+
+       getline(cin,input);
+       _robbed = value<int>(input);
+       cerr << "Robbed: " << _robbed << endl;
+
+       getline(cin,input);
+       while (true){
+               getline(cin, input);
+               if (input == "bv/")
+                       break;
+               istringstream bank(input);
+               bank >> input;
+               bank >> input;
+               bank >> _banks[input];
+       }
+       cerr << "Number of banks: " << _banks.size() << endl;
+       
+       getline(cin,input);
+       while (true){
+               getline(cin, input);
+               if (input == "ev/")
+                       break;
+               istringstream evidence(input);
+       }
+       
+       getline(cin,input);
+       _smell = value<int>(input);
+
+       getline(cin,input);
+       while (true){
+               getline(cin, input);
+               if (input == "pl/")
+                       break;
+               istringstream player(input);
+               player >> input;
+               player >> input;
+               cerr << "Player: " << input << endl;
+               Player& pl = _players[input];
+               player >> pl.location;
+               player >> pl.type;
+       }
+       cerr << "Number of players: " << _players.size() << endl;
+}
+
+void Bot::move(std::string location){
+       cout << "mov: " << location << " " << _type << endl;
+}
+
+template<class T>
+T value(std::string input){
        istringstream istr(input);
-       vector<string> strings;
-       copy(istream_iterator<string>(istr), istream_iterator<string>(), back_inserter(strings));
-       return strings;
+       istr >> input;
+       T s;
+       istr >> s;
+       return s;
 }
+
+std::string Bot::turn(){
+       return _location;
+}
+
index d07fb06e829dbb395105873333f75cb86023f58e..416fe63a000e9ee68f9f0998a2023266c6048f4c 100644 (file)
--- a/bot/bot.h
+++ b/bot/bot.h
@@ -32,12 +32,13 @@ namespace __gnu_cxx {
                };
 };
 
-struct AdjInfo{
-       std::string intersection;
-};
+enum StreetType{foot, car, both};
 
 struct Intersection{
-       std::vector<AdjInfo> adjs;
+       __gnu_cxx::hash_map<std::string,StreetType> connections;
+       std::string type;
+       int x;
+       int y;
 };
 
 struct Player{
@@ -50,23 +51,31 @@ struct Bank{
        int value;
 };
 
-std::vector<std::string> tokenizeString(std::string input);
+template<class T>
+T value(std::string input);
 
 class Bot {
        public:
                Bot(std::string name, std::string type);
+               virtual ~Bot();
+
+               virtual void play();
 
-               void play();
+       protected:
                void buildGraph();
                void updateWorld();
-               virtual void turn() = 0;
+               virtual std::string turn();
+               void move(std::string location);
 
-       private:
        __gnu_cxx::hash_map<std::string, Intersection> _intersections;
        __gnu_cxx::hash_map<std::string, Player> _players;
+       __gnu_cxx::hash_map<std::string, int> _banks;
        std::string _name;
        std::string _type;
-       std::string _position;
+       std::string _location;
+       int _world;
+       int _robbed;
+       int _smell;
 };