Skip to content

Instantly share code, notes, and snippets.

// Place your key bindings in this file to override the defaults
[
// New file uses cmd+n and a new folder uses cmd+shift+n (or ctrl).
{
"key": "cmd+n",
"command": "explorer.newFile",
"when": "explorerViewletFocus"
},
{
"key": "cmd+enter",
+---------+ +--------+ +-----------+ +-------------+
| Tooling | | GitHub | | 3rd Party | | Your Server |
+---------+ +--------+ +-----------+ +-------------+
| | | |
| Create Deployment | | |
|--------------------->| | |
| | | |
| Deployment Created | | |
|<---------------------| | |
| | | |
def move(state)
head = state[:you][:body][0]
neck = state[:you][:body][1]
moves = ['up', 'down', 'left', 'right']
moves.each do |move|
coord = move_as_coord(move, head)
if !off_board(state, coord) && !coord_equal(coord, neck)
return { move: move }
end
def coord_equal(a, b)
a[:x] === b[:x] && a[:y] === b[:y]
end
def move(state)
head = state[:you][:body][0]
moves = ['up', 'down', 'left', 'right']
moves.each do |move|
coord = move_as_coord(move, head)
unless off_board(state, coord)
return { move: move }
end
end
def off_board(state, coord)
return true if coord[:x] < 0
return true if coord[:y] < 0
return true if coord[:y] >= state[:board][:height]
return true if coord[:x] >= state[:board][:height]
return false # If it makes it here we are ok.
end
@colinjfw
colinjfw / move_1.rb
Last active September 28, 2019 01:08
def move(state)
head = state[:you][:body][0]
moves = ['up', 'down', 'left', 'right']
moves.each do |move|
coord = move_as_coord(move, head)
# We now know where this is going to be!
end
end
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]}
def move(state)
head = state[:you][:body][0]
...
end
def move(state)
puts state
{ move: 'right' }
end