Author: dragonking
Date: Mon Apr 13 12:02:56 2009
New Revision: 34845
URL: http://svn.gna.org/viewcvs/wesnoth?rev=34845&view=rev
Log:
Renamed formula_ai::make_move to make_action, and candidate_move to
candidate_action
Modified:
trunk/src/formula_ai.cpp
trunk/src/formula_ai.hpp
trunk/src/formula_candidates.cpp
trunk/src/formula_candidates.hpp
Modified: trunk/src/formula_ai.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/formula_ai.cpp?rev=34845&r1=34844&r2=34845&view=diff
==============================================================================
--- trunk/src/formula_ai.cpp (original)
+++ trunk/src/formula_ai.cpp Mon Apr 13 12:02:56 2009
@@ -1580,14 +1580,14 @@
keeps_cache_(),
vars_(),
function_table(*this),
- candidate_move_manager_()
+ candidate_action_manager_()
{
//make sure we don't run out of refcount
vars_.add_ref();
const config& ai_param = current_team().ai_parameters();
- // load candidate moves from config
- candidate_move_manager_.load_config(ai_param, this, &function_table);
+ // load candidate actions from config
+ candidate_action_manager_.load_config(ai_param, this, &function_table);
foreach (const config &func, ai_param.child_range("function"))
{
@@ -1717,7 +1717,7 @@
game_logic::map_formula_callable callable(this);
callable.add_ref();
callable.add("me", variant(new unit_callable(*i)));
- make_move(formula, callable);
+ make_action(formula, callable);
}
catch(formula_error& e) {
if(e.filename == "formula")
@@ -1735,7 +1735,7 @@
game_logic::map_formula_callable
callable(this);
callable.add_ref();
callable.add("me", variant(new
unit_callable(*i)));
- while ( make_move(loop_formula, callable) &&
i.valid() ) {}
+ while ( make_action(loop_formula, callable) &&
i.valid() ) {}
}
catch(formula_error& e) {
if(e.filename == "formula")
@@ -1746,18 +1746,18 @@
}
}
- if( candidate_move_manager_.has_candidate_moves() ) {
+ if( candidate_action_manager_.has_candidate_actions() ) {
move_maps_valid_ = false;
- while( candidate_move_manager_.evaluate_candidate_moves(this,
units_) )
+ while(
candidate_action_manager_.evaluate_candidate_actions(this, units_) )
{
game_logic::map_formula_callable callable(this);
callable.add_ref();
- candidate_move_manager_.update_callable_map( callable );
-
- const_formula_ptr
move_formula(candidate_move_manager_.get_best_move_formula());
-
- make_move(move_formula, callable);
+ candidate_action_manager_.update_callable_map( callable
);
+
+ const_formula_ptr
move_formula(candidate_action_manager_.get_best_action_formula());
+
+ make_action(move_formula, callable);
move_maps_valid_ = false;
}
@@ -1765,7 +1765,7 @@
game_logic::map_formula_callable callable(this);
callable.add_ref();
- while(make_move(move_formula_,callable)) { }
+ while(make_action(move_formula_,callable)) { }
}
@@ -1842,7 +1842,7 @@
move_maps_valid_ = true;
}
-bool formula_ai::make_move(game_logic::const_formula_ptr formula_, const
game_logic::formula_callable& variables)
+bool formula_ai::make_action(game_logic::const_formula_ptr formula_, const
game_logic::formula_callable& variables)
{
if(!formula_) {
if(get_master()) {
Modified: trunk/src/formula_ai.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/formula_ai.hpp?rev=34845&r1=34844&r2=34845&view=diff
==============================================================================
--- trunk/src/formula_ai.hpp (original)
+++ trunk/src/formula_ai.hpp Mon Apr 13 12:02:56 2009
@@ -127,7 +127,7 @@
private:
void display_message(const std::string& msg) const;
bool do_recruitment();
- bool make_move(game_logic::const_formula_ptr formula_, const
game_logic::formula_callable& variables);
+ bool make_action(game_logic::const_formula_ptr formula_, const
game_logic::formula_callable& variables);
bool execute_variant(const variant& var, bool commandline=false);
virtual variant get_value(const std::string& key) const;
virtual void get_inputs(std::vector<game_logic::formula_input>* inputs)
const;
@@ -148,7 +148,7 @@
game_logic::map_formula_callable vars_;
game_logic::ai_function_symbol_table function_table;
- game_logic::candidate_move_manager candidate_move_manager_;
+ game_logic::candidate_action_manager candidate_action_manager_;
friend class ai;
};
Modified: trunk/src/formula_candidates.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/formula_candidates.cpp?rev=34845&r1=34844&r2=34845&view=diff
==============================================================================
--- trunk/src/formula_candidates.cpp (original)
+++ trunk/src/formula_candidates.cpp Mon Apr 13 12:02:56 2009
@@ -13,7 +13,7 @@
/**
* @file formula_candidates.cpp
- * Defines formula ai candidate moves
+ * Defines formula ai candidate actions
* */
#include "formula_ai.hpp"
@@ -26,57 +26,62 @@
namespace game_logic {
-void candidate_move_manager::load_config(const config& cfg, formula_ai* ai,
function_symbol_table* function_table)
-{
- // register candidate moves
- foreach (const config &rc_move,
cfg.child_range("register_candidate_move"))
- {
- const t_string &name = rc_move["name"];
+void candidate_action_manager::load_config(const config& cfg, formula_ai* ai,
function_symbol_table* function_table)
+{
+ // register candidate actions
+ foreach (const config &rc_action,
cfg.child_range("register_candidate_action"))
+ {
+ const t_string &name = rc_action["name"];
try{
- const t_string &type = rc_move["type"];
-
- candidate_move_ptr new_cm;
+ const t_string &type = rc_action["type"];
+
+ candidate_action_ptr new_ca;
if( type == "movement") {
- new_cm = candidate_move_ptr(new
move_candidate_move(rc_move, function_table ));
+ new_ca = candidate_action_ptr(new
move_candidate_action(rc_action, function_table ));
} else if( type == "attack") {
- new_cm = candidate_move_ptr(new
attack_candidate_move(rc_move, function_table ));
- } else
+ new_ca = candidate_action_ptr(new
attack_candidate_action(rc_action, function_table ));
+ } else if( type == "support") {
+ new_ca = candidate_action_ptr(new
support_candidate_action(rc_action, function_table ));
+ } else {
+ ERR_AI << "Unknown candidate action type: " <<
type << "\n";
continue;
-
- candidate_moves_.push_back(new_cm);
+ }
+
+
+ candidate_actions_.push_back(new_ca);
}
catch(formula_error& e) {
- ai->handle_exception(e, "Error while registering
candidate move '" + name + "'");
- }
- }
-}
-
-bool candidate_move_manager::evaluate_candidate_moves(formula_ai* ai,
unit_map& units)
-{
- evaluated_candidate_moves_.clear();
-
- foreach(candidate_move_ptr cm, candidate_moves_)
+ ai->handle_exception(e, "Error while registering
candidate action '" + name + "'");
+ }
+ }
+}
+
+bool candidate_action_manager::evaluate_candidate_actions(formula_ai* ai,
unit_map& units)
+{
+ evaluated_candidate_actions_.clear();
+
+ foreach(candidate_action_ptr cm, candidate_actions_)
{
cm->evaluate(ai, units);
- evaluated_candidate_moves_.insert(cm);
- }
-
- if( evaluated_candidate_moves_.empty() ||
- (*evaluated_candidate_moves_.begin())->get_score() < 1 )
+ evaluated_candidate_actions_.insert(cm);
+ }
+
+ if( evaluated_candidate_actions_.empty() ||
+ (*evaluated_candidate_actions_.begin())->get_score() < 1 )
return false;
return true;
}
-base_candidate_move::base_candidate_move(const config& cfg,
function_symbol_table* function_table) :
+base_candidate_action::base_candidate_action(const config& cfg,
function_symbol_table* function_table) :
eval_(new game_logic::formula(cfg["evaluation"], function_table)),
action_(new game_logic::formula(cfg["action"], function_table))
{}
-int base_candidate_move::execute_formula(const const_formula_ptr& formula,
+int base_candidate_action::execute_formula(const const_formula_ptr& formula,
const game_logic::formula_callable& callable, const
formula_ai* ai)
{
int res = 0;
@@ -87,14 +92,14 @@
res = 0;
} catch(type_error& e) {
res = 0;
- ERR_AI << "formula type error while evaluating candidate move:
" << e.message << "\n";
+ ERR_AI << "formula type error while evaluating candidate
action: " << e.message << "\n";
}
return res;
}
-candidate_move_with_filters::candidate_move_with_filters(const config& cfg,
function_symbol_table* function_table) :
- base_candidate_move(cfg, function_table)
+candidate_action_with_filters::candidate_action_with_filters(const config&
cfg, function_symbol_table* function_table) :
+ base_candidate_action(cfg, function_table)
{
const config & filter_params = cfg.child("filter");
@@ -109,15 +114,15 @@
}
}
-move_candidate_move::move_candidate_move(const config& cfg,
function_symbol_table* function_table) :
- candidate_move_with_filters(cfg, function_table)
-{}
-
-void move_candidate_move::evaluate(formula_ai* ai, unit_map& units)
+move_candidate_action::move_candidate_action(const config& cfg,
function_symbol_table* function_table) :
+ candidate_action_with_filters(cfg, function_table)
+{}
+
+void move_candidate_action::evaluate(formula_ai* ai, unit_map& units)
{
score_ = 0;
- candidate_move_filters::const_iterator me_filter =
filter_map_.find("me");
+ candidate_action_filters::const_iterator me_filter =
filter_map_.find("me");
for(unit_map::unit_iterator i = units.begin() ; i != units.end() ; ++i)
{
@@ -143,23 +148,23 @@
}
}
-void
move_candidate_move::update_callable_map(game_logic::map_formula_callable&
callable)
+void
move_candidate_action::update_callable_map(game_logic::map_formula_callable&
callable)
{
variant my_unit_callable(new unit_callable( *my_unit_ ));
callable.add("me", my_unit_callable);
}
-attack_candidate_move::attack_candidate_move(const config& cfg,
function_symbol_table* function_table) :
- candidate_move_with_filters(cfg, function_table)
-{}
-
-void attack_candidate_move::evaluate(formula_ai* ai, unit_map& units)
+attack_candidate_action::attack_candidate_action(const config& cfg,
function_symbol_table* function_table) :
+ candidate_action_with_filters(cfg, function_table)
+{}
+
+void attack_candidate_action::evaluate(formula_ai* ai, unit_map& units)
{
std::vector< unit_map::const_unit_iterator > my_units;
std::vector< unit_map::const_unit_iterator > enemy_units;
- candidate_move_filters::const_iterator me_filter =
filter_map_.find("me");
- candidate_move_filters::const_iterator target_filter =
filter_map_.find("target");
+ candidate_action_filters::const_iterator me_filter =
filter_map_.find("me");
+ candidate_action_filters::const_iterator target_filter =
filter_map_.find("target");
for(unit_map::unit_iterator unit = units.begin() ; unit != units.end()
; ++unit)
{
@@ -216,7 +221,7 @@
}
}
-void
attack_candidate_move::update_callable_map(game_logic::map_formula_callable&
callable)
+void
attack_candidate_action::update_callable_map(game_logic::map_formula_callable&
callable)
{
variant my_unit_callable(new unit_callable( *my_unit_ ));
callable.add("me", my_unit_callable);
@@ -224,10 +229,8 @@
callable.add("target", enemy_unit_callable);
}
-support_candidate_move::support_candidate_move(const config& cfg,
function_symbol_table* function_table) :
- candidate_move_with_filters(cfg, function_table)
-{}
-
-
-
-}
+support_candidate_action::support_candidate_action(const config& cfg,
function_symbol_table* function_table) :
+ candidate_action_with_filters(cfg, function_table)
+{}
+
+}
Modified: trunk/src/formula_candidates.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/formula_candidates.hpp?rev=34845&r1=34844&r2=34845&view=diff
==============================================================================
--- trunk/src/formula_candidates.hpp (original)
+++ trunk/src/formula_candidates.hpp Mon Apr 13 12:02:56 2009
@@ -13,7 +13,7 @@
/**
* @file formula_candidates.hpp
- * Defines formula ai candidate moves - headers
+ * Defines formula ai candidate actions - headers
* */
#ifndef _FORMULA_CANDIDATES_HPP
@@ -21,20 +21,20 @@
namespace game_logic {
-class base_candidate_move;
+class base_candidate_action;
-typedef std::map< std::string, game_logic::const_formula_ptr >
candidate_move_filters;
-typedef boost::shared_ptr<game_logic::base_candidate_move> candidate_move_ptr;
+typedef std::map< std::string, game_logic::const_formula_ptr >
candidate_action_filters;
+typedef boost::shared_ptr<game_logic::base_candidate_action>
candidate_action_ptr;
-//every new candidate move type should be derived from this class
+//every new candidate action type should be derived from this class
//and should complete evaluate and update_callable_map methods
-class base_candidate_move {
+class base_candidate_action {
public:
- base_candidate_move(const config& cfg, function_symbol_table*
function_table);
+ base_candidate_action(const config& cfg, function_symbol_table*
function_table);
- virtual ~base_candidate_move() {}
+ virtual ~base_candidate_action() {}
- //evaluate candidate move using eval_ formula
+ //evaluate candidate action using eval_ formula
virtual void evaluate(formula_ai* /*ai*/, unit_map& /*units*/) {}
//adds needed callable objects to callable map
@@ -57,68 +57,68 @@
int score_;
};
-struct candidate_move_compare {
- bool operator() (const candidate_move_ptr lmove,
- const candidate_move_ptr rmove) const
+struct candidate_action_compare {
+ bool operator() (const candidate_action_ptr laction,
+ const candidate_action_ptr raction) const
{
- return lmove->get_score() > rmove->get_score();
+ return laction->get_score() > raction->get_score();
}
};
-typedef std::set<game_logic::candidate_move_ptr,
game_logic::candidate_move_compare> candidate_move_set;
+typedef std::set<game_logic::candidate_action_ptr,
game_logic::candidate_action_compare> candidate_action_set;
-//this class is responsible for managing candidate moves
-class candidate_move_manager {
+//this class is responsible for managing candidate actions
+class candidate_action_manager {
public:
- candidate_move_manager() {}
+ candidate_action_manager() {}
- //register candidate moves from config
+ //register candidate actions from config
void load_config(const config& cfg, formula_ai* ai,
function_symbol_table* function_table);
- //evaluate candidate moves, return true if we have candidate moves that
have score > 0
- bool evaluate_candidate_moves(formula_ai* ai, unit_map& units);
+ //evaluate candidate action, return true if we have candidate action
that have score > 0
+ bool evaluate_candidate_actions(formula_ai* ai, unit_map& units);
- const_formula_ptr get_best_move_formula() {
- if( evaluated_candidate_moves_.empty() )
+ const_formula_ptr get_best_action_formula() {
+ if( evaluated_candidate_actions_.empty() )
return game_logic::formula_ptr();
- return (*evaluated_candidate_moves_.begin())->get_action();
+ return (*evaluated_candidate_actions_.begin())->get_action();
}
- //calls same method from best candidate move
+ //calls same method from best candidate action
void update_callable_map(game_logic::map_formula_callable& callable){
- if( evaluated_candidate_moves_.empty() )
+ if( evaluated_candidate_actions_.empty() )
return;
-
(*evaluated_candidate_moves_.begin())->update_callable_map(callable);
+
(*evaluated_candidate_actions_.begin())->update_callable_map(callable);
}
- void register_candidate_move(candidate_move_ptr& candidate_move){
- candidate_moves_.push_back(candidate_move);
+ void register_candidate_action(candidate_action_ptr& candidate_action){
+ candidate_actions_.push_back(candidate_action);
}
- bool has_candidate_moves() { return !candidate_moves_.empty(); }
+ bool has_candidate_actions() { return !candidate_actions_.empty(); }
void clear() {
- candidate_moves_.clear();
- evaluated_candidate_moves_.clear();
+ candidate_actions_.clear();
+ evaluated_candidate_actions_.clear();
}
private:
- game_logic::candidate_move_set evaluated_candidate_moves_;
- std::vector<candidate_move_ptr> candidate_moves_;
+ game_logic::candidate_action_set evaluated_candidate_actions_;
+ std::vector<candidate_action_ptr> candidate_actions_;
};
-class candidate_move_with_filters : public base_candidate_move {
+class candidate_action_with_filters : public base_candidate_action {
public:
- candidate_move_with_filters(const config& cfg, function_symbol_table*
function_table);
+ candidate_action_with_filters(const config& cfg, function_symbol_table*
function_table);
protected:
- game_logic::candidate_move_filters filter_map_;
+ game_logic::candidate_action_filters filter_map_;
};
-class move_candidate_move : public candidate_move_with_filters {
+class move_candidate_action : public candidate_action_with_filters {
public:
- move_candidate_move(const config& cfg, function_symbol_table*
function_table);
+ move_candidate_action(const config& cfg, function_symbol_table*
function_table);
virtual void evaluate(formula_ai* ai, unit_map& units);
@@ -128,9 +128,9 @@
unit_map::unit_iterator my_unit_;
};
-class attack_candidate_move : public candidate_move_with_filters {
+class attack_candidate_action : public candidate_action_with_filters {
public:
- attack_candidate_move(const config& cfg, function_symbol_table*
function_table);
+ attack_candidate_action(const config& cfg, function_symbol_table*
function_table);
virtual void evaluate(formula_ai* ai, unit_map& units);
@@ -140,9 +140,9 @@
unit_map::const_unit_iterator enemy_unit_;
};
-class support_candidate_move : public candidate_move_with_filters {
+class support_candidate_action : public candidate_action_with_filters {
public:
- support_candidate_move(const config& cfg, function_symbol_table*
function_table);
+ support_candidate_action(const config& cfg, function_symbol_table*
function_table);
};
}
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits