https://github.com/leongc/kenken/commits/master
I've been working on a kenken[1] solver. It is far from done, but some
basics are in place.
I'm linking to the history because I think it's interesting to note
that I have already made a couple of major structural changes to how I
initially modeled things.
I definitely over-guessed at what I would need when I began and it
took a while for me to see that I had put a lot of junk in the Puzzle
that did not belong there.
Later I suspected there might be a better way to construct puzzles;
using a version of Builder helped me see the extra baggage the Puzzle
was carrying.
Trying to write tests also exposed poor separation of concerns between
the Solver and the Solution.
So far I believe I can express Puzzles and expected Solutions easily,
but solving is far off.
I'm also not thrilled about the lack of a coordinate construct to
represent (row, col) int pairs for addressing cells in Cages and
Solutions, but on the flip side, does it help or hinder to have a pair
of ints as a struct?
I have only identified a couple of logical side-effects that are
independent of Cages:
A. when setting a value in a cell, that value is impossible for all
other cells in that row and column, and other values are impossible in
that cell
B. when a cell has only one possible value, that must be the value to set
And a few Cage-based reductions that might lead towards a solution.
1. the identity cage (duh)
2. (im)possible pairs (brute force)
3. shrinking cages when a cell in the cage has a known value
I know I need to add some more general logic to establish (im)possible
lists of Cage factors and addends (beyond pairs).
If a value appears in the intersection of possible lists of Cage
factors or addends and the value is possible in only one of the Cage
cells, then that is the value to set for that cell.
There will also be a row/column aspect for repeated Cage factors or
addends in the lists (must appear in different rows and columns). I
don't know how to structure this yet.
I also know there needs to be some kind of Cage-independent solution
logic that can evaluate a row or column and detect if N cells from
that row or column have a union of N or less possible values, then it
is impossible for the other cells in that row or column to have any
value from the union. Initially I expected this would be done by
Uniques, but I eliminated that class because I don't know how to
structure this yet either.
I welcome your thoughts, comments, or suggestions,
Cheng
[1]
http://en.wikipedia.org/wiki/KenKen