Skip to content
Permalink
Browse files

eat more

  • Loading branch information...
kssilveira committed Mar 9, 2019
1 parent d265e30 commit 80e9d9f057eee4db28153d66e1a92c55d89ae6f2
Showing with 12 additions and 1 deletion.
  1. +12 −1 app/main.py
@@ -76,6 +76,7 @@ def __init__(self, data, exclude_heads_of_other_snakes):

you = data['you']
self.id = you['id']
self.name = you['name']
body = you['body']
self.health = you['health']
self.head = body[0]
@@ -170,6 +171,13 @@ def move_to_food(self, distances, moves, tail_distances):
print 'move_to_food', 'mindist', mindist, 'res', res
return res

def get_min_health(name):
res = 100
if name == "s2":
res = 50
print 'get_min_health', 'name', name, 'res', res
return res

def run(data, exclude_heads_of_other_snakes):
print 'exclude_heads_of_other_snakes', exclude_heads_of_other_snakes

@@ -204,14 +212,17 @@ def run(data, exclude_heads_of_other_snakes):
break
if direction == NO_MOVE and not exclude_heads_of_other_snakes:
direction = game.move_to_max(distances, moves)
if game.health <= 50:
if game.health <= get_min_health(game.name):
food_direction = game.move_to_food(distances, moves, tail_distances)
if food_direction != NO_MOVE:
direction = food_direction
print 'move_response', 'dir', direction

return direction

# TODO
# - don't eat if too close to tail

@bottle.post('/move')
def move():
data = bottle.request.json

0 comments on commit 80e9d9f

Please sign in to comment.
You can’t perform that action at this time.