@@ -293,24 +293,32 @@ defmodule BotManager.BotStateMachine do
293
293
shortest_path = AStarNative . a_star_shortest_path ( from , to , bot_state_machine . collision_grid )
294
294
295
295
# If we don't have a path, retry finding new position in map
296
- if Enum . empty? ( shortest_path ) do
297
- Map . put ( bot_state_machine , :path_towards_position , nil )
298
- |> Map . put ( :position_to_move_to , nil )
299
- else
300
- # Replacing first and last points with the actual start and end points
301
- shortest_path = ( [ from ] ++ Enum . slice ( shortest_path , 1 , Enum . count ( shortest_path ) - 2 ) ++ [ to ] )
302
- |> AStarNative . simplify_path ( bot_state_machine . obstacles )
303
- |> SplinePath . smooth_path ( )
304
-
305
- # The first point should only be necessary to simplify the path
306
- shortest_path = tl ( shortest_path )
307
-
308
- Map . put ( bot_state_machine , :position_to_move_to , position_to_move_to )
309
- |> Map . put (
310
- :path_towards_position ,
311
- shortest_path
312
- )
313
- |> Map . put ( :last_time_position_changed , :os . system_time ( :millisecond ) )
296
+ cond do
297
+ Enum . empty? ( shortest_path ) ->
298
+ Map . put ( bot_state_machine , :path_towards_position , nil )
299
+ |> Map . put ( :position_to_move_to , nil )
300
+ length ( shortest_path ) == 1 ->
301
+ Map . put ( bot_state_machine , :position_to_move_to , position_to_move_to )
302
+ |> Map . put (
303
+ :path_towards_position ,
304
+ [ to ]
305
+ )
306
+ |> Map . put ( :last_time_position_changed , :os . system_time ( :millisecond ) )
307
+ true ->
308
+ # Replacing first and last points with the actual start and end points
309
+ shortest_path = ( [ from ] ++ Enum . slice ( shortest_path , 1 , Enum . count ( shortest_path ) - 2 ) ++ [ to ] )
310
+ |> AStarNative . simplify_path ( bot_state_machine . obstacles )
311
+ |> SplinePath . smooth_path ( )
312
+
313
+ # The first point should only be necessary to simplify the path
314
+ shortest_path = tl ( shortest_path )
315
+
316
+ Map . put ( bot_state_machine , :position_to_move_to , position_to_move_to )
317
+ |> Map . put (
318
+ :path_towards_position ,
319
+ shortest_path
320
+ )
321
+ |> Map . put ( :last_time_position_changed , :os . system_time ( :millisecond ) )
314
322
end
315
323
end
316
324
end
0 commit comments