Battleships update

I’ve been rather obsessively working on my Battleships program the last few days, and have quite a bit to show for it: The autosolver works now, as does the random puzzle generator. The random puzzle generator is nowhere near as speedy or elegant as the one in Fathom It!, but it’s a start.

For the autosolver, I spent the better part of a programming day working on a blind alley of an approach, placing the 4-ship, then the 3-ships, and so on. I’m not sure where the algorithm went awry, but it consistently failed to work as expected. Then it occurred to me to simply solve the puzzles in a brute force variation of what I use on the harder puzzles:

  • Fill in the easy cells.
  • For the first empty cell, create a test version where it’s a ship, and another where it’s water.
  • Repeat these steps for each of the two test versions.
  • Repeat until all test versions have been completed or ruled out.

I use a List of possible solutions, creating a second List by iterating through the first one, then copying the second List back to the first one and repeating.

Now that the autosolver works, I’m now thinking about adding a puzzle designer so the user can design, test, and save their own puzzles (although I think I’m going to first take some time off from this project to get some other things done).

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.