1、数字建模 模拟一数独陈丽娟蒋鑫陈德进Creating Sudoku PuzzlesSummarySudoku puzzle is an attractive game which is very popular in the world now. At current, creating and evaluating the difficulty level of Sudoku puzzles is a significant problem. In our paper we design an algorithm that based on improvement backdating me
2、thod and can produce different difficulty Sudoku with a unique solution, then evaluate the complexity of it. First, we define the basic operation of finding the smallest candidate number and judging whether the layout is final layout or death layout. On this basis, using the search algorithm minimum
3、 candidate number and backtracking exhaustively state space to minimize algorithm complexity. Then, construct a decision tree and use backdating method to define difficulty evaluation from three aspects. The three aspects are the number of known grids in original layout, the smallest known number of
4、 each row and each line, the search number in solving the final layout. Through a lot of experiments we endow them with corresponding weights, and use the weights to calculate the difficulty grade of each original layout.Finally, design an algorithm to produce an original layout which satisfies the
5、rules of Sudoku. Solve it and get all the final layouts of it, then use backtracking to seek an original layout with unique solution meeting the chosen difficulty level. key words: the search algorithm minimum candidate; decision tree; weights; backtracking Content1. Introduction Sudoku was devised
6、by mathematician Olah, and now it is popular at home and abroad. It is an attractive game that lots of people like to study it though buying books. There are 9 3 3 unit grids in the original Sudoku, each of which is a unit 3 3 grid. Each grid can have a number of 1 to 9 to give it a simple constrain
7、t, or may be empty. The rules of the game are as follows 3: 1. Each row of cells contains the integers 1 through to 9 exactly once;2. Each column of cells contains the integers 1 through to 9 exactly once;3. Each 3 3 square contains the integers 1 through to 9 exactly once. In order to understand cl
8、early we give a simple example as picture 1 shows:528167394649328715173495268394586172817234956256719483435871629762953841981642537281673946432871517349268345861728173495625671943435816297629534198164253 The original layout the final layoutFigure 1 The simple example of Sudoku2. Description and Anal
9、ysis We should devise algorithm and metrics of constructing Sudoku puzzles which can be extensible to a varying number of difficulty levels, whats more ensure the unique solution for each Sudoku. The methods of solving the grids are generally classified into the visual-fit method and candidate numbe
10、r method.The visual-fit method is combining the digital available with the rows, columns and palace they arrayed in, and then find the blanks that can decide a unique number. The candidate number method is calculating the number of candidates in some blank. Because the visual-fit method can only aga
11、inst part of the simple Sudoku solution, in the paper we use candidate number method.Our primary aim is making the smallest algorithm complexity while the requirements above are satisfied. In order to guarantee the algorithm complexity minimum, we use the smallest candidate number method. Whats more
12、, to describe levels of Sudoku puzzles, we have difficulty criterion definition.We describe the solving process as a decision tree as figure 2 shows. The numbers (m, n) in the tree nodes, among which m means the blanks of corresponding layout and n means the number of the smallest candidates. If m0
13、and n=0, that means the corresponding layout is a death layout; if m=0 and n=0, that means the corresponding layout is a final layout. This decision tree indicates that the original layout S0 has S1 and S2 two solutions, among which from S1.1 to S1.5 represent the middle layouts of S1 and from S2.1
14、to S2.5 represent the middle layout of S2, While S1.1 is the same as S2.1 and S1.2 is the same as S2.2.Figure 2 Decision tree of solving Sudoku with 6 spaces3. Assumptions1.In this paper, all layouts is a 9 9 grid, dont involve other sizes.2.All statistics about running time have nothing to do with
15、computer, that is to say, programs running time should be same in different computers.3.The running time is embodied by the number of middle layouts between each original layout and its all final layouts. 4. Symbols and Terms4.1 Symbols S: the layout of Sudoku;i: the row number of unit grid;j: the l
16、ine number of unit grid;m: the number of blanks in corresponding layout;n: the number of the smallest candidates;k: the number of layout.4.2 Terms 1Original Layout: the unit grid state at the beginning of the game, include several digital and several spaces;Final Layout: the unit grid state at the e
17、nd of the game, include several digital and no spaces exist;Middle Layout: the unit grid state in the process of finding final layout from the original layout;Death Layout: there are spaces in the layout, but no matter what digital from 1 to 9 falling in the spaces all will conflict with the rules o
18、f the game;Unit grid: the grid that make up by a grid which contain the number from 1 to 9 only once;Candidates: lots of number that can be filled in the unit grid that means the number must be different from the digitals in the same row, same line and the same unit grid; Solution: an original layou
19、t which can find its final layout5. Model Design and Solve5.1 Basic Operation 1Obviously, the layout of Sudoku should be expressed by matrix structure. To describe subsequent algorithm now we devise basic operation as follows:Function Candidates=Check(S,i,j).Function Check use to calculate the candi
20、date number vector of the unit row i line j in S layout. Candidates:Function i,j=Find Candidate(S).Function Find Candidate search the unit i,j which has the smallest candidate number. Suppose there are k spaces in layout S that in the performing of function Find Candidate, there need to invoke k tim
21、es function Check:Function flag = Success(S).Function Success is used to estimate whether S layout is final layout:Function flag = Failed(S).Function Failed is used to estimate whether the S layout is death layout.5.2 The search algorithm based on the minimum number of candidates The Candidates Elim
22、ination Techniques is writing all the digitals that may appear in the blanks first, and then through some commonly used algorithm to cut candidate number until gain the certain unique candidate number. It is widely used in computer generating puzzle and problem solving in practice. This not only bec
23、ause it relatively easy programming, and its algorithm are also growing which make its solving efficiency and ability raise.In order to understand the Candidates Elimination more clearly, we give an example of finding candidates in Sudoku as follow: Figure 3 the example of finding candidatesThe basi
24、c method to solve original layout is using backdating method to illustrate state space exhaustively. But which space should be filled in which digital in each step will influence the state space greatly, and then influence the efficiency of the algorithm. Generally, we think the state space to solve
25、 original layout is a 9 fork tree whose depth is less than 811.Using more fork tree traversal algorithm frame and combine the calculation of the smallest candidates number, we devise algorithm as follows 1.Write original layout as S0, write the first K a layout of the solving process as Sk, and stor
26、e the data structure of middle layout as stack SS. The recursive algorithm of solving all the final layout of Sk describes as follows:1. If that is to say Sk is the final layout, then from S1 to Sk which kept in stack SS are solving processes from original layout to an final layout and return to the
27、 upper function calls;2. If that is to say Sk is a stalemate, so return to the upper function calls;3. Find the smallest candidates unit grids position in Sk that is ;4 . Calculate the candidates vector of position i,j that is Candidates=Check(Sk,i,j);Filling each candidate in the empty grids i,j of
28、 Sk in turn to gain a new layoutSk+1, then put Sk+1 in stack SS and invoke Solve (Sk+1) recursively, after that execute a stack operation. The flow chart of function solve is as follow:Figure 4 the program flowchart of function Solve5.3 The Measurement for Difficulty Grades 2We evaluate the difficul
29、ty of a Sudoku from the logic inference of human and the exhaustive search of computer. Due to the players reasoning to the unknown grids based on the information provided by the known grids, while the known grids quantity and distribution decided how much information they can provided. The less kno
30、wn grids, and its distribution is more uneven, more asymmetry that the logic inference of the Sudoku should be more difficult. Thus to a Sudoku topic, we give three evaluation projects(as chart 1),evaluate it by marking it from 0 to 4,and to give the three projects corresponding weights, then get th
31、e summation scoring of the topic. Use the integer part of the score to weigh the gamers difficulty level need as follows:Grade 1: the score from 0 to 1;Grade 2: the score from 1 to 2;Grade 3: the score from 2 to 3;Grade 4: the score from 3 to 4.Chart 1 evaluation of SudokuscoreProjectsofEvaluation 1234The number of known grids in original layout: k(weights:0.4)From 38 to 45From 31 to 37
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1