Simple Attack Micro AI: code cleanup
This commit is contained in:
parent
19462f3a15
commit
b6559a82e2
1 changed files with 6 additions and 11 deletions
|
@ -1,4 +1,3 @@
|
|||
local H = wesnoth.require "lua/helper.lua"
|
||||
local AH = wesnoth.require "ai/lua/ai_helper.lua"
|
||||
local BC = wesnoth.require "ai/lua/battle_calcs.lua"
|
||||
local LS = wesnoth.require "lua/location_set.lua"
|
||||
|
@ -12,29 +11,26 @@ function ca_simple_attack:evaluation(ai, cfg, self)
|
|||
}
|
||||
if (not units[1]) then return 0 end
|
||||
|
||||
-- Get all possible attacks
|
||||
local attacks = AH.get_attacks(units, { include_occupied = true })
|
||||
--print('#attacks', #attacks)
|
||||
if (not attacks[1]) then return 0 end
|
||||
|
||||
-- If cfg.filter_second is set, set up a map (location set)
|
||||
-- of enemies that it is okay to attack
|
||||
local enemy_map
|
||||
if cfg.filter_second then
|
||||
local enemies = wesnoth.get_units {
|
||||
{ "filter_side", {{ "enemy_of", { side = wesnoth.current.side } }} },
|
||||
{ "filter_side", { { "enemy_of", { side = wesnoth.current.side } } } },
|
||||
{ "and", cfg.filter_second }
|
||||
}
|
||||
--print('#enemies', #enemies)
|
||||
if (not enemies[1]) then return 0 end
|
||||
|
||||
enemy_map = LS.create()
|
||||
for i,e in ipairs(enemies) do enemy_map:insert(e.x, e.y) end
|
||||
for _,e in ipairs(enemies) do enemy_map:insert(e.x, e.y) end
|
||||
end
|
||||
|
||||
-- Now find the best of the possible attacks
|
||||
local attacks = AH.get_attacks(units, { include_occupied = true })
|
||||
if (not attacks[1]) then return 0 end
|
||||
|
||||
local max_rating, best_attack = -9e99, {}
|
||||
for i, att in ipairs(attacks) do
|
||||
for _, att in ipairs(attacks) do
|
||||
local valid_target = true
|
||||
if cfg.filter_second and (not enemy_map:get(att.target.x, att.target.y)) then
|
||||
valid_target = false
|
||||
|
@ -46,7 +42,6 @@ function ca_simple_attack:evaluation(ai, cfg, self)
|
|||
local dst = { att.dst.x, att.dst.y }
|
||||
|
||||
local rating = BC.attack_rating(attacker, enemy, dst)
|
||||
--print('rating:', rating, attacker.id, enemy.id)
|
||||
|
||||
if (rating > max_rating) then
|
||||
max_rating = rating
|
||||
|
|
Loading…
Add table
Reference in a new issue