Update ModuleScripts/Grids.lua

This commit is contained in:
Sovereignty 2024-12-11 06:51:56 +00:00
parent f222d942e6
commit 4a151df395

View file

@ -145,7 +145,7 @@ local function generateRandomPath<grid>(grid: grid & Grid<any>, startIndex: numb
table.insert(directions, {node = forwardNode, weight = 1.2})
end
for i, direction in ipairs(directions) do
for i, direction in directions do
local distance = math.abs(direction.node - endIndex)
direction.weight = direction.weight / (distance + 1)
end
@ -153,7 +153,7 @@ local function generateRandomPath<grid>(grid: grid & Grid<any>, startIndex: numb
if #directions > 0 then
local totalWeight = 0
for _, direction in ipairs(directions) do
for _, direction in directions do
totalWeight = totalWeight + direction.weight
end
@ -161,7 +161,7 @@ local function generateRandomPath<grid>(grid: grid & Grid<any>, startIndex: numb
local accumulatedWeight = 0
local selectedNode
for _, direction in ipairs(directions) do
for _, direction in directions do
accumulatedWeight = accumulatedWeight + direction.weight
if rand <= accumulatedWeight then
selectedNode = direction.node