![]() |
Battleships (C# Project)
Overview
For my third significant project, I decided to program a solver interface for Battleships, a puzzle type found in Games Magazine (and its sister, World of Puzzles), as well as on the Conceptis website. While Conceptis produces puzzles in three sizes, one (10x10 with ten ships) is standard in the magazines, so that's the one I went with. I tried to keep the code flexible enough that I could use other sizes as well with minor revisions.
For this first version, it's simply a solver. The user is responsible for generating the puzzle files (although I provide three files, a total of eighteen puzzles). The puzzle files are in XML, so that it will be easy for users to create new puzzle files; individual files can contain as many puzzles as the user wants, although the puzzle selection interface is optimized for six puzzles because that's the standard per-issue crop of puzzles in the magazine. It takes me about five minutes to do the data entry for a set of six.
The program
This is an online or offline implementation, with the following prerequisites.
If these components are already installed, you can run the application now (apparently requires Internet Explorer). Otherwise, set it up and run it (does not require Internet Explorer).
![]() |
![]() | |
| Fig. 1: Unsolved grid | Fig. 2: Solved grid |
My focus on this program was delving deeper into UI programming in WPF. The underlying solver logic was fairly straightforward; lots of clicking, checking the grid status, and redrawing the grid contents. I wanted the program to intuitively draw the correct ship segment based on its nighbors, so the user only had to toggle ship segments on or off. Other than this bit, most of the programming was on the UI and on reading the XML support files.
I made several posts in my Cerebri Laevi blog as I programmed, commenting on various programming issues:
Update: I've updated the program to add a randomizer and autosolver. The randomizer is not as elegant the one in Fathom it!, and I'll probably revisit it, but it appears to work.
Future developments
Some things that would make a nice, minimalist program nicer:
As for the program itself, I believe I've caught the bugs. Please do let me know if you find any problems, have any questions, or if you just happen to find this page, enjoy the program or write-up, and want to say hello.