• 沒有找到結果。

Pseudo-Generator

在文檔中 2008mcmsolutions (頁 133-136)

Our pseudo-generator takes a completed Sudoku board and a set of cells to leave empty at beginning of a puzzle, called the reserved cells. The idea is to guarantee the use of a high-level strategy, such as Swordfish or Backtracking, by ensuring that a generated puzzle cannot be completed without such a strategy. Call the starting puzzle the seed board and the solution the completed seed board. To use the pseudo-generator, we must first prepare a list of reserved cells, found as follows:

1. Take a seed board thathsolvecannot solve using strategies only up to tierk, buthsolvecan solve with strategies up to tierk + 1(see Appendix

for the different tiers of strategies we use).

2. Usehsolveto make all possible deductions (i.e. adjusting the SSG) using only strategies up to tierk.

3. Create a list of cells that are still empty.

We then pass to the pseudo-generator the completed seed board and this list of reserved cells. The pseudo-generator iterates the algorithm below, starting with an empty board, until all the cells except the reserved cells are filled in:

1. Randomly fill an unoccupied, unreserved cell on the board with the number in the corresponding cell of the completed seed board.

2. Applyhsolveto make logical deductions and to complete the board as much as possible.

Differences From Standard Generator

The main differences between the pseudo-generator and the standard generator are:

1. When filling in an empty cell, the standard generator uses the number in the corresponding cell of the completed puzzle, instead of choosing this number at random from the cell’s SSG.

2. When selecting which empty cell to fill in, the pseudo-generator never selects one of the reserved cells.

3. hsolveis equipped with strategies only up to tierk.

4. The pseudo-generator terminates not when the board is completely filled in but rather when all of the unreserved cells are filled in.

The pseudo-generator is only partially random. It provides enough clues so that the unreserved cells of the board can be solved with strate-gies up to tierk, and the choice of which of these cells to reveal as clues is determined randomly. However, the solution of the generated puzzle is in-dependent of these random choices and must be identical to the completed seed board. For the same reason as in the standard generator, the solution must be unique.

The pseudo-generator never provides clues for reserved cells; hence, whenhsolve solves a puzzle, it uses strategies of tiers 0 throughk to fill in the unreserved cells, and then is forced to use a strategy in tierk + 1to solve the remaining portion of the board.

Pseudo-Generator Puzzle Variability

The benefit of the pseudo-generator over the standard generator is gen-erating puzzles in which a strategy of tier k + 1must be used, thus

guar-We implement the pseudo-generator by first randomly permuting the rows, columns, and numbers of the given completed puzzle, so as to create an illusion that it is a different puzzle. Ideally, we should have a large database of difficult puzzles to choose from (together with the highest tier strategy needed to solve each puzzle and its list of reserved cells that cannot be filled with strategies of lower tiers).

Difficulty Concerns

“Difficulty level” is not well-defined: In a system of three difficulty lev-els, how difficult is a medium puzzle, as compared to a hard or easy puzzle?

In the previous correlation analysis in which we divided 800 puzzles into eight difficulty levels, we forced each difficulty level to contain 100 puzzles.

Generating Puzzles with a Specific Difficulty

Figure 5 shows the measured difficulty of 1,000 puzzles generated by the standard generator. We can divide the puzzles into intervals of difficulty, with equal numbers of puzzles in each interval. To create a puzzle of given difficulty level using the standard generator, we iterate the generator until a puzzle is generated whose difficulty value falls within the appropriate interval.

1000 2000 3000 4000

0.0005 0.001 0.0015 0.002 0.0025 0.003 0.0035

Figure 5. A histogram of the measured difficulty of 1,000 puzzles generated by the standard generator.

Standard Generator Runtime

It took 3 min to generate 100 valid boards (and 30 invalid boards) and 12 min to determine the difficulties of the 100 valid boards. Thus, 100 boards take a total 15 min to run, or an average of about 9 sec per valid board.

From the difficulty distribution in Figure 5, we can obtain an expected runtime estimate for each level of difficulty. For four levels, the expected number of boards that one needs to construct to obtain a board of level 1 is a geometric random variable with parameterp = 1000598, so the expected runtime to obtain a board of level 1 is0.15 × 1000598 = 0.25min. Similarly, the expected runtimes to obtain boards of level 2, level 3, and level 4 are 3.1, 4.7, and 30 min.

Using Pseudo-Generator to Generate Difficult Puzzles

To generate large numbers of difficult boards, it would be best to employ the pseudo-generator. We fed the pseudo-generator a puzzle (“Riddle of Sho”) that can be solved only by using the tier-5 backtracking strategy [Sudoku Solver n.d.]. The difficulty of the puzzle was determined to be 8,122, while the average difficulty of 20 derived puzzles generated using this puzzle was 7,111. Since all puzzles derived from a puzzle fed into the pseudo-generator must share application of the most difficult strategy, the difficulties of the derived puzzles are approximately the same as that of the original puzzle.

With a database of difficult puzzles, a method of employing the pseudo-generator is to find the midpoint of the difficulty bounds of the desired level, choose randomly a puzzle whose difficulty is close to this midpoint, and generate a derived puzzle. If the difficulty of the derived puzzle fails to be within our bounds, we continue choosing an existing puzzle at random and creating a derived puzzle until the bound condition is met. The average generation time for a puzzle is 9 sec, the same as for the standard generator.

For difficult boards, there is a huge difference between the two strategies in the expected number of boards that one needs to construct, and the pseudo-generator is much more efficient.

Conclusion

在文檔中 2008mcmsolutions (頁 133-136)

相關文件