Skip to content

Commit 5388120

Browse files
committed
Fix weird crash
1 parent 85af0fc commit 5388120

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

lib/move_your_cedric/models/player.ex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ defmodule MoveYourCedric.Models.Player do
1414
position: nil,
1515
status: :idle,
1616
target: nil,
17-
path: nil,
18-
completed: true
17+
path: nil
1918
}
2019
{:ok, state}
2120
end
@@ -219,7 +218,8 @@ defmodule MoveYourCedric.Models.Player do
219218
Astar.cost_to_enter(current.position, neighbor.position) +
220219
Astar.manhattan_distance(neighbor.position, state.target)
221220
end)
222-
|> Enum.min()
221+
# Avoid a weird crash when no route's available... Probably a wrong fix.
222+
|> Enum.min(fn -> 0 end)
223223

224224
IO.puts("Calculated shortest path available")
225225

@@ -243,7 +243,7 @@ defmodule MoveYourCedric.Models.Player do
243243
}
244244

245245
if not neighbor_in_open_list do
246-
node
246+
node
247247
else
248248
nil
249249
end

0 commit comments

Comments
 (0)