Skip to content

Commit 0be78df

Browse files
committed
run formatter
1 parent 6126ad6 commit 0be78df

File tree

3 files changed

+78
-69
lines changed

3 files changed

+78
-69
lines changed

apps/arena/lib/arena/bots/bot.ex

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -83,39 +83,40 @@ defmodule Arena.Bots.Bot do
8383
|> maybe_set_obstacles(game_state)
8484
end
8585

86-
defp maybe_set_obstacles(%{bot_state_machine: %{obstacles: nil}} = state, %{obstacles: obstacles}) when not is_nil(obstacles) do
86+
defp maybe_set_obstacles(%{bot_state_machine: %{obstacles: nil}} = state, %{obstacles: obstacles})
87+
when not is_nil(obstacles) do
8788
obstacles =
88-
obstacles
89-
|> Enum.map(fn {obstacle_id, obstacle} ->
90-
obstacle =
91-
obstacle
92-
|> Map.take([
93-
:id,
94-
:shape,
95-
:position,
96-
:radius,
97-
:vertices,
98-
:speed,
99-
:category,
100-
:direction,
101-
:is_moving,
102-
:name
103-
])
104-
105-
obstacle =
106-
obstacle
107-
|> Map.put(:position, %{x: obstacle.position.x, y: obstacle.position.y})
108-
|> Map.put(
109-
:vertices,
110-
Enum.map(obstacle.vertices.positions, fn position -> %{x: position.x, y: position.y} end)
111-
)
112-
|> Map.put(:direction, %{x: obstacle.direction.x, y: obstacle.direction.y})
113-
|> Map.put(:shape, get_shape(obstacle.shape))
114-
|> Map.put(:category, get_category(obstacle.category))
115-
116-
{obstacle_id, obstacle}
117-
end)
118-
|> Map.new()
89+
obstacles
90+
|> Enum.map(fn {obstacle_id, obstacle} ->
91+
obstacle =
92+
obstacle
93+
|> Map.take([
94+
:id,
95+
:shape,
96+
:position,
97+
:radius,
98+
:vertices,
99+
:speed,
100+
:category,
101+
:direction,
102+
:is_moving,
103+
:name
104+
])
105+
106+
obstacle =
107+
obstacle
108+
|> Map.put(:position, %{x: obstacle.position.x, y: obstacle.position.y})
109+
|> Map.put(
110+
:vertices,
111+
Enum.map(obstacle.vertices.positions, fn position -> %{x: position.x, y: position.y} end)
112+
)
113+
|> Map.put(:direction, %{x: obstacle.direction.x, y: obstacle.direction.y})
114+
|> Map.put(:shape, get_shape(obstacle.shape))
115+
|> Map.put(:category, get_category(obstacle.category))
116+
117+
{obstacle_id, obstacle}
118+
end)
119+
|> Map.new()
119120

120121
%{state | bot_state_machine: %{state.bot_state_machine | obstacles: obstacles}}
121122
end

apps/bot_manager/lib/bot_state_machine.ex

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -331,24 +331,28 @@ defmodule BotManager.BotStateMachine do
331331
Enum.empty?(shortest_path) ->
332332
Map.put(bot_state_machine, :path_towards_position, nil)
333333
|> Map.put(:position_to_move_to, nil)
334+
334335
length(shortest_path) == 1 ->
335336
Map.put(bot_state_machine, :position_to_move_to, position_to_move_to)
336337
|> Map.put(
337338
:path_towards_position,
338339
[to]
339340
)
340341
|> Map.put(:last_time_position_changed, :os.system_time(:millisecond))
342+
341343
true ->
342344
# Replacing first and last points with the actual start and end points
343-
shortest_path = ([from] ++ Enum.slice(shortest_path, 1, Enum.count(shortest_path) - 2) ++ [to])
344-
|> AStarNative.simplify_path(bot_state_machine.obstacles)
345-
346-
shortest_path = if System.get_env("TEST_PATHFINDING_SPLINES") == "true" do
347-
shortest_path
348-
|> SplinePath.smooth_path()
349-
else
350-
shortest_path
351-
end
345+
shortest_path =
346+
([from] ++ Enum.slice(shortest_path, 1, Enum.count(shortest_path) - 2) ++ [to])
347+
|> AStarNative.simplify_path(bot_state_machine.obstacles)
348+
349+
shortest_path =
350+
if System.get_env("TEST_PATHFINDING_SPLINES") == "true" do
351+
shortest_path
352+
|> SplinePath.smooth_path()
353+
else
354+
shortest_path
355+
end
352356

353357
# The first point should only be necessary to simplify the path
354358
shortest_path = tl(shortest_path)

apps/bot_manager/lib/spline_path.ex

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ defmodule SplinePath do
44
55
Based on https://qroph.github.io/2018/07/30/smooth-paths-using-catmull-rom-splines.html
66
"""
7-
alias BotManager.Math.Vector
7+
alias BotManager.Math.Vector
88

99
@segment_point_amount 5
1010
@tension 0.2
@@ -37,41 +37,45 @@ alias BotManager.Math.Vector
3737
t01 = :math.pow(Vector.distance(p0, p1), @alpha)
3838
t12 = :math.pow(Vector.distance(p1, p2), @alpha)
3939
t23 = :math.pow(Vector.distance(p2, p3), @alpha)
40-
41-
m1 = Vector.sub(
42-
Vector.mult(Vector.sub(p1, p0), 1 / t01),
43-
Vector.mult(Vector.sub(p1, p0), 1 / (t01 + t12))
44-
)
45-
|> Vector.mult(t12)
46-
|> Vector.add(p2)
47-
|> Vector.sub(p1)
48-
|> Vector.mult(1.0 - @tension)
4940

50-
m2 = Vector.sub(
51-
Vector.mult(Vector.sub(p3, p2), 1 / t23),
52-
Vector.mult(Vector.sub(p3, p1), 1 / (t12 + t23))
53-
)
54-
|> Vector.mult(t12)
55-
|> Vector.add(p2)
56-
|> Vector.sub(p1)
57-
|> Vector.mult(1.0 - @tension)
41+
m1 =
42+
Vector.sub(
43+
Vector.mult(Vector.sub(p1, p0), 1 / t01),
44+
Vector.mult(Vector.sub(p1, p0), 1 / (t01 + t12))
45+
)
46+
|> Vector.mult(t12)
47+
|> Vector.add(p2)
48+
|> Vector.sub(p1)
49+
|> Vector.mult(1.0 - @tension)
5850

59-
a = Vector.sub(p1, p2)
60-
|> Vector.mult(2.0)
61-
|> Vector.add(m1)
62-
|> Vector.add(m2)
51+
m2 =
52+
Vector.sub(
53+
Vector.mult(Vector.sub(p3, p2), 1 / t23),
54+
Vector.mult(Vector.sub(p3, p1), 1 / (t12 + t23))
55+
)
56+
|> Vector.mult(t12)
57+
|> Vector.add(p2)
58+
|> Vector.sub(p1)
59+
|> Vector.mult(1.0 - @tension)
6360

64-
b = Vector.sub(p1, p2)
65-
|> Vector.mult(-3.0)
66-
|> Vector.sub(m1)
67-
|> Vector.sub(m1)
68-
|> Vector.sub(m2)
61+
a =
62+
Vector.sub(p1, p2)
63+
|> Vector.mult(2.0)
64+
|> Vector.add(m1)
65+
|> Vector.add(m2)
66+
67+
b =
68+
Vector.sub(p1, p2)
69+
|> Vector.mult(-3.0)
70+
|> Vector.sub(m1)
71+
|> Vector.sub(m1)
72+
|> Vector.sub(m2)
6973

7074
c = m1
7175
d = p1
7276

7377
# last point will be the next part start so do not add it
74-
Enum.map(0..(@segment_point_amount - 1), fn segment_num ->
78+
Enum.map(0..(@segment_point_amount - 1), fn segment_num ->
7579
t = segment_num / @segment_point_amount
7680

7781
d

0 commit comments

Comments
 (0)