Update ModuleScripts/Grids.lua
This commit is contained in:
parent
f222d942e6
commit
4a151df395
1 changed files with 3 additions and 3 deletions
|
@ -145,7 +145,7 @@ local function generateRandomPath<grid>(grid: grid & Grid<any>, startIndex: numb
|
||||||
table.insert(directions, {node = forwardNode, weight = 1.2})
|
table.insert(directions, {node = forwardNode, weight = 1.2})
|
||||||
end
|
end
|
||||||
|
|
||||||
for i, direction in ipairs(directions) do
|
for i, direction in directions do
|
||||||
local distance = math.abs(direction.node - endIndex)
|
local distance = math.abs(direction.node - endIndex)
|
||||||
direction.weight = direction.weight / (distance + 1)
|
direction.weight = direction.weight / (distance + 1)
|
||||||
end
|
end
|
||||||
|
@ -153,7 +153,7 @@ local function generateRandomPath<grid>(grid: grid & Grid<any>, startIndex: numb
|
||||||
|
|
||||||
if #directions > 0 then
|
if #directions > 0 then
|
||||||
local totalWeight = 0
|
local totalWeight = 0
|
||||||
for _, direction in ipairs(directions) do
|
for _, direction in directions do
|
||||||
totalWeight = totalWeight + direction.weight
|
totalWeight = totalWeight + direction.weight
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -161,7 +161,7 @@ local function generateRandomPath<grid>(grid: grid & Grid<any>, startIndex: numb
|
||||||
local accumulatedWeight = 0
|
local accumulatedWeight = 0
|
||||||
local selectedNode
|
local selectedNode
|
||||||
|
|
||||||
for _, direction in ipairs(directions) do
|
for _, direction in directions do
|
||||||
accumulatedWeight = accumulatedWeight + direction.weight
|
accumulatedWeight = accumulatedWeight + direction.weight
|
||||||
if rand <= accumulatedWeight then
|
if rand <= accumulatedWeight then
|
||||||
selectedNode = direction.node
|
selectedNode = direction.node
|
||||||
|
|
Loading…
Reference in a new issue