Author: boucman
Date: Mon Apr 13 16:46:34 2009
New Revision: 34868

URL: http://svn.gna.org/viewcvs/wesnoth?rev=34868&view=rev
Log:
new type of candidate move: strategic, only called once with no parameter. Also 
initialize name_ and type_ correctly

Modified:
    trunk/src/formula_candidates.cpp
    trunk/src/formula_candidates.hpp

Modified: trunk/src/formula_candidates.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/formula_candidates.cpp?rev=34868&r1=34867&r2=34868&view=diff
==============================================================================
--- trunk/src/formula_candidates.cpp (original)
+++ trunk/src/formula_candidates.cpp Mon Apr 13 16:46:34 2009
@@ -39,11 +39,13 @@
                        candidate_action_ptr new_ca;
 
                        if( type == "movement") {
-                               new_ca = candidate_action_ptr(new 
move_candidate_action(rc_action, function_table ));
+                               new_ca = candidate_action_ptr(new 
move_candidate_action(name, type, rc_action, function_table ));
                        } else if( type == "attack") {
-                               new_ca = candidate_action_ptr(new 
attack_candidate_action(rc_action, function_table ));
+                               new_ca = candidate_action_ptr(new 
attack_candidate_action(name, type, rc_action, function_table ));
                        } else if( type == "support") {
-                               new_ca = candidate_action_ptr(new 
support_candidate_action(rc_action, function_table ));
+                               new_ca = candidate_action_ptr(new 
support_candidate_action(name, type, rc_action, function_table ));
+                       } else if( type == "strategic") {
+                               new_ca = candidate_action_ptr(new 
strategic_candidate_action(name, type, rc_action, function_table ));
                        } else {
                                ERR_AI << "Unknown candidate action type: " << 
type << "\n";
                                continue;
@@ -76,7 +78,9 @@
        return true;
 }
 
-base_candidate_action::base_candidate_action(const config& cfg, 
function_symbol_table* function_table) :
+base_candidate_action::base_candidate_action(const std::string& name,const 
std::string& type,const config& cfg, function_symbol_table* function_table) :
+       name_(name),
+       type_(type),
        eval_(new game_logic::formula(cfg["evaluation"], function_table)),
        action_(new game_logic::formula(cfg["action"], function_table))
 {}
@@ -98,8 +102,8 @@
        return res;
 }
 
-candidate_action_with_filters::candidate_action_with_filters(const config& 
cfg, function_symbol_table* function_table) :
-       base_candidate_action(cfg, function_table)
+candidate_action_with_filters::candidate_action_with_filters(const 
std::string& name, const std::string& type,const config& cfg, 
function_symbol_table* function_table) :
+       base_candidate_action(name, type, cfg, function_table)
 {
        const config & filter_params = cfg.child("filter");
 
@@ -114,8 +118,8 @@
        }       
 }
 
-move_candidate_action::move_candidate_action(const config& cfg, 
function_symbol_table* function_table) :
-       candidate_action_with_filters(cfg, function_table)
+move_candidate_action::move_candidate_action(const std::string& name, const 
std::string& type,const config& cfg, function_symbol_table* function_table) :
+       candidate_action_with_filters(name, type, cfg, function_table)
 {}
 
 void move_candidate_action::evaluate(formula_ai* ai, unit_map& units)
@@ -154,8 +158,8 @@
        callable.add("me", my_unit_callable);
 }
 
-attack_candidate_action::attack_candidate_action(const config& cfg, 
function_symbol_table* function_table) :
-       candidate_action_with_filters(cfg, function_table)
+attack_candidate_action::attack_candidate_action(const std::string& name, 
const std::string& type,const config& cfg, function_symbol_table* 
function_table) :
+       candidate_action_with_filters(name, type, cfg, function_table)
 {}
 
 void attack_candidate_action::evaluate(formula_ai* ai, unit_map& units)
@@ -229,8 +233,33 @@
        callable.add("target", enemy_unit_callable);
 }
 
-support_candidate_action::support_candidate_action(const config& cfg, 
function_symbol_table* function_table) :
-       candidate_action_with_filters(cfg, function_table)
-{}
-
-}
+strategic_candidate_action::strategic_candidate_action(const std::string& 
name, const std::string& type,const config& cfg, function_symbol_table* 
function_table) :
+       base_candidate_action(name, type, cfg, function_table)
+{}
+
+void strategic_candidate_action::evaluate(formula_ai* ai, unit_map& units)
+{
+       score_ = 0;
+
+
+       for(unit_map::unit_iterator i = units.begin() ; i != units.end() ; ++i)
+       {
+               if( (i->second.side() == ai->get_side() ) &&
+                               (i->second.has_moved() == false) ) {
+
+                       game_logic::map_formula_callable 
callable(static_cast<const formula_callable*>(ai));
+                       callable.add_ref();
+                       int res = execute_formula(eval_, callable, ai);
+
+                       if(res > score_) {
+                               score_ = res;
+                       }
+               }
+       }
+}
+
+support_candidate_action::support_candidate_action(const std::string& name, 
const std::string& type,const config& cfg, function_symbol_table* 
function_table) :
+       candidate_action_with_filters(name, type, cfg, function_table)
+{}
+
+}

Modified: trunk/src/formula_candidates.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/formula_candidates.hpp?rev=34868&r1=34867&r2=34868&view=diff
==============================================================================
--- trunk/src/formula_candidates.hpp (original)
+++ trunk/src/formula_candidates.hpp Mon Apr 13 16:46:34 2009
@@ -30,7 +30,7 @@
 //and should complete evaluate and update_callable_map methods
 class base_candidate_action {
 public:
-       base_candidate_action(const config& cfg, function_symbol_table* 
function_table);
+       base_candidate_action(const std::string& name, const std::string& 
type,const config& cfg, function_symbol_table* function_table);
 
        virtual ~base_candidate_action() {}
 
@@ -45,6 +45,9 @@
        int get_score() const {return score_;}
        
        const_formula_ptr& get_action() {return action_;}
+
+       const std::string& get_name() { return name_;}
+       const std::string& get_type() { return type_;}
        
 protected:
        int execute_formula(const const_formula_ptr& formula, 
@@ -110,7 +113,7 @@
 
 class candidate_action_with_filters : public base_candidate_action {
 public:
-       candidate_action_with_filters(const config& cfg, function_symbol_table* 
function_table);
+       candidate_action_with_filters(const std::string& name, const 
std::string& type,const config& cfg, function_symbol_table* function_table);
 protected:
 
        game_logic::candidate_action_filters filter_map_;
@@ -118,7 +121,7 @@
 
 class move_candidate_action : public candidate_action_with_filters {
 public:
-       move_candidate_action(const config& cfg, function_symbol_table* 
function_table);
+       move_candidate_action(const std::string& name, const std::string& 
type,const config& cfg, function_symbol_table* function_table);
 
        virtual void evaluate(formula_ai* ai, unit_map& units);
 
@@ -130,7 +133,7 @@
 
 class attack_candidate_action : public candidate_action_with_filters {
 public:
-       attack_candidate_action(const config& cfg, function_symbol_table* 
function_table);
+       attack_candidate_action(const std::string& name, const std::string& 
type,const config& cfg, function_symbol_table* function_table);
 
        virtual void evaluate(formula_ai* ai, unit_map& units);
 
@@ -140,11 +143,16 @@
        unit_map::const_unit_iterator enemy_unit_;
 };
 
+class strategic_candidate_action : public base_candidate_action {
+public:
+       strategic_candidate_action(const std::string& name, const std::string& 
type,const config& cfg, function_symbol_table* function_table);
+       virtual void evaluate(formula_ai* ai, unit_map& units);
+};
+
 class support_candidate_action : public candidate_action_with_filters {
 public:
-       support_candidate_action(const config& cfg, function_symbol_table* 
function_table);
+       support_candidate_action(const std::string& name, const std::string& 
type,const config& cfg, function_symbol_table* function_table);
 };
-
 }
 
 #endif /* _FORMULA_CANDIDATES_HPP */


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to