Skip to content

Instantly share code, notes, and snippets.

@colinjfw
Last active September 28, 2019 01:14
Show Gist options
  • Save colinjfw/f3df25b0b01cdcfe279a8821b821fdfd to your computer and use it in GitHub Desktop.
Save colinjfw/f3df25b0b01cdcfe279a8821b821fdfd to your computer and use it in GitHub Desktop.
def move_as_coord(move, head)
case move
when 'up'
return {x: head[:x], y: head[:y]-1}
when 'down'
return {x: head[:x], y: head[:y]+1}
when 'left'
return {x: head[:x]-1, y: head[:y]}
when 'right'
return {x: head[:x]+1, y: head[:y]}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment