Battleship

Solving Battleships with SAT

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

cnf.comment('link ships to board')
covered = defaultdict(list)
for ship1 in all_ships:
    for xy in just_ship(*ship1):
        covered[xy].append(ship1)
for xy in in_bounds:
    cells = [f(*s) for s in covered[xy]]
    if not cells:
        cnf.write_one(-f(*xy))
        continue
    cnf.write(iff_gen(f(*xy), cells, modeB=any))
Name:
Mail: (not shown)

Please type this: