Skip to content

Commit

Permalink
Remove old move-to-targets CA and move new one to default
Browse files Browse the repository at this point in the history
  • Loading branch information
CelticMinstrel committed Mar 24, 2016
1 parent ab443bc commit af9be37
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 167 deletions.
14 changes: 4 additions & 10 deletions data/core/macros/ai_candidate_actions.cfg
Expand Up @@ -164,19 +164,13 @@
{AI_CA_LEADER_SHARES_KEEP}
#enddef

# extra candidate actions

# Keep for backward compatibility, but redirect it
#define AI_CA_SIMPLE_MOVE_TO_TARGETS
# Extra candidate action: simple_move_to_targets
[candidate_action]
id=simple_move_to_targets
engine=cpp
name=ai_default_rca::simple_move_and_targeting_phase
max_score={AI_CA_MOVE_TO_TARGETS_SCORE}
score={AI_CA_MOVE_TO_TARGETS_SCORE}
[/candidate_action]
{AI_CA_MOVE_TO_TARGETS}
#enddef

# extra candidate actions

#define AI_CA_POISONING
# Extra candidate action: Formula AI CA for poisoners to spread poison around
[candidate_action]
Expand Down
4 changes: 2 additions & 2 deletions projectfiles/CodeBlocks/wesnoth.cbp
Expand Up @@ -151,6 +151,8 @@
<Unit filename="../../src/ai/default/attack.cpp" />
<Unit filename="../../src/ai/default/ca.cpp" />
<Unit filename="../../src/ai/default/ca.hpp" />
<Unit filename="../../src/ai/default/ca_move_to_targets.cpp" />
<Unit filename="../../src/ai/default/ca_move_to_targets.hpp" />
<Unit filename="../../src/ai/default/contexts.cpp" />
<Unit filename="../../src/ai/default/contexts.hpp" />
<Unit filename="../../src/ai/default/engine_cpp.cpp" />
Expand Down Expand Up @@ -193,8 +195,6 @@
<Unit filename="../../src/ai/simulated_actions.hpp" />
<Unit filename="../../src/ai/testing.cpp" />
<Unit filename="../../src/ai/testing.hpp" />
<Unit filename="../../src/ai/testing/ca_testing_move_to_targets.cpp" />
<Unit filename="../../src/ai/testing/ca_testing_move_to_targets.hpp" />
<Unit filename="../../src/ai/testing/stage_sf_with_rca.cpp" />
<Unit filename="../../src/ai/testing/stage_sf_with_rca.hpp" />
<Unit filename="../../src/animated.hpp" />
Expand Down
40 changes: 20 additions & 20 deletions projectfiles/VC9/wesnoth.vcproj
Expand Up @@ -2008,7 +2008,7 @@
>
</File>
<File
RelativePath="..\..\src\ai\default\contexts.cpp"
RelativePath="..\..\src\ai\default\ca_move_to_targets.cpp"
>
<FileConfiguration
Name="Debug|Win32"
Expand Down Expand Up @@ -2060,11 +2060,11 @@
</FileConfiguration>
</File>
<File
RelativePath="..\..\src\ai\default\contexts.hpp"
RelativePath="..\..\src\ai\default\ca_move_to_targets.hpp"
>
</File>
<File
RelativePath="..\..\src\ai\default\engine_cpp.cpp"
RelativePath="..\..\src\ai\default\contexts.cpp"
>
<FileConfiguration
Name="Debug|Win32"
Expand Down Expand Up @@ -2116,11 +2116,11 @@
</FileConfiguration>
</File>
<File
RelativePath="..\..\src\ai\default\engine_cpp.hpp"
RelativePath="..\..\src\ai\default\contexts.hpp"
>
</File>
<File
RelativePath="..\..\src\ai\default\recruitment.cpp"
RelativePath="..\..\src\ai\default\engine_cpp.cpp"
>
<FileConfiguration
Name="Debug|Win32"
Expand Down Expand Up @@ -2172,11 +2172,11 @@
</FileConfiguration>
</File>
<File
RelativePath="..\..\src\ai\default\recruitment.hpp"
RelativePath="..\..\src\ai\default\engine_cpp.hpp"
>
</File>
<File
RelativePath="..\..\src\ai\default\stage_rca.cpp"
RelativePath="..\..\src\ai\default\recruitment.cpp"
>
<FileConfiguration
Name="Debug|Win32"
Expand Down Expand Up @@ -2228,69 +2228,69 @@
</FileConfiguration>
</File>
<File
RelativePath="..\..\src\ai\default\stage_rca.hpp"
RelativePath="..\..\src\ai\default\recruitment.hpp"
>
</File>
</Filter>
<Filter
Name="testing"
>
<File
RelativePath="..\..\src\ai\testing\ca_testing_move_to_targets.cpp"
RelativePath="..\..\src\ai\default\stage_rca.cpp"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)\ai\testing\"
ObjectFile="$(IntDir)\ai\default\"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)\ai\testing\"
ObjectFile="$(IntDir)\ai\default\"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug_with_VLD|Win32"
>
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)\ai\testing\"
ObjectFile="$(IntDir)\ai\default\"
/>
</FileConfiguration>
<FileConfiguration
Name="Test_Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)\ai\testing\"
ObjectFile="$(IntDir)\ai\default\"
/>
</FileConfiguration>
<FileConfiguration
Name="Test_Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)\ai\testing\"
ObjectFile="$(IntDir)\ai\default\"
/>
</FileConfiguration>
<FileConfiguration
Name="ReleaseDEBUG|Win32"
>
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)\ai\testing\"
ObjectFile="$(IntDir)\ai\default\"
/>
</FileConfiguration>
</File>
<File
RelativePath="..\..\src\ai\testing\ca_testing_move_to_targets.hpp"
RelativePath="..\..\src\ai\default\stage_rca.hpp"
>
</File>
</Filter>
<Filter
Name="testing"
>
<File
RelativePath="..\..\src\ai\testing\stage_sf_with_rca.cpp"
>
Expand Down
16 changes: 8 additions & 8 deletions projectfiles/Xcode/Wesnoth.xcodeproj/project.pbxproj
Expand Up @@ -275,8 +275,8 @@
B54AC7010FEA9FA5006F6FBD /* scrollbar_panel.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B54AC6FB0FEA9FA5006F6FBD /* scrollbar_panel.cpp */; };
B552D92410869477002D8F86 /* distributor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B552D92210869477002D8F86 /* distributor.cpp */; };
B552D92510869477002D8F86 /* distributor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B552D92210869477002D8F86 /* distributor.cpp */; };
B552D92D108694BB002D8F86 /* ca_testing_move_to_targets.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B552D92A108694BB002D8F86 /* ca_testing_move_to_targets.cpp */; };
B552D92F108694BB002D8F86 /* ca_testing_move_to_targets.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B552D92A108694BB002D8F86 /* ca_testing_move_to_targets.cpp */; };
B552D92D108694BB002D8F86 /* ca_move_to_targets.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B552D92A108694BB002D8F86 /* ca_move_to_targets.cpp */; };
B552D92F108694BB002D8F86 /* ca_move_to_targets.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B552D92A108694BB002D8F86 /* ca_move_to_targets.cpp */; };
B553B6BA12189C5900CC8C58 /* utility.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B553B6B812189C5900CC8C58 /* utility.cpp */; };
B553B6BB12189C5900CC8C58 /* utility.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B553B6B812189C5900CC8C58 /* utility.cpp */; };
B559986C0EC616B3008DD061 /* SDLMain.mm in Sources */ = {isa = PBXBuildFile; fileRef = B559986B0EC616B3008DD061 /* SDLMain.mm */; settings = {COMPILER_FLAGS = "-w"; }; };
Expand Down Expand Up @@ -1515,8 +1515,8 @@
B54AC6FD0FEA9FA5006F6FBD /* window_private.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = window_private.hpp; sourceTree = "<group>"; };
B552D92210869477002D8F86 /* distributor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = distributor.cpp; sourceTree = "<group>"; };
B552D92310869477002D8F86 /* distributor.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = distributor.hpp; sourceTree = "<group>"; };
B552D92A108694BB002D8F86 /* ca_testing_move_to_targets.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ca_testing_move_to_targets.cpp; sourceTree = "<group>"; };
B552D92B108694BB002D8F86 /* ca_testing_move_to_targets.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = ca_testing_move_to_targets.hpp; sourceTree = "<group>"; };
B552D92A108694BB002D8F86 /* ca_move_to_targets.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ca_move_to_targets.cpp; sourceTree = "<group>"; };
B552D92B108694BB002D8F86 /* ca_move_to_targets.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = ca_move_to_targets.hpp; sourceTree = "<group>"; };
B553B6B812189C5900CC8C58 /* utility.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = utility.cpp; sourceTree = "<group>"; };
B553B6B912189C5900CC8C58 /* utility.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = utility.hpp; sourceTree = "<group>"; };
B559986A0EC616B3008DD061 /* SDLMain.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDLMain.h; path = "Mac Sources/SDLMain.h"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3484,6 +3484,8 @@
B54AC6AB0FEA9EB5006F6FBD /* engine_cpp.hpp */,
EC48D74B17F3148300DE80BF /* recruitment.cpp */,
EC48D74C17F3148300DE80BF /* recruitment.hpp */,
B552D92A108694BB002D8F86 /* ca_move_to_targets.cpp */,
B552D92B108694BB002D8F86 /* ca_move_to_targets.hpp */,
B54AC6C50FEA9EB5006F6FBD /* stage_rca.cpp */,
B54AC6C60FEA9EB5006F6FBD /* stage_rca.hpp */,
);
Expand Down Expand Up @@ -3514,8 +3516,6 @@
B54AC6C00FEA9EB5006F6FBD /* testing */ = {
isa = PBXGroup;
children = (
B552D92A108694BB002D8F86 /* ca_testing_move_to_targets.cpp */,
B552D92B108694BB002D8F86 /* ca_testing_move_to_targets.hpp */,
EC4E3B1E19B2D8480049CBD7 /* stage_sf_with_rca.cpp */,
EC4E3B1F19B2D8480049CBD7 /* stage_sf_with_rca.hpp */,
);
Expand Down Expand Up @@ -4344,7 +4344,7 @@
62D24F2D1519982500350848 /* brush.cpp in Sources */,
B5599AD40EC62181008DD061 /* button.cpp in Sources */,
B5A9BD5B0ECA805A002BE442 /* button.cpp in Sources */,
B552D92D108694BB002D8F86 /* ca_testing_move_to_targets.cpp in Sources */,
B552D92D108694BB002D8F86 /* ca_move_to_targets.cpp in Sources */,
B54AC6E60FEA9EB5006F6FBD /* ca.cpp in Sources */,
B5599B810EC62181008DD061 /* callable_objects.cpp in Sources */,
B5951A9B1013BB5A00C10B66 /* callable_objects.cpp in Sources */,
Expand Down Expand Up @@ -4864,7 +4864,7 @@
B597C5600FACD6CA00CE81F5 /* binary_or_text.cpp in Sources */,
B597C5690FACD6CA00CE81F5 /* button.cpp in Sources */,
B597C65A0FACDDE800CE81F5 /* button.cpp in Sources */,
B552D92F108694BB002D8F86 /* ca_testing_move_to_targets.cpp in Sources */,
B552D92F108694BB002D8F86 /* ca_move_to_targets.cpp in Sources */,
B54AC6D50FEA9EB5006F6FBD /* ca.cpp in Sources */,
B597C5310FACD6CA00CE81F5 /* callable_objects.cpp in Sources */,
B5951A9D1013BB5A00C10B66 /* callable_objects.cpp in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Expand Up @@ -698,6 +698,7 @@ set(wesnoth-main_SRC
ai/default/aspect_attacks.cpp
ai/default/attack.cpp
ai/default/ca.cpp
ai/default/ca_move_to_targets.cpp
ai/default/contexts.cpp
ai/default/engine_cpp.cpp
ai/default/recruitment.cpp
Expand All @@ -719,7 +720,6 @@ set(wesnoth-main_SRC
ai/registry.cpp
ai/simulated_actions.cpp
ai/testing.cpp
ai/testing/ca_testing_move_to_targets.cpp
ai/testing/stage_sf_with_rca.cpp
animated_game.cpp
attack_prediction.cpp
Expand Down
2 changes: 1 addition & 1 deletion src/SConscript
Expand Up @@ -223,6 +223,7 @@ wesnoth_sources = Split("""
ai/default/aspect_attacks.cpp
ai/default/attack.cpp
ai/default/ca.cpp
ai/default/ca_move_to_targets.cpp
ai/default/contexts.cpp
ai/default/engine_cpp.cpp
ai/default/recruitment.cpp
Expand All @@ -244,7 +245,6 @@ wesnoth_sources = Split("""
ai/registry.cpp
ai/simulated_actions.cpp
ai/testing.cpp
ai/testing/ca_testing_move_to_targets.cpp
ai/testing/stage_sf_with_rca.cpp
animated_game.cpp
attack_prediction.cpp
Expand Down
71 changes: 0 additions & 71 deletions src/ai/default/ca.cpp
Expand Up @@ -1549,77 +1549,6 @@ bool retreat_phase::should_retreat(const map_location& loc, const unit_map::cons
}


//==============================================================

simple_move_and_targeting_phase::simple_move_and_targeting_phase(
rca_context &context, const config &cfg)
: candidate_action(context,cfg)
, move_()
{
}

simple_move_and_targeting_phase::~simple_move_and_targeting_phase()
{
}

double simple_move_and_targeting_phase::evaluate()
{
// Pick first enemy leader, move all units as close to
// enemy leader as possible.
// Own leader should not be moved.
// Code does not support multiple leaders per side.
// Do it fast even if there is a lot of units present.
unit_map &units_ = *resources::units;

unit_map::const_iterator leader = units_.find_leader(get_side());
map_location my_leader_loc = map_location::null_location();
if (leader.valid()) {
my_leader_loc = leader->get_location();
}

for(leader = units_.begin(); leader != units_.end(); ++leader) {
if(leader->can_recruit() && current_team().is_enemy(leader->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) {
if(my_leader_loc == i->second){// Do not move leaders.
continue;
}
const int distance = distance_between(i->first, leader->get_location());
if(closest_distance == -1 || distance < closest_distance) {
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 get_score();
}
}

return BAD_SCORE;
}

void simple_move_and_targeting_phase::execute()
{
move_->execute();
if (!move_->is_ok()){
LOG_AI_TESTING_AI_DEFAULT << get_name() << "::execute not ok" << std::endl;
}
}


//==============================================================

leader_control_phase::leader_control_phase( rca_context &context, const config &cfg )
Expand Down
18 changes: 0 additions & 18 deletions src/ai/default/ca.hpp
Expand Up @@ -237,24 +237,6 @@ class retreat_phase : public candidate_action {

};

//============================================================================

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 void execute();

private:

move_result_ptr move_;
};


//============================================================================

Expand Down

0 comments on commit af9be37

Please sign in to comment.