]> ruin.nu Git - icfp05.git/blob - bot.h
initial commit
[icfp05.git] / 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 struct AdjInfo{
36         std::string intersection;
37 };
38
39 struct Intersection{
40         std::vector<AdjInfo> adjs;
41 };
42
43 struct Player{
44         std::string type;
45         std::string location;
46 };
47
48 struct Bank{
49         std::string location;
50         int value;
51 };
52
53 std::vector<std::string> tokenizeString(std::string input);
54
55 class Bot {
56         public:
57                 Bot(std::string name, std::string type);
58
59                 void play();
60                 void buildGraph();
61                 void updateWorld();
62                 virtual void turn() = 0;
63
64         private:
65         __gnu_cxx::hash_map<std::string, Intersection> _intersections;
66         __gnu_cxx::hash_map<std::string, Player> _players;
67         std::string _name;
68         std::string _type;
69         std::string _position;
70 };
71
72
73 #endif