Micro AIs: standardize eval/exec function table setup
This commit is contained in:
parent
59e95ff304
commit
bb8c08a314
7 changed files with 18 additions and 18 deletions
|
@ -4,8 +4,6 @@ local AH = wesnoth.require "ai/lua/ai_helper.lua"
|
|||
local BC = wesnoth.require "ai/lua/battle_calcs.lua"
|
||||
local MAISD = wesnoth.require "ai/micro_ais/micro_ai_self_data.lua"
|
||||
|
||||
local ca_bottleneck_move = {}
|
||||
|
||||
local function bottleneck_is_my_territory(map, enemy_map)
|
||||
-- Create map that contains 'true' for all hexes that are
|
||||
-- on the AI's side of the map
|
||||
|
@ -212,6 +210,8 @@ local function bottleneck_move_out_of_way(unit, self)
|
|||
if best_reach > -1 then return best_hex end
|
||||
end
|
||||
|
||||
local ca_bottleneck_move = {}
|
||||
|
||||
function ca_bottleneck_move:evaluation(ai, cfg, self)
|
||||
-- Check whether the side leader should be included or not
|
||||
if cfg.active_side_leader and
|
||||
|
|
|
@ -5,8 +5,6 @@ local LS = wesnoth.require "lua/location_set.lua"
|
|||
local MAIUV = wesnoth.require "ai/micro_ais/micro_ai_unit_variables.lua"
|
||||
local MAISD = wesnoth.require "ai/micro_ais/micro_ai_self_data.lua"
|
||||
|
||||
local ca_goto = {}
|
||||
|
||||
local function custom_cost(x, y, u, enemy_map, enemy_attack_map, multiplier)
|
||||
local terrain = wesnoth.get_terrain(x, y)
|
||||
local move_cost = wesnoth.unit_movement_cost(u, terrain)
|
||||
|
@ -17,6 +15,8 @@ local function custom_cost(x, y, u, enemy_map, enemy_attack_map, multiplier)
|
|||
return move_cost
|
||||
end
|
||||
|
||||
local ca_goto = {}
|
||||
|
||||
function ca_goto:evaluation(ai, cfg, self)
|
||||
|
||||
-- If cfg.release_all_units_at_goal is set, check
|
||||
|
|
|
@ -3,8 +3,6 @@ local AH = wesnoth.require "ai/lua/ai_helper.lua"
|
|||
|
||||
local messenger_next_waypoint = wesnoth.require "ai/micro_ais/cas/ca_messenger_f_next_waypoint.lua"
|
||||
|
||||
local ca_messenger_attack = {}
|
||||
|
||||
local function messenger_find_enemies_in_way(unit, goal_x, goal_y)
|
||||
-- Returns the first unit on or next to the path of the messenger
|
||||
-- unit: proxy table for the messenger unit
|
||||
|
@ -124,6 +122,8 @@ local function messenger_find_clearing_attack(unit, goal_x, goal_y, cfg)
|
|||
end
|
||||
end
|
||||
|
||||
local ca_messenger_attack = {}
|
||||
|
||||
function ca_messenger_attack:evaluation(ai, cfg, self)
|
||||
-- Attack units in the path of the messengers
|
||||
-- goal_x, goal_y: coordinates of the goal toward which the messenger moves
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
local AH = wesnoth.require("ai/lua/ai_helper.lua")
|
||||
|
||||
local ca_recruit_random = {}
|
||||
|
||||
local recruit
|
||||
|
||||
local ca_recruit_random = {}
|
||||
|
||||
function ca_recruit_random:evaluation(ai, cfg)
|
||||
-- Random recruiting from all the units the side has
|
||||
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
local AH = wesnoth.require("ai/lua/ai_helper.lua")
|
||||
|
||||
local ca_recruit_rushers = {}
|
||||
|
||||
local internal_recruit_cas = {}
|
||||
local internal_params = {}
|
||||
-- The following external engine creates the CA functions recruit_rushers_eval and recruit_rushers_exec
|
||||
|
@ -10,6 +8,8 @@ local internal_params = {}
|
|||
-- 'ai' is nil here (not defined), so we pass it directly in the execution function below
|
||||
wesnoth.require("ai/lua/generic_recruit_engine.lua").init(ai, internal_recruit_cas, internal_params)
|
||||
|
||||
local ca_recruit_rushers = {}
|
||||
|
||||
function ca_recruit_rushers:evaluation(ai, cfg)
|
||||
internal_params.randomness = cfg.randomness
|
||||
return internal_recruit_cas:recruit_rushers_eval()
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
local H = wesnoth.require "lua/helper.lua"
|
||||
local AH = wesnoth.require "ai/lua/ai_helper.lua"
|
||||
|
||||
local swarm_move = {}
|
||||
local ca_swarm_move = {}
|
||||
|
||||
function swarm_move:evaluation(ai, cfg)
|
||||
function ca_swarm_move:evaluation(ai, cfg)
|
||||
local units = wesnoth.get_units { side = wesnoth.current.side }
|
||||
for i,u in ipairs(units) do
|
||||
if (u.moves > 0) then return cfg.ca_score end
|
||||
|
@ -12,7 +12,7 @@ function swarm_move:evaluation(ai, cfg)
|
|||
return 0
|
||||
end
|
||||
|
||||
function swarm_move:execution(ai, cfg)
|
||||
function ca_swarm_move:execution(ai, cfg)
|
||||
local enemy_distance = cfg.enemy_distance or 5
|
||||
local vision_distance = cfg.vision_distance or 12
|
||||
|
||||
|
@ -71,4 +71,4 @@ function swarm_move:execution(ai, cfg)
|
|||
AH.movefull_stopunit(ai, unit, best_hex)
|
||||
end
|
||||
|
||||
return swarm_move
|
||||
return ca_swarm_move
|
||||
|
|
|
@ -16,15 +16,15 @@ local function get_swarm_units(cfg)
|
|||
return AH.get_units_with_moves { side = wesnoth.current.side }
|
||||
end
|
||||
|
||||
local swarm_scatter = {}
|
||||
local ca_swarm_scatter = {}
|
||||
|
||||
function swarm_scatter:evaluation(ai, cfg)
|
||||
function ca_swarm_scatter:evaluation(ai, cfg)
|
||||
if (not get_enemies(cfg)[1]) then return 0 end
|
||||
if (not get_swarm_units(cfg)[1]) then return 0 end
|
||||
return cfg.ca_score
|
||||
end
|
||||
|
||||
function swarm_scatter:execution(ai, cfg)
|
||||
function ca_swarm_scatter:execution(ai, cfg)
|
||||
local enemies = get_enemies(cfg)
|
||||
local units = get_swarm_units(cfg)
|
||||
local vision_distance = cfg.vision_distance or 12
|
||||
|
@ -53,4 +53,4 @@ function swarm_scatter:execution(ai, cfg)
|
|||
end
|
||||
end
|
||||
|
||||
return swarm_scatter
|
||||
return ca_swarm_scatter
|
||||
|
|
Loading…
Add table
Reference in a new issue