ai_composite: new candidate action:

...testing_ai_default::simple_move_and_targeting_phase plus bugfixes
This commit is contained in:
Iurii Chernyi 2009-06-28 14:45:55 +00:00
parent 5652b111c0
commit 7ba34dee6c
6 changed files with 66 additions and 17 deletions

View file

@ -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

View file

@ -430,6 +430,7 @@ void move_result::do_execute()
/*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();
}

View file

@ -176,8 +176,8 @@ protected:
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_;

View file

@ -86,8 +86,8 @@ static composite_ai::register_candidate_action_factory<testing_ai_default::get_h
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");

View file

@ -732,7 +732,11 @@ bool move_leader_to_keep_phase::execute()
{
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,27 +1665,68 @@ bool retreat_phase::execute()
//==============================================================
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"])
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"])
{
}
move_and_targeting_phase::~move_and_targeting_phase()
simple_move_and_targeting_phase::~simple_move_and_targeting_phase()
{
}
double move_and_targeting_phase::evaluate()
double simple_move_and_targeting_phase::evaluate()
{
ERR_AI_TESTING_AI_DEFAULT << get_name() << ": evaluate - not yet implemented!" << std::endl;
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 move_and_targeting_phase::execute()
bool simple_move_and_targeting_phase::execute()
{
ERR_AI_TESTING_AI_DEFAULT << get_name() << ": execute - not yet implemented!" << std::endl;
return true;
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 )

View file

@ -288,17 +288,20 @@ public:
//============================================================================
class move_and_targeting_phase : public candidate_action {
class simple_move_and_targeting_phase : public candidate_action {
public:
move_and_targeting_phase( rca_context &context, const config &cfg );
simple_move_and_targeting_phase( rca_context &context, const config &cfg );
virtual ~move_and_targeting_phase();
virtual ~simple_move_and_targeting_phase();
virtual double evaluate();
virtual bool execute();
private:
move_result_ptr move_;
};
//============================================================================