Skip to content

Commit

Permalink
I'll bail now
Browse files Browse the repository at this point in the history
  • Loading branch information
lgauthie committed Feb 22, 2015
1 parent eb73a77 commit 7353bcf
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,23 +160,36 @@ def move_edge(nagini, bounds):
def move():
data = bottle.request.json

width = len(data['board'])
height = len(data['board'][0])

bounds = {
"up": 1,
"down": len(data['board'][0]) - 2,
"right": len(data['board']) - 2,
"down": height - 2,
"right": width - 2,
"left": 1,
}

nagini = [s for s in data['snakes'] if s['name'] == 'nagini'][0]

directions = get_possible_directions(nagini, data['board'], bounds)
if not directions:
# Commit suicide honorably so as not to give any victories to
# the other inferior snakes!
return json.dumps({
'move': seppuku(nagini, data['board']),
'taunt': 'You will always remember this as the day you almost caught Captain Jack Sparrow!'
})
bounds = {
"up": 0,
"down": height - 1,
"right": width - 1,
"left": 0,
}

directions = get_possible_directions(nagini, data['board'], bounds)
if not directions:
# Commit suicide honorably so as not to give any victories to
# the other inferior snakes!

return json.dumps({
'move': seppuku(nagini, data['board']),
'taunt': 'You will always remember this as the day you almost caught Captain Jack Sparrow!'
})

direction = move_edge(nagini, bounds)

Expand Down

0 comments on commit 7353bcf

Please sign in to comment.