00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef FORMULA_AI_HPP_INCLUDED
00016 #define FORMULA_AI_HPP_INCLUDED
00017
00018 #include "ai.hpp"
00019 #include "ai_interface.hpp"
00020 #include "formula_fwd.hpp"
00021 #include "formula_callable.hpp"
00022
00023 namespace game_logic {
00024 typedef std::map<const std::string, std::vector<const_formula_ptr> > candidate_move_map;
00025 }
00026
00027 class formula_ai : public ai {
00028 public:
00029 explicit formula_ai(info& i);
00030 virtual void play_turn();
00031
00032 using ai_interface::get_info;
00033 using ai_interface::current_team;
00034 using ai_interface::move_map;
00035
00036 const move_map& srcdst() const { if(!move_maps_valid_) { prepare_move(); } return srcdst_; }
00037
00038 std::string evaluate(const std::string& formula_str);
00039
00040 struct move_map_backup {
00041 move_map_backup() : move_maps_valid(false) {}
00042 bool move_maps_valid;
00043 move_map srcdst, dstsrc, full_srcdst, full_dstsrc, enemy_srcdst, enemy_dstsrc;
00044 variant attacks_cache;
00045 };
00046
00047 void swap_move_map(move_map_backup& backup);
00048
00049 variant get_keeps() const;
00050
00051 const variant& get_keeps_cache() const { return keeps_cache_; }
00052
00053 private:
00054 void do_recruitment();
00055 bool make_move(game_logic::const_formula_ptr formula_, const game_logic::formula_callable& variables);
00056 bool execute_variant(const variant& var, bool commandline=false);
00057 virtual variant get_value(const std::string& key) const;
00058 virtual void get_inputs(std::vector<game_logic::formula_input>* inputs) const;
00059 game_logic::const_formula_ptr recruit_formula_;
00060 game_logic::const_formula_ptr move_formula_;
00061
00062 mutable std::map<location,paths> possible_moves_;
00063
00064 void prepare_move() const;
00065 mutable bool move_maps_valid_;
00066 mutable move_map srcdst_, dstsrc_, full_srcdst_, full_dstsrc_, enemy_srcdst_, enemy_dstsrc_;
00067 mutable variant attacks_cache_;
00068 mutable variant keeps_cache_;
00069
00070 game_logic::map_formula_callable vars_;
00071 };
00072
00073 #endif