Battleship

Solving Battleships with SAT

Comments are moderated. It may take a few minutes before your comment appears.
Markdown is supported in your comments.

print('terms:', cnf.maxterm)
print('clauses:', cnf.clauses)
assert cnf.verify()

interesting = set(f(x,y) for x,y in product(xs, ys))
for solution in cnf.solutions(3, interesting=interesting):
    print()
    marked = {}
    used_ships = [s for s in all_ships if f(*s) in solution]
    for s in used_ships:
        marked.update(exact_ship(*s))
    for y in ys:
        line = ''
        for x in xs:
            if (x,y) in marked:
                line += marked[(x,y)]
            else:
                line += '.'
            line += ' '
        line = line.replace('~', '.')
        print(line)
Name:
Mail: (not shown)

Please type this: