]> ruin.nu Git - icfp05.git/blob - bot/bot.h
implemented shortest path
[icfp05.git] / bot / bot.h
1 #ifndef __BOT_H__
2 #define __BOT_H__
3
4 #include <ext/hash_map>
5 #include <vector>
6 #include <string>
7 #include <locale>
8 // These are needed to be able to use std::string as key in a hash_map.
9 namespace __gnu_cxx {
10         template< typename CharT, typename Traits, typename Alloc >
11                 struct hash< std::basic_string<CharT, Traits, Alloc> > {
12                         size_t operator()(const std::basic_string<CharT, Traits, Alloc>& s) const {
13
14                                 const std::collate<CharT>& c = std::use_facet< std::collate<CharT> >(std::locale());
15
16                                 return c.hash(s.c_str(), s.c_str() + s.size());
17
18                         }
19
20                 };
21
22         template< typename CharT, typename Traits, typename Alloc >
23                 struct hash< const std::basic_string<CharT, Traits, Alloc> > { //yes you need this version aswell!
24
25                         size_t operator()(const std::basic_string<CharT, Traits, Alloc>& s) const {
26
27                                 const std::collate<CharT>& c = std::use_facet< std::collate<CharT> >(std::locale());
28
29                                 return c.hash(s.c_str(), s.c_str() + s.size());
30                         }
31
32                 };
33 };
34
35 enum StreetType{foot, car, both};
36
37 struct Intersection{
38         __gnu_cxx::hash_map<std::string,StreetType> connections;
39         std::string type;
40         int x;
41         int y;
42 };
43
44 struct Player{
45         std::string type;
46         std::string location;
47 };
48
49 struct Bank{
50         std::string location;
51         int value;
52 };
53
54 template<class T>
55 T value(std::string input);
56
57 class Bot {
58         public:
59                 Bot(std::string name, std::string type);
60                 virtual ~Bot();
61
62                 virtual void play();
63
64         protected:
65                 void buildGraph();
66                 void updateWorld();
67                 virtual std::string turn();
68                 void move(std::string location);
69                 std::vector<std::string> shortestPath(std::string from, std::string to, std::string type);
70
71         __gnu_cxx::hash_map<std::string, Intersection> _intersections;
72         __gnu_cxx::hash_map<std::string, Player> _players;
73         __gnu_cxx::hash_map<std::string, int> _banks;
74         std::string _name;
75         std::string _type;
76         std::string _location;
77         int _world;
78         int _robbed;
79         int _smell;
80 };
81
82
83 #endif