Пример #1
0
def solve_file(path, dist=False):
    print("Reading level from", path)
    level = Level()
    level.load_from_file(path)

    print("Generating clauses ...")
    clauses = sat_get_clauses(level, dist)
    print("Got %d clauses" % len(clauses))

    pathparts = splitext(path)
    pathin = "%s.sat_in%s" % pathparts
    pathout = "%s.sat_out%s" % pathparts
    pathsol = "%s.sol.png" % pathparts[0]

    print("Writing to file ...")
    map = sat_write_clauses(clauses, pathin)

    # Release some memory
    clauses = []
    collect()

    print("Running SAT solver ...")
    call([SAT_PATH, pathin, pathout])

    print("Reading valuation ...")
    val = sat_read_valuation(level, map, pathout)

    if not val:
        print("Unsatisfiable ...")
        return

    # pprint(val)

    print("Displaying solution ...")
    img = get_solution(level, val, dist)
    img.show()
    img.save(pathsol)