@bottle.post('/move')
def move():
    data = bottle.request.json
    (game_id, grid, food, charlie, enemies, check_food) = init(data)
    if ((len(enemies) > 2) or (charlie.length <= 25) or (charlie.health <= 60)):
        path = eat_food(charlie, grid, food, check_food)
        if path:
            return move_response(direction(path[0], path[1]))
    if (charlie.length >= 3):
        path = find_my_tail(charlie, grid)
        if path:
            return move_response(direction(path[0], path[1]))
    if (not path):
        path = find_enemy_tail(charlie, enemies, grid)
        if path:
            return move_response(direction(path[0], path[1]))
    if (charlie.length >= 3):
        path = find_my_tail_emergency(charlie, grid)
        if path:
            return move_response(direction(path[0], path[1]))
    if (not path):
        path = trouble(charlie, grid)
        if path:
            return move_response(direction(path[0], path[1]))
@bottle.post('/move')
def move():
    data = bottle.request.json
    (game_id, grid, food, charlie, enemies, check_food) = init(data)
    if ((len(enemies) > 2) or (charlie.length <= 25) or (charlie.health <= 60)):
        path = eat_food(charlie, grid, food, check_food)
        if path:
            return move_response(direction(path[0], path[1]))
    if (charlie.length >= 3):
        path = find_my_tail(charlie, grid)
        if path:
            return move_response(direction(path[0], path[1]))
    if (not path):
        path = find_enemy_tail(charlie, enemies, grid)
        if path:
            return move_response(direction(path[0], path[1]))
    if (charlie.length >= 3):
        path = find_my_tail_emergency(charlie, grid)
        if path:
            return move_response(direction(path[0], path[1]))
    if (not path):
        path = trouble(charlie, grid)
        if path:
            return move_response(direction(path[0], path[1]))