Count the Islands - An Example Program for WPF and Recursion

106 13
Recently, an About Visual Basic reader sent me the following programming challenge:

Write a (VB6) program that solves the below problem:

You are given a map as a string. The map represents an ocean with some number of islands. For example:

.........
.XX....X.
XXX..XX..
.X.......
...XXX...


On the map, "X" represents land, while "." represents water. The grid will be rectangular with width

Now, not being born yesterday, I recognized a school assignment when I saw one.


I usually decline to do school assignments because people don't learn when I do their homework for them. But this one looked intensely interesting, so I decided to program it anyway. Since I'm doing it for my reasons, I decided to write the code using VB.NET with WPF, not VB6. And I wrote it to generate different maps populated with random characters rather than using a fixed map for more thorough testing. Besides, now that it's done, there are a lot of different things that I'm going to be able to pack into one article using this program.
  1. Using pseudocode to develop an algorithm
  2. Dynamically generating the content of a WPF Grid
  3. A really interesting example of the use of recursion
  4. How to solve the problem (of course)

The rest of this article explains the program code in detail. If you download the source using this link, you will be able to follow along more easily. We start on the first part of the program - generating a island "map" in WPF using VB.NET code on the next page:
Source...
Subscribe to our newsletter
Sign up here to get the latest news, updates and special offers delivered directly to your inbox.
You can unsubscribe at any time

Leave A Reply

Your email address will not be published.