Exemplo n.º 1
0
def random_nonogram(row_count, col_count):
    cell_count = row_count * col_count

    # nonograms with half of the cells colored are the hardest
    colored_cell_count = np.random.binomial(cell_count, 0.5)

    fields = list(itertools.product(range(row_count), range(col_count)))

    colored_fields = random.sample(fields, k=colored_cell_count)

    nonogram = Nonogram(row_count, col_count, colored_cells=colored_fields)

    nonogram.calculate_descriptors()
    nonogram.reset_cells()

    if nonogram.solve():
        return nonogram
    else:
        return random_nonogram(row_count, col_count)