mail[Wesnoth-commits] r36504 - in /trunk/src/ai: composite/engine_fai.cpp formula/ai.cpp formula/ai.hpp


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by terraninfo on July 01, 2009 - 23:47:
Author: crab
Date: Wed Jul  1 23:47:29 2009
New Revision: 36504

URL: http://svn.gna.org/viewcvs/wesnoth?rev=36504&view=rev
Log:
ai_composite: engine_fai: added wrapper of fai candidate actions to standard 
ai_composite interface

Modified:
    trunk/src/ai/composite/engine_fai.cpp
    trunk/src/ai/formula/ai.cpp
    trunk/src/ai/formula/ai.hpp

Modified: trunk/src/ai/composite/engine_fai.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/ai/composite/engine_fai.cpp?rev=36504&r1=36503&r2=36504&view=diff
==============================================================================
--- trunk/src/ai/composite/engine_fai.cpp (original)
+++ trunk/src/ai/composite/engine_fai.cpp Wed Jul  1 23:47:29 2009
@@ -32,9 +32,38 @@
 #define LOG_AI_COMPOSITE_ENGINE_FAI LOG_STREAM(info, 
log_ai_composite_engine_fai)
 #define ERR_AI_COMPOSITE_ENGINE_FAI LOG_STREAM(err, 
log_ai_composite_engine_fai)
 
+class fai_candidate_action_wrapper : public candidate_action {
+public:
+       fai_candidate_action_wrapper( rca_context &context, const config 
&/*cfg*/, game_logic::candidate_action_ptr fai_ca, formula_ai &_formula_ai )
+               : 
candidate_action(context,fai_ca->get_name(),fai_ca->get_type()),fai_ca_(fai_ca),formula_ai_(_formula_ai)
+       {
+       }
+
+
+       virtual ~fai_candidate_action_wrapper() {}
+
+
+       virtual double evaluate()
+       {
+               formula_ai_.evaluate_candidate_action(fai_ca_);
+               return fai_ca_->get_score();
+       }
+
+
+       virtual bool execute()
+       {
+               return formula_ai_.execute_candidate_action(fai_ca_);
+       }
+private:
+       game_logic::candidate_action_ptr fai_ca_;
+       formula_ai &formula_ai_;
+};
+
+
 engine_fai::engine_fai( composite_ai_context &context, const config &cfg )
        : engine(context,cfg), formula_ai_(context)
 {
+
 }
 
 
@@ -45,8 +74,12 @@
 
 void engine_fai::do_parse_candidate_action_from_config( rca_context 
&context, const config &cfg, std::back_insert_iterator<std::vector< 
candidate_action_ptr > > b ){
        game_logic::candidate_action_ptr fai_ca = 
formula_ai_.load_candidate_action_from_config(cfg);
-       //candidate_action_ptr ca = wrap(context,fai_ca);
-       //*b = ca;
+       if (!fai_ca) {
+               ERR_AI_COMPOSITE_ENGINE_FAI << "side "<<ai_.get_side()<< " : 
ERROR creating candidate_action["<<cfg["name"]<<"]"<< std::endl;
+               DBG_AI_COMPOSITE_ENGINE_FAI << "config snippet contains: " << 
std::endl << cfg << std::endl;
+       }
+       candidate_action_ptr ca = 
candidate_action_ptr(&fai_candidate_action_wrapper(context,cfg,fai_ca,formula_ai_));
+       *b = ca;
 
 }
 

Modified: trunk/src/ai/formula/ai.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/ai/formula/ai.cpp?rev=36504&r1=36503&r2=36504&view=diff
==============================================================================
--- trunk/src/ai/formula/ai.cpp (original)
+++ trunk/src/ai/formula/ai.cpp Wed Jul  1 23:47:29 2009
@@ -2614,3 +2614,19 @@
         }
 
 }
+
+void formula_ai::evaluate_candidate_action(game_logic::candidate_action_ptr 
fai_ca)
+{
+       fai_ca->evaluate(this,get_info().units);
+
+}
+
+bool formula_ai::execute_candidate_action(game_logic::candidate_action_ptr 
fai_ca)
+{
+       move_maps_valid_ = false;//@todo 1.7 think about optimizing this
+       game_logic::map_formula_callable callable(this);
+       callable.add_ref();
+       fai_ca->update_callable_map( callable );
+       const_formula_ptr move_formula(fai_ca->get_action());
+       return make_action(move_formula, callable);
+}

Modified: trunk/src/ai/formula/ai.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/ai/formula/ai.hpp?rev=36504&r1=36503&r2=36504&view=diff
==============================================================================
--- trunk/src/ai/formula/ai.hpp (original)
+++ trunk/src/ai/formula/ai.hpp Wed Jul  1 23:47:29 2009
@@ -137,6 +137,16 @@
 
        game_logic::candidate_action_ptr 
load_candidate_action_from_config(const config& cfg);
 
+       /** Evaluate the fai candidate action */
+       void evaluate_candidate_action(game_logic::candidate_action_ptr 
fai_ca);
+
+       /**
+        * Execute the fai candidate action
+        * @return true if game state was changed
+        * @return false if game state was changed
+        */
+       bool execute_candidate_action(game_logic::candidate_action_ptr 
fai_ca);
+
 private:
        ai::recursion_counter recursion_counter_;
        void display_message(const std::string& msg) const;




Related Messages


Powered by MHonArc, Updated Thu Jul 02 00:00:07 2009