I use this blog as a soap box to preach (ahem... to talk :-) about subjects that interest me.

Friday, October 7, 2011

The CalcuDoku application for the iPad is almost done!

Hopefully, in the next week or two, you will see the application in the Apple Store.  There will be a version with ten puzzles for free and a version with one hundred puzzles for a few dollars.  This is obviously to allow people to try out the game for free, and then, if they like what they see, buy the version with many puzzles to play.

Since the last article on this blog, I added a tool bar and a menu to select the puzzles, as shown in the following snapshot.


Let’s look at the tool bar first.  The button “Dismiss” is normally “Puzzles” and becomes “Dismiss” only after you have touched it in order to display the puzzle menu.  When you touch “Get hint”, the application suggest an action that you can perform to progress towards a solution; more about that later in this article.  “Reset puzzle” returns the current puzzle (“007” in the snapshot) to its initial state, with no cells solved and no candidates removed.  “Reveal puzzle” shows the solved puzzle (but then, where is all the fun? :-)

As you can see, you have a couple of segmented controls to select a subset of the puzzles.  Not really useful with ten puzzles, but absolutely necessary when you have one hundred of them.  The “difficulty” value that you see in the puzzle summary is calculated on the basis of the number and type of strategies needed to solve it.  I’ll tell you how I calculate it in a moment, when I explain the “Get hint” function.

Still in the puzzle summary, “8 actions” is the total number of times you have “touched” inside the action menu (see the previous article) to remove a candidate or solve a cell.

“3 cells solved” counts all the cells solved, regardless of how they were solved (and who solved them).  Cells can be solved in a number of ways. Two of them are obvious: you can touch a green “This cell contains” button in the action menu, or the red button marked “Show cell solution”.  Perhaps less obvious is that you can solve a cell by touching one of the “Remove candidate” blue buttons.  This can occur because the application automatically marks as solved the cells that remain with a single candidate.  If, for example, one cell whose solution is 2 shows the candidates 1 and 2, you can solve it either by pressing the green 2 or the blue 1.  The two actions are completely equivalent.

There is a fourth way of solving cells, and that is by letting the application automatically perform one of its hints.  The following snapshot shows an example of what happens when you press the “Get hint” button:


Below the tool bar you see the hint, which in the snapshot says: “You can remove the 6s from all the cells of row I that don’t belong to cage 30x in I4”.  It doesn’t say why, but if you look at the puzzle, you will notice that cage 30x in I4 only admits two solutions: 56 and 65 (obvious, as 6x5 is the only product of two numbers between 1 and 9 that results in 30).  But then, you know that 6 cannot possibly solve I8.

Now, if you touch the big button “Go ahead and do it!”, the application removes for you the 6 in I8, without you having to click on the cell to bring up the action menu and then touch the blue 6.  In this example, it is not a big deal, but in some cases there are a handful of cells containing the candidate to be removed.

I am not suggesting that you use the hints, but you might find them useful as a training exercise, to learn how to apply the strategies.

I have implemented five strategies to provide the hints, each requiring an average of 130 lines of objective-C code.  The application tries the strategies in order of complexity, so that it only resorts to a particular strategy when all the simpler ones have failed.

So far, I haven’t encountered a puzzle that those five strategies cannot solve.  This means that the application will always be able to give you a hint when you request it.  In fact, I use the hint mechanism to calculate the difficulty of the puzzles as: n5 * 25 + n4 * 5 + n3, where nX is the number of times the application needs to apply strategy X to solve the puzzle.  Note that the application starts searching for a hint from the last cell you have touched.  Therefore, you might find it a bit tricky to reproduce the difficulty I calculate, because I always do it with a freshly started application and a freshly loaded puzzle.  Only by starting from the same conditions it makes some sense to use my grading mechanism to compare puzzles.

Before I forget, although it goes almost without saying, you can also play the game in landscape mode if you like.

I still need to do a few things before I can release it:
  1. Generate and grade some 93 puzzles, so that both applications (free and not) are released at the same time.
  2. Modify the hint message to include the level of complexity of the strategy, just because you might like to know it.
  3. Make a page attached to the “About” button of the tool bar.
  4. Add to my web site zambon.com.au some pages of information associated with the application.
  5. Prepare a good ad page for the Apple Store.

No comments:

Post a Comment