Skip to content

Commit

Permalink
ai_helper.find_best_move: return nil instead of {} if no move found
Browse files Browse the repository at this point in the history
This is done for consistency with similar functions in mainline. In principle this breaks backward compatibility.  However, while it is theoretically possible for this to happen, this function will generally always return at least the hex the unit is on, so it is very unlikely that this actually makes a difference somewhere.
  • Loading branch information
mattsc committed Oct 26, 2018
1 parent 41bd835 commit cd8af96
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions data/ai/lua/ai_helper.lua
Expand Up @@ -1416,16 +1416,14 @@ function ai_helper.find_best_move(units, rating_function, cfg)
-- best_hex: format { x, y }
-- best_unit: unit for which this rating function produced the maximum value
-- max_rating: the rating found for this hex/unit combination
-- If no valid moves were found, best_unit and best_hex are empty arrays

-- TODO: change return value to nil if no unit/hex is found later in 1.13., but keep as is in 1.12
-- If no valid moves were found, best_unit and best_hex are nil

cfg = cfg or {}

-- If this is an individual unit, turn it into an array
if units.hitpoints then units = { units } end

local max_rating, best_hex, best_unit = - math.huge, {}, {}
local max_rating, best_hex, best_unit = - math.huge
for _,unit in ipairs(units) do
-- Hexes each unit can reach
local reach_map = ai_helper.get_reachable_unocc(unit, cfg)
Expand Down

0 comments on commit cd8af96

Please sign in to comment.