示例#1
0
def load(board_state_rows):
    board = Board.load()

    tile_args_dicts = []
    for tile_args in board_state_rows:
        missing = [arg for arg in FIELDNAMES if tile_args.get(arg) is None]
        if missing:
            raise ValueError(
                "Invalid board state input. Row missing {}: {}".format(
                    ", ".join(missing), tile_args))

        tile_id = tile_args.pop("tile_id")
        tile_args["tile"] = get_tile(tile_id)
        if not tile_args["tile"]:
            raise ValueError(
                "No tile with the tile ID {} was found.".format(tile_id))

        tile_args_dicts.append(tile_args)

    for tile_args in sorted(tile_args_dicts,
                            key=lambda adict: adict["tile"].phase):
        if tile_args["tile"].is_chicago:
            board.place_chicago(tile_args["tile"])
        else:
            board.place_tile(**tile_args)

    return board
示例#2
0
def _get_orientations(coord, tile_id):
    if not coord or not tile_id:
        return None

    try:
        cell = Cell.from_coord(coord)
    except ValueError:
        return None

    tile = tiles.get_tile(tile_id)
    if not tile:
        return None

    orientations = []
    for orientation in range(0, 6):
        try:
            _BASE_BOARD._validate_place_tile_neighbors(cell, tile, orientation)
            _BASE_BOARD._validate_place_tile_upgrade(_get_space(coord), cell,
                                                     tile, orientation)
        except ValueError:
            continue

        orientations.append(orientation)

    return orientations
示例#3
0
def board_tile_info():
    coord = request.args.get("coord")
    chicago_neighbor = request.args.get("chicagoNeighbor")
    tile_id = request.args.get("tileId")

    tile = tiles.get_tile(tile_id) if tile_id else _BASE_BOARD.get_space(
        Cell.from_coord(coord))

    default_offset = {"x": 0, "y": 0}
    offset_data = STATION_DATA["tile"] if tile_id else STATION_DATA["board"]
    offset = offset_data.get(coord, {}).get("offset", default_offset)
    if chicago_neighbor:
        offset = offset[chicago_neighbor]

    info = {"capacity": tile.capacity, "offset": offset, "phase": tile.phase}

    return jsonify({"info": info})