这是使用物件导向程式设计来求解数独的程式库
一个链结(chain)是由同个群组中2个以上的空白点组合起来,在这些点上的可被填上的代码总数刚好等于这些点数,所以在同个群组中的其他空白点就不可能被填上这个链结上的所有代码。
数独游戏的整体物件
get the possition list which can see the position, p method: “u”: un-assigned positions, “a”: all, “s”: assigned positions num: if method=”u”, the position must have be possible to be filled the number
reduce the position(x, y)’s possible numbers from v Return:
int, as following
2 -- if set a number,
1 -- if just set number
0 -- if is not in the possible set, if check is True, it will raise an SudokuError exception
数字物件
在数独表中的一个点
一个例外处理,当一个点无法被设定或减掉某个数字(v)时而产生, 其中type 为s 表示为设定动作, r 表示为减掉动作
一个例外处理, 当一个座标列表, [(x1, y1), ...], checkPos 有设定时, 这些点中如有被设定时, 就会引发此事件的处理
Check every number which has been assigned and known as group-number and its effect’s boxes’ does not have assigned that number” Only: False, check all numbers
True, check the first number only
first: the first number to be checked
检查每一个x 轴或y 轴线群组,是否只剩一个点能够填上某个数字
Check every number which has been assigned and its effect’s boxes’ does not have assigned that number Only: False, check all numbers
True, check the first number only
first: the first number to be checked
比较所有的结果列表,比较每个列表从原本最后一笔纪录之后的行动纪录,如果有相同者,则表示每一种状况都会导致这个结果,那此行动就应该是符合逻辑的,可以照做无误
emulate the x, y to be set v, then start to use some basic methods to try to solve it will stop when and return 1: one of the targets have been set the checkval 2: isDone -1: error is True 0: all basic methods have been tested, and can’t solve and the result matrix
When setting a number, may cause 1-3 groups left only one possible position check if a group have only position left, just set it
检查每一个空白点,看是否在可能的数字列表中只剩一个。
when a position(p1) has 2 or more possible numbers, we can emulate every possible number and get its result, 1. if it causes an error, we can reduce that number, 2. if it can solve the sudoku, we can set this number, 3. if all possible number can’s get condition 1 or 2, we can compare their rec, if they have the same records, we can do it.
when a group(lineX, lineY, Box) has 2 or more position have the same possible number, we can emulate every position to set the number and get its result, 1. if it causes an error, we can reduce the position’s possible number from that number, 2. if it can solve the sudoku, we can set this number in the position, 3. if all possible position can’s get condition 1 or 2, we can compare their rec, if they have the same records, we can do it.
当一个点(p1)只有两个能数时,我们可以先假设这个点其中一数(设为first),然后将此点设为另外一数(设为second)来模拟f求解,看这求解过程中,first这个数落在哪些点上,那对所落的点与p1有所交集(两个点都能看见)的空白点而言,都不可能存在填入first这个数的可能,而可以让这些点将这个可能数消除。
Check is there an more obvious method for the position, p1 than method1 Obvious methods include fillLastPostionOfGroup=0 and checkObviousNumber=1 return: True: set, False: not set
Solve a sudoku which define in a file! loopLimit: the limit for the method loops, 0: no limits recLimit: when the records >= recLimit, it will stop, 0: no limits
Try Error Method, only fill the first possible postion
= 0)。”检查与更新Matrix 物件(m)的链结状况与资讯,并取得链节总数(= 0)。
Update the group number, num, in a box, and store those group number in m.n.group list return: >=0 means the group number’s amount in the matrix, m