Skip to content

Commit

Permalink
ExpAI grab villages CA: fix enemy distance rating under fog
Browse files Browse the repository at this point in the history
ai_helper.get_closest_enemy() returns math.huge for the enemy distance if no enemy is visible to the AI. This fixes #4157.
  • Loading branch information
mattsc committed Jul 10, 2019
1 parent 6e27a3f commit e148d25
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions data/ai/lua/ca_grab_villages.lua
Expand Up @@ -64,7 +64,8 @@ function ca_grab_villages:evaluation(cfg, data)
if wesnoth.is_enemy(owner, wesnoth.current.side) then village_rating = village_rating + 20000 end
end

local _, enemy_distance_from_village = AH.get_closest_enemy(v)
local village_closest_enemy, enemy_distance_from_village = AH.get_closest_enemy(v)
if (not village_closest_enemy) then enemy_distance_from_village = 0 end

-- Now we go on to the unit-dependent rating
local best_unit_rating = - math.huge
Expand Down Expand Up @@ -96,7 +97,8 @@ function ca_grab_villages:evaluation(cfg, data)
end

-- Prefer not backtracking and moving more distant units to capture villages
local _, enemy_distance_from_unit = AH.get_closest_enemy({u.x, u.y})
local unit_closest_enemy, enemy_distance_from_unit = AH.get_closest_enemy({u.x, u.y})
if (not unit_closest_enemy) then enemy_distance_from_unit = 0 end
rating = rating - (enemy_distance_from_village + enemy_distance_from_unit)/5

if (rating > best_unit_rating) then
Expand Down

0 comments on commit e148d25

Please sign in to comment.