From 8e101f8bfd995321ac08a16fea9a171b549a0ae4 Mon Sep 17 00:00:00 2001 From: Steph Enders Date: Sat, 17 Dec 2022 11:04:20 -0500 Subject: Support doors with keys Add initial support for doors and keys via pre-defined mappings: k || d ------ 1 -> a 2 -> b 3 -> c 4 -> d Any key can open any door of its mapping, but is spent once used. May require additional testing --- dnglib/algs.lua | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'dnglib/algs.lua') diff --git a/dnglib/algs.lua b/dnglib/algs.lua index d2e6252..b5f331f 100644 --- a/dnglib/algs.lua +++ b/dnglib/algs.lua @@ -150,10 +150,12 @@ end ---@param target_pos table [x, y] -- @param enemies list of enemy positions (cannot pass thru enemy) -- @param treasures list of treasure positions (cannot pass thru treasure) +-- @param door_keys list of key positions (cannot pass thru treasure) +-- @param doors list of door positions (cannot pass thru treasure) ---@param map table 2D map array ---@return table best move to target [x, y] --- -local function pathfind(start_pos, target_pos, enemies, treasures, map) +local function pathfind(start_pos, target_pos, enemies, treasures, door_keys, doors, map) local queue = Queue:new() local visit_map = {} @@ -173,7 +175,13 @@ local function pathfind(start_pos, target_pos, enemies, treasures, map) for _, t in ipairs(treasures) do visit_map[t.y][t.x] = MAP_WALL -- use wall value for impass end - + for _, k in ipairs(door_keys) do + visit_map[k.y][k.x] = MAP_WALL -- use wall value for impass + end + for _, d in ipairs(doors) do + visit_map[d.y][d.x] = MAP_WALL -- use wall value for impass + end + -- since we mutate the visit_map let's calc this early if need be local best_effort = best_effort_move(start_pos, target_pos, visit_map) -- cgit v1.2.3-54-g00ecf