Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef AI_INTERFACE_HPP_INCLUDED
00022 #define AI_INTERFACE_HPP_INCLUDED
00023
00024 #include "../savegame_config.hpp"
00025 #include "default/contexts.hpp"
00026
00027 namespace ai {
00028
00029 class interface : savegame::savegame_config {
00030 public:
00031
00032
00033
00034 interface()
00035 : savegame_config()
00036 {
00037 }
00038
00039
00040 virtual ~interface() {}
00041
00042
00043
00044
00045
00046
00047 virtual void play_turn() = 0;
00048
00049
00050
00051
00052 virtual void new_turn() = 0;
00053
00054
00055
00056
00057
00058 virtual void on_create() {
00059 }
00060
00061 virtual void switch_side(ai::side_number side) = 0;
00062
00063
00064 virtual std::string evaluate(const std::string& )
00065 { return "evaluate command not implemented by this AI"; }
00066
00067
00068 virtual std::string describe_self() const;
00069
00070
00071
00072 virtual config to_config() const = 0;
00073 };
00074
00075 class ai_factory;
00076
00077 class ai_factory{
00078 public:
00079 typedef boost::shared_ptr< ai_factory > factory_ptr;
00080 typedef std::map<std::string, factory_ptr> factory_map;
00081 typedef std::pair<const std::string, factory_ptr> factory_map_pair;
00082
00083 static factory_map& get_list() {
00084 static factory_map *ai_factories;
00085 if (ai_factories==NULL) {
00086 ai_factories = new factory_map;
00087 }
00088 return *ai_factories;
00089 }
00090
00091 virtual ai_ptr get_new_instance( ai_context &context, const config &cfg) = 0;
00092
00093 ai_factory( const std::string &name )
00094 {
00095 factory_ptr ptr_to_this(this);
00096 get_list().insert(make_pair(name,ptr_to_this));
00097 }
00098
00099 virtual ~ai_factory() {}
00100 };
00101
00102
00103 template<class AI>
00104 class register_ai_factory : public ai_factory {
00105 public:
00106 register_ai_factory( const std::string &name )
00107 : ai_factory( name )
00108 {
00109 }
00110
00111 virtual ai_ptr get_new_instance( ai_context &context, const config &cfg){
00112 ai_ptr a(new AI(context,cfg));
00113 a->on_create();
00114 return a;
00115 }
00116 };
00117
00118
00119
00120 }
00121
00122 #endif