Author: crab
Date: Sun Jun 28 16:45:55 2009
New Revision: 36441
URL: http://svn.gna.org/viewcvs/wesnoth?rev=36441&view=rev
Log:
ai_composite: new candidate action:
testing_ai_default::simple_move_and_targeting_phase plus bugfixes
Modified:
trunk/data/ai/dev/testing_ai_default.cfg
trunk/src/ai/actions.cpp
trunk/src/ai/actions.hpp
trunk/src/ai/registry.cpp
trunk/src/ai/testing/ca.cpp
trunk/src/ai/testing/ca.hpp
Modified: trunk/data/ai/dev/testing_ai_default.cfg
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/data/ai/dev/testing_ai_default.cfg?rev=36441&r1=36440&r2=36441&view=diff
==============================================================================
--- trunk/data/ai/dev/testing_ai_default.cfg (original)
+++ trunk/data/ai/dev/testing_ai_default.cfg Sun Jun 28 16:45:55 2009
@@ -35,7 +35,7 @@
[/candidate_action]
[candidate_action]
engine=cpp
- name=testing_ai_default::move_and_targeting_phase
+ name=testing_ai_default::simple_move_and_targeting_phase
[/candidate_action]
[candidate_action]
engine=cpp
Modified: trunk/src/ai/actions.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/ai/actions.cpp?rev=36441&r1=36440&r2=36441&view=diff
==============================================================================
--- trunk/src/ai/actions.cpp (original)
+++ trunk/src/ai/actions.cpp Sun Jun 28 16:45:55 2009
@@ -430,6 +430,7 @@
/*bool is_replay*/ false);
unit_location_ = to_;//@todo: 1.7 modify move_unit to get this info
from it
set_gamestate_changed();
+ manager::raise_unit_moved();
}
Modified: trunk/src/ai/actions.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/ai/actions.hpp?rev=36441&r1=36440&r2=36441&view=diff
==============================================================================
--- trunk/src/ai/actions.hpp (original)
+++ trunk/src/ai/actions.hpp Sun Jun 28 16:45:55 2009
@@ -176,8 +176,8 @@
private:
const unit *get_unit(const unit_map &units, const std::vector<team>
&teams, bool update_knowledge = false);
bool test_route(const unit &un, const team &my_team, const unit_map
&units, const std::vector<team> &teams, const gamemap &map, bool
update_knowledge = false);
- const map_location& from_;
- const map_location& to_;
+ const map_location from_;
+ const map_location to_;
bool remove_movement_;
plain_route route_;
map_location unit_location_;
Modified: trunk/src/ai/registry.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/ai/registry.cpp?rev=36441&r1=36440&r2=36441&view=diff
==============================================================================
--- trunk/src/ai/registry.cpp (original)
+++ trunk/src/ai/registry.cpp Sun Jun 28 16:45:55 2009
@@ -86,8 +86,8 @@
static
composite_ai::register_candidate_action_factory<testing_ai_default::retreat_phase>
retreat_phase_factory("testing_ai_default::retreat_phase");
-static
composite_ai::register_candidate_action_factory<testing_ai_default::move_and_targeting_phase>
-
move_and_targeting_phase_factory("testing_ai_default::move_and_targeting_phase");
+static
composite_ai::register_candidate_action_factory<testing_ai_default::simple_move_and_targeting_phase>
+
simple_move_and_targeting_phase_factory("testing_ai_default::simple_move_and_targeting_phase");
static
composite_ai::register_candidate_action_factory<testing_ai_default::leader_control_phase>
leader_control_phase_factory("testing_ai_default::leader_control_phase");
Modified: trunk/src/ai/testing/ca.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/ai/testing/ca.cpp?rev=36441&r1=36440&r2=36441&view=diff
==============================================================================
--- trunk/src/ai/testing/ca.cpp (original)
+++ trunk/src/ai/testing/ca.cpp Sun Jun 28 16:45:55 2009
@@ -732,7 +732,11 @@
{
bool gamestate_changed = false;
move_->execute();
- gamestate_changed |= move_->is_ok();
+ recalculate_move_maps();//@todo 1.7: replace with event observers
+ if (!move_->is_ok()){
+ LOG_AI_TESTING_AI_DEFAULT << get_name() <<"::execute not ok"
<< std::endl;
+ }
+ gamestate_changed |= move_->is_gamestate_changed();
return gamestate_changed;
}
@@ -1661,22 +1665,86 @@
//==============================================================
-move_and_targeting_phase::move_and_targeting_phase( rca_context &context,
const config &cfg )
- :
candidate_action(context,"testing_ai_default::move_and_targeting_phase",cfg["type"])
-{
-}
-
-move_and_targeting_phase::~move_and_targeting_phase()
-{
-}
-
-double move_and_targeting_phase::evaluate()
+simple_move_and_targeting_phase::simple_move_and_targeting_phase( rca_context
&context, const config &cfg )
+ :
candidate_action(context,"testing_ai_default::simple_move_and_targeting_phase",cfg["type"])
+{
+}
+
+simple_move_and_targeting_phase::~simple_move_and_targeting_phase()
+{
+}
+
+double simple_move_and_targeting_phase::evaluate()
+{
+ unit_map &units_ = get_info().units;
+
+ unit_map::const_iterator leader;
+ map_location my_leader_loc = units_.find_leader(get_side())->first;
+
+ for(leader = units_.begin(); leader != units_.end(); ++leader) {
+ if(leader->second.can_recruit() &&
current_team().is_enemy(leader->second.side())) {
+ break;
+ }
+ }
+
+ if(leader == units_.end()) {
+ return BAD_SCORE;
+ }
+
+ int closest_distance = -1;
+ std::pair<map_location,map_location> closest_move;
+
+ for(move_map::const_iterator i = get_dstsrc().begin(); i !=
get_dstsrc().end(); ++i) {
+ const int distance = distance_between(i->first,leader->first);
+ if(closest_distance == -1 || distance < closest_distance) {
+ if ((i->second!=my_leader_loc) &&
(i->second!=i->first)) {
+ closest_distance = distance;
+ closest_move = *i;
+ }
+ }
+ }
+
+ if(closest_distance != -1) {
+ move_ =
check_move_action(closest_move.second,closest_move.first,true);
+ if (move_->is_ok()){
+ return 15;
+ }
+ }
+
+ return BAD_SCORE;
+}
+
+bool simple_move_and_targeting_phase::execute()
+{
+ bool gamestate_changed = false;
+ move_->execute();
+ recalculate_move_maps();//@todo 1.7: replace with event observers
+ if (!move_->is_ok()){
+ LOG_AI_TESTING_AI_DEFAULT << get_name() << "::execute not ok"
<< std::endl;
+ }
+ gamestate_changed |= move_->is_gamestate_changed();
+ return gamestate_changed;
+}
+
+
+//==============================================================
+
+leader_control_phase::leader_control_phase( rca_context &context, const config
&cfg )
+ :
candidate_action(context,"testing_ai_default::leader_control_phase",cfg["type"])
+{
+}
+
+leader_control_phase::~leader_control_phase()
+{
+}
+
+double leader_control_phase::evaluate()
{
ERR_AI_TESTING_AI_DEFAULT << get_name() << ": evaluate - not yet
implemented!" << std::endl;
return BAD_SCORE;
}
-bool move_and_targeting_phase::execute()
+bool leader_control_phase::execute()
{
ERR_AI_TESTING_AI_DEFAULT << get_name() << ": execute - not yet
implemented!" << std::endl;
return true;
@@ -1684,29 +1752,6 @@
//==============================================================
-leader_control_phase::leader_control_phase( rca_context &context, const config
&cfg )
- :
candidate_action(context,"testing_ai_default::leader_control_phase",cfg["type"])
-{
-}
-
-leader_control_phase::~leader_control_phase()
-{
-}
-
-double leader_control_phase::evaluate()
-{
- ERR_AI_TESTING_AI_DEFAULT << get_name() << ": evaluate - not yet
implemented!" << std::endl;
- return BAD_SCORE;
-}
-
-bool leader_control_phase::execute()
-{
- ERR_AI_TESTING_AI_DEFAULT << get_name() << ": execute - not yet
implemented!" << std::endl;
- return true;
-}
-
-//==============================================================
-
} //end of namespace testing_ai_default
} //end of namespace ai
Modified: trunk/src/ai/testing/ca.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/ai/testing/ca.hpp?rev=36441&r1=36440&r2=36441&view=diff
==============================================================================
--- trunk/src/ai/testing/ca.hpp (original)
+++ trunk/src/ai/testing/ca.hpp Sun Jun 28 16:45:55 2009
@@ -288,17 +288,20 @@
//============================================================================
-class move_and_targeting_phase : public candidate_action {
-public:
-
- move_and_targeting_phase( rca_context &context, const config &cfg );
-
- virtual ~move_and_targeting_phase();
-
- virtual double evaluate();
-
- virtual bool execute();
-
+class simple_move_and_targeting_phase : public candidate_action {
+public:
+
+ simple_move_and_targeting_phase( rca_context &context, const config
&cfg );
+
+ virtual ~simple_move_and_targeting_phase();
+
+ virtual double evaluate();
+
+ virtual bool execute();
+
+private:
+
+ move_result_ptr move_;
};
//============================================================================
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits