Skip to content

Commit

Permalink
Code suggestion for snake moving
Browse files Browse the repository at this point in the history
  • Loading branch information
ggpasqualino committed Feb 8, 2020
1 parent 14612a4 commit 0d543f6
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions docs/tutorial/03-let-the-snake-move.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,13 @@ Now we're ready to implement the movement logic. Let's recall what happens durin
defp move_snake(%{snake: snake} = state) do
%{body: body, direction: direction} = snake

# new head
# new head's position
[head | _] = body
new_head = move(state, head, direction)

# truncate body
size = length(body)
new_body = Enum.take([new_head | body], size)
# place a new head on the tile that we want to move to
# and remove the last tile from the snake tail
new_body = List.delete_at([new_head | body], -1)

state
|> put_in([:snake, :body], new_body)
Expand Down

0 comments on commit 0d543f6

Please sign in to comment.