import csv


def layer_to_grid(layer_filename):
    """
    Converts a TMX layer to a matrix indicating if a tile is
    present (0) or not (1). This provides the barriers needed for pathfinding.
    """
    with open(layer_filename, newline='') as f:
        reader = csv.reader(f)
        matrix = list(reader)

    matrix_2 = []

    for row in matrix:
        matrix_2.append([1 if int(num) < 0 else 0 for num in row])

    return matrix_2