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('no overlapping ships')
for i,ship1 in enumerate(all_ships):
    points1 = set(just_ship(*ship1))
    water1 = just_water(points1)
    occupied1 = points1 | water1
    for ship2 in all_ships[i:]:
        if ship1[0] == ship2[0]:
        points2 = set(just_ship(*ship2))
        if occupied1 & points2:
            cnf.write_one(-f(*ship1), -f(*ship2))
        # (points1 & water2) would be redundant
Mail: (not shown)

Please type this: