Example #1
0
def move():
    data = bottle.request.json
    board = Board.from_json(data)
    murgatroid_controller = MurgatroidController(board)

    directions_map = murgatroid_controller.get_possible_directions()

    edge_direction = murgatroid_controller.move_edge()

    food_directions = murgatroid_controller.get_food_directions(directions_map)
    if food_directions:
        return json.dumps({
            'move':
            murgatroid_controller.get_safest_direction(food_directions),
            'shout':
            SHOUT,
        })
    else:
        if edge_direction in directions_map:
            direction = edge_direction
        else:
            direction = murgatroid_controller.get_safest_direction(
                directions_map)

        return json.dumps({
            'move': direction,
            'shout': SHOUT,
        })
Example #2
0
def move():
    data = bottle.request.json
    board = Board.from_json(data)
    murgatroid_controller = MurgatroidController(board)

    directions_map = murgatroid_controller.get_possible_directions()
    if not directions_map:
        # Commit suicide honorably so as not to give any victories to
        # the other inferior snakes!
        return json.dumps({
            'move': murgatroid_controller.seppuku(),
            'taunt': 'You will always remember this as the day you almost caught Captain Jack Sparrow!'
        })

    print directions_map

    edge_direction = murgatroid_controller.move_edge()
    print edge_direction

    taunt = get_taunt()

    food_directions = murgatroid_controller.get_food_directions(directions_map)
    if food_directions:
        return json.dumps({
            'move': murgatroid_controller.get_safest_direction(food_directions),
            'taunt': taunt,
        })
    else:
        if edge_direction in directions_map:
            direction = edge_direction
        else:
            direction = murgatroid_controller.get_safest_direction(directions_map)

        return json.dumps({
            'move': direction,
            'taunt': taunt,
        })