Skip to content

Commit 3d8be76

Browse files
committed
run formatter
1 parent 5150caf commit 3d8be76

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
@@ -95,39 +95,40 @@ defmodule Arena.Bots.Bot do
9595
|> maybe_set_obstacles(game_state)
9696
end
9797

98-
defp maybe_set_obstacles(%{bot_state_machine: %{obstacles: nil}} = state, %{obstacles: obstacles}) when not is_nil(obstacles) do
98+
defp maybe_set_obstacles(%{bot_state_machine: %{obstacles: nil}} = state, %{obstacles: obstacles})
99+
when not is_nil(obstacles) do
99100
obstacles =
100-
obstacles
101-
|> Enum.map(fn {obstacle_id, obstacle} ->
102-
obstacle =
103-
obstacle
104-
|> Map.take([
105-
:id,
106-
:shape,
107-
:position,
108-
:radius,
109-
:vertices,
110-
:speed,
111-
:category,
112-
:direction,
113-
:is_moving,
114-
:name
115-
])
116-
117-
obstacle =
118-
obstacle
119-
|> Map.put(:position, %{x: obstacle.position.x, y: obstacle.position.y})
120-
|> Map.put(
121-
:vertices,
122-
Enum.map(obstacle.vertices.positions, fn position -> %{x: position.x, y: position.y} end)
123-
)
124-
|> Map.put(:direction, %{x: obstacle.direction.x, y: obstacle.direction.y})
125-
|> Map.put(:shape, get_shape(obstacle.shape))
126-
|> Map.put(:category, get_category(obstacle.category))
127-
128-
{obstacle_id, obstacle}
129-
end)
130-
|> Map.new()
101+
obstacles
102+
|> Enum.map(fn {obstacle_id, obstacle} ->
103+
obstacle =
104+
obstacle
105+
|> Map.take([
106+
:id,
107+
:shape,
108+
:position,
109+
:radius,
110+
:vertices,
111+
:speed,
112+
:category,
113+
:direction,
114+
:is_moving,
115+
:name
116+
])
117+
118+
obstacle =
119+
obstacle
120+
|> Map.put(:position, %{x: obstacle.position.x, y: obstacle.position.y})
121+
|> Map.put(
122+
:vertices,
123+
Enum.map(obstacle.vertices.positions, fn position -> %{x: position.x, y: position.y} end)
124+
)
125+
|> Map.put(:direction, %{x: obstacle.direction.x, y: obstacle.direction.y})
126+
|> Map.put(:shape, get_shape(obstacle.shape))
127+
|> Map.put(:category, get_category(obstacle.category))
128+
129+
{obstacle_id, obstacle}
130+
end)
131+
|> Map.new()
131132

132133
%{state | bot_state_machine: %{state.bot_state_machine | obstacles: obstacles}}
133134
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)