AI: add [filter_own] to all Experimental AI candidate actions
This commit is contained in:
parent
997e08c5d3
commit
1816ee5249
9 changed files with 52 additions and 21 deletions
|
@ -26,7 +26,7 @@ end
|
|||
|
||||
local ca_castle_switch = {}
|
||||
|
||||
function ca_castle_switch:evaluation(cfg, data)
|
||||
function ca_castle_switch:evaluation(cfg, data, filter_own)
|
||||
local start_time, ca_name = wesnoth.get_time_stamp() / 1000., 'castle_switch'
|
||||
if AH.print_eval() then AH.print_ts(' - Evaluating castle_switch CA:') end
|
||||
|
||||
|
@ -38,7 +38,8 @@ function ca_castle_switch:evaluation(cfg, data)
|
|||
local leader = wesnoth.units.find_on_map {
|
||||
side = wesnoth.current.side,
|
||||
canrecruit = 'yes',
|
||||
formula = '(movement_left = total_movement) and (hitpoints = max_hitpoints)'
|
||||
formula = '(movement_left = total_movement) and (hitpoints = max_hitpoints)',
|
||||
{ "and", filter_own }
|
||||
}[1]
|
||||
if not leader then
|
||||
-- CA is irrelevant if no leader or the leader may have moved from another CA
|
||||
|
@ -189,8 +190,12 @@ function ca_castle_switch:evaluation(cfg, data)
|
|||
return 0
|
||||
end
|
||||
|
||||
function ca_castle_switch:execution(cfg, data)
|
||||
local leader = wesnoth.units.find_on_map { side = wesnoth.current.side, canrecruit = 'yes' }[1]
|
||||
function ca_castle_switch:execution(cfg, data, filter_own)
|
||||
local leader = wesnoth.units.find_on_map {
|
||||
side = wesnoth.current.side,
|
||||
canrecruit = 'yes',
|
||||
{ "and", filter_own }
|
||||
}[1]
|
||||
|
||||
if AH.print_exec() then AH.print_ts(' Executing castle_switch CA') end
|
||||
if AH.show_messages() then wesnoth.wml_actions.message { speaker = leader.id, message = 'Switching castles' } end
|
||||
|
|
|
@ -8,12 +8,16 @@ local GV_unit, GV_village
|
|||
|
||||
local ca_grab_villages = {}
|
||||
|
||||
function ca_grab_villages:evaluation(cfg, data)
|
||||
function ca_grab_villages:evaluation(cfg, data, filter_own)
|
||||
local start_time, ca_name = wesnoth.get_time_stamp() / 1000., 'grab_villages'
|
||||
if AH.print_eval() then AH.print_ts(' - Evaluating grab_villages CA:') end
|
||||
|
||||
-- Check if there are units with moves left
|
||||
local units = AH.get_units_with_moves({ side = wesnoth.current.side, canrecruit = 'no' }, true)
|
||||
local units = AH.get_units_with_moves({
|
||||
side = wesnoth.current.side,
|
||||
canrecruit = 'no',
|
||||
{ "and", filter_own }
|
||||
}, true)
|
||||
if (not units[1]) then
|
||||
if AH.print_eval() then AH.done_eval_messages(start_time, ca_name) end
|
||||
return 0
|
||||
|
|
|
@ -9,13 +9,14 @@ local MTAE_unit, MTAE_destination
|
|||
|
||||
local ca_move_to_any_enemy = {}
|
||||
|
||||
function ca_move_to_any_enemy:evaluation(cfg, data)
|
||||
function ca_move_to_any_enemy:evaluation(cfg, data, filter_own)
|
||||
local start_time, ca_name = wesnoth.get_time_stamp() / 1000., 'move_to_any_enemy'
|
||||
if AH.print_eval() then AH.print_ts(' - Evaluating move_to_any_enemy CA:') end
|
||||
|
||||
local units = AH.get_units_with_moves {
|
||||
side = wesnoth.current.side,
|
||||
canrecruit = 'no'
|
||||
canrecruit = 'no',
|
||||
{ "and", filter_own }
|
||||
}
|
||||
|
||||
if (not units[1]) then
|
||||
|
|
|
@ -5,11 +5,11 @@ local HS = wesnoth.require "ai/micro_ais/cas/ca_healer_move.lua"
|
|||
|
||||
local ca_place_healers = {}
|
||||
|
||||
function ca_place_healers:evaluation(cfg, data)
|
||||
function ca_place_healers:evaluation(cfg, data, filter_own)
|
||||
local start_time, ca_name = wesnoth.get_time_stamp() / 1000., 'place_healers'
|
||||
if AH.print_eval() then AH.print_ts(' - Evaluating place_healers CA:') end
|
||||
|
||||
if HS:evaluation(cfg, data) > 0 then
|
||||
if HS:evaluation({ { 'filter', filter_own } }, data) > 0 then
|
||||
if AH.print_eval() then AH.done_eval_messages(start_time, ca_name) end
|
||||
return 96000
|
||||
end
|
||||
|
|
|
@ -34,9 +34,10 @@ wesnoth.require("ai/lua/generic_recruit_engine.lua").init(dummy_engine, params)
|
|||
|
||||
local ca_recruit_rushers = {}
|
||||
|
||||
function ca_recruit_rushers:evaluation(cfg, data)
|
||||
function ca_recruit_rushers:evaluation(cfg, data, filter_own)
|
||||
params.high_level_fraction = cfg.high_level_fraction
|
||||
params.randomness = cfg.randomness
|
||||
params.filter_own = filter_own
|
||||
return dummy_engine:recruit_rushers_eval()
|
||||
end
|
||||
|
||||
|
|
|
@ -7,11 +7,14 @@ local retreat_unit, retreat_loc
|
|||
|
||||
local ca_retreat_injured = {}
|
||||
|
||||
function ca_retreat_injured:evaluation(cfg, data)
|
||||
function ca_retreat_injured:evaluation(cfg, data, filter_own)
|
||||
local start_time, ca_name = wesnoth.get_time_stamp() / 1000., 'retreat_injured'
|
||||
if AH.print_eval() then AH.print_ts(' - Evaluating retreat_injured CA:') end
|
||||
|
||||
local units = AH.get_units_with_moves({ side = wesnoth.current.side }, true)
|
||||
local units = AH.get_units_with_moves({
|
||||
side = wesnoth.current.side,
|
||||
{ "and", filter_own }
|
||||
}, true)
|
||||
local unit, loc = R.retreat_injured_units(units)
|
||||
if unit then
|
||||
retreat_unit = unit
|
||||
|
|
|
@ -7,7 +7,7 @@ local SP_attack
|
|||
|
||||
local ca_spread_poison = {}
|
||||
|
||||
function ca_spread_poison:evaluation(cfg, data)
|
||||
function ca_spread_poison:evaluation(cfg, data, filter_own)
|
||||
local start_time, ca_name = wesnoth.get_time_stamp() / 1000., 'spread_poison'
|
||||
if AH.print_eval() then AH.print_ts(' - Evaluating spread_poison CA:') end
|
||||
|
||||
|
@ -21,7 +21,8 @@ function ca_spread_poison:evaluation(cfg, data)
|
|||
} }
|
||||
} }
|
||||
} },
|
||||
canrecruit = 'no'
|
||||
canrecruit = 'no',
|
||||
{ "and", filter_own }
|
||||
}
|
||||
if (not poisoners[1]) then
|
||||
if AH.print_eval() then AH.done_eval_messages(start_time, ca_name) end
|
||||
|
|
|
@ -6,7 +6,7 @@ local AH = wesnoth.require "ai/lua/ai_helper.lua"
|
|||
|
||||
local ca_village_hunt = {}
|
||||
|
||||
function ca_village_hunt:evaluation(cfg, data)
|
||||
function ca_village_hunt:evaluation(cfg, data, filter_own)
|
||||
local start_time, ca_name = wesnoth.get_time_stamp() / 1000., 'village_hunt'
|
||||
if AH.print_eval() then AH.print_ts(' - Evaluating village_hunt CA:') end
|
||||
|
||||
|
@ -30,7 +30,11 @@ function ca_village_hunt:evaluation(cfg, data)
|
|||
return 0
|
||||
end
|
||||
|
||||
local units = AH.get_units_with_moves({ side = wesnoth.current.side, canrecruit = 'no' }, true)
|
||||
local units = AH.get_units_with_moves({
|
||||
side = wesnoth.current.side,
|
||||
canrecruit = 'no',
|
||||
{ "and", filter_own }
|
||||
}, true)
|
||||
|
||||
if not units[1] then
|
||||
if AH.print_eval() then AH.done_eval_messages(start_time, ca_name) end
|
||||
|
@ -41,8 +45,12 @@ function ca_village_hunt:evaluation(cfg, data)
|
|||
return 30000
|
||||
end
|
||||
|
||||
function ca_village_hunt:execution(cfg, data)
|
||||
local unit = AH.get_units_with_moves({ side = wesnoth.current.side, canrecruit = 'no' }, true)[1]
|
||||
function ca_village_hunt:execution(cfg, data, filter_own)
|
||||
local unit = AH.get_units_with_moves({
|
||||
side = wesnoth.current.side,
|
||||
canrecruit = 'no',
|
||||
{ "and", filter_own }
|
||||
}, true)[1]
|
||||
|
||||
if AH.print_exec() then AH.print_ts(' Executing village_hunt CA') end
|
||||
|
||||
|
|
|
@ -336,7 +336,11 @@ return {
|
|||
|
||||
function do_recruit_eval(data)
|
||||
-- Check if leader is on keep
|
||||
local leader = wesnoth.units.find_on_map { side = wesnoth.current.side, canrecruit = 'yes' }[1]
|
||||
local leader = wesnoth.units.find_on_map {
|
||||
side = wesnoth.current.side,
|
||||
canrecruit = 'yes',
|
||||
{ "and", params.filter_own }
|
||||
}[1]
|
||||
|
||||
if (not leader) or (not wesnoth.get_terrain_info(wesnoth.get_terrain(leader.x, leader.y)).keep) then
|
||||
return 0
|
||||
|
@ -566,7 +570,11 @@ return {
|
|||
end
|
||||
|
||||
local recruit_type
|
||||
local leader = wesnoth.units.find_on_map { side = wesnoth.current.side, canrecruit = 'yes' }[1]
|
||||
local leader = wesnoth.units.find_on_map {
|
||||
side = wesnoth.current.side,
|
||||
canrecruit = 'yes',
|
||||
{ "and", params.filter_own }
|
||||
}[1]
|
||||
repeat
|
||||
recruit_data.recruit.best_hex, recruit_data.recruit.target_hex = ai_cas:find_best_recruit_hex(leader, recruit_data)
|
||||
recruit_type = ai_cas:find_best_recruit(attack_type_count, unit_attack_type_count, recruit_effectiveness, recruit_vulnerability, attack_range_count, unit_attack_range_count, most_common_range_count)
|
||||
|
|
Loading…
Add table
Reference in a new issue