Monday, March 7, 2011

Planning the level math

With the hint groups I've decided to start with (equals and sum), it's time to start writing the math to generate and solve levels. This is how I imagine it working, roughly:


Generate level

  • (Done) Start with an empty board of size n * n
  • (Done) Fill in the numbers, like discussed before
  • (Done) Shuffle columns and rows around to make the board random
  • Create a class, Solver, that given a board will return options for the next play. If this method is implemented like you'd actually play if you were good, then it is a good indicator of how many moves it takes to complete a level. This number can also be used as an indicator for the difficulty of the level.
  • Add hint groups to the level until the Solver is able to solve it in less than X moves.

Solver

The Solver class will have one method:

public static List<PlayAction> GetPossibleMoves(Level level, int? maxMoves)

Outline of the solver code

I'm not entirely sure how this will work yet. Based on how I'd play, it will do this:

  • Remove answers to cells that are wrong

    This one might be optional. There can be an option in the game of whether or not it will tell you that an answer is wrong (blink red or something).
  • Look for equals hint groups and check off the numbers.
  • Eliminate numbers that cannot exist in a sum:

    Calculate all the ways to make a certain sum and exclude the numbers that cannot be used to make the sum. (I wrote the code for this when I woke up today and it works quite well)
  • Answer squares where every number but one is eliminated
  • Answer squares when it is the only one that can have a certain number
  • Exclude numbers when they must be used somewhere else.
    If two cells in the row have excluded every number but A and B, then A nor B can be used anywhere else in the row. This logic works for all numbers, not only two. I'm not sure how to write this yet.
  • Unnamed

    When a hint group has a bend/turn in it, such as:



    The green group is a sum group that must add up to 6. There are three ways to accomplish that: (2, 2, 2), (3, 2, 1), (4, 1, 1). The solution (2, 2, 2) is impossible, because the number 2 would end up being used twice in the same column or row. Assuming the solution (3, 2, 1) is eliminated, the solution (4, 1, 1), or in the image (1, 4, 1) is given by the constraint of not repeating the number 1 in the same column or row.

0 comments:

Post a Comment