Beispiel #1
0
def greedy_start():
    return jsonify({
        "color": 'yellow',
        "head_url": urljoin(request.url, '/images/heads/demon-1.png'),
        "name": 'GenetiGreedy',
        "taunt": taunt(),
        })
Beispiel #2
0
 def __init__(self, name, funcstr, head_url, color=None, taunt_str=None):
     self.name = name
     self.funcstr = funcstr
     self.head_url = head_url
     self.color = color or string2color(funcstr)
     self.taunt = taunt_str or taunt()
     self.snake = GenetiSnake(solver.parsefunc(GenetiSnake.ARITY, self.funcstr))
Beispiel #3
0
def trainee_start():
    return jsonify({
        "color": 'green',
        "head_url": urljoin(request.url, '/images/heads/kabuki-2.png'),
        "name": 'GenetiRookie',
        "taunt": taunt(),
        })
Beispiel #4
0
def rookie_start(idx):
    rookie = ROOKIES[int(idx)]
    return jsonify({
        "color": rookie.color,
        "head_url": urljoin(request.url, rookie.head_url),
        "name": rookie.name,
        "taunt": taunt(),
        })
Beispiel #5
0
def start():
    LOG.debug("start: request.json=%s", request.json)

    return jsonify({
        "color": COLOR,
        "head_url": urljoin(request.url, '/images/heads/chinese-1.png'),
        "name": NAME,
        "taunt": taunt(),
        })
Beispiel #6
0
def move(snake=None):
    #LOG.debug("move: request=%s", request)

    # See https://stembolthq.github.io/battle_snake/
    # board	Array<Array<BoardCell>>	Two dimensional representation of the board
    # food	Array<Point>	Array of all food currently on the board
    # game_id	UUID
    # height	integer
    # width	integer
    # snakes	Array<Snake>	Array of all living snakes in the game
    #   coords	 	Array<Point>
    #   health_points	 	0..100
    #   id	 	UUID
    #   name	 	string
    #   taunt	 	string
    # turn	integer	The current turn.
    # you	UUID	A reference to your snake's id, the snake object can be found in snakes.
    request.get_data() # get all request data and cache it
    data = request.json

    if not snake:
        snake=BEST_SNAKE
    
    if "board" in data:
        del data["board"]

    LOG.debug("move: pid=%s turn=%s content_length=%s",
              os.getpid(), data["turn"],
              request.headers.get('content-length'))

    # convert the Battlesnake server structure into my Game
    width, height = (int(data[x]) for x in ("width", "height"))
    game = Game(width, height)
    board = game.render()
    game.food = [board.index(*xy) for xy in data["food"]]
    game.turn_count = int(data["turn"])
    self_index = None
    for idx, data_snake in enumerate(data["snakes"]):
        player = game.add_snake(data_snake, data_snake["id"])
        player.body = [board.index(*xy) for xy in data_snake["coords"]]
        player.health = data_snake["health_points"]
        if player.name == data["you"]:
            self_index = idx
    board = game.render()
    move_name = snake.move(game, board, self_index)

    LOG.debug("move: move=%s", move_name)

    return jsonify({
        "move": move_name,
        "taunt": taunt(),
        })