# 程式详解: sudoku套件¶

class sudoku.sudoku.Box(idx, p)[源代码]

Box

get_group_number(num, pos=, []notInLineX=None, notInLineY=None)[源代码]

class sudoku.sudoku.Chain(numList, posList)[源代码]

class sudoku.sudoku.GroupNumber(b, num, p, direction, idx)[源代码]

class sudoku.sudoku.LineX(idx, p)[源代码]

x 轴线群组

class sudoku.sudoku.LineY(idx, p)[源代码]

y 轴线群组

class sudoku.sudoku.Matrix(file='')[源代码]

allow(x, y, v)[源代码]

can_see(p0, method='u', num=0)[源代码]

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

get_all_pos(diff=, []method='a', num=0, chain=None, possibles=None)[源代码]

get all postion

print_rec()[源代码]

reduce(x, y, v, d='set', check=False, info='')[源代码]

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
```
setit(x, y, v, d='define', info='')[源代码]

set the position x, y to be the number v return: >=1 if set successfully, 0 if it can’t be set the number v

sort_unassigned_pos_by_possibles(possibles=0)[源代码]

Get unassign position’s possible number list, format is [p1, p2,...] and Sorted By the possible numbers possibles: 0 for all, >=2, mean get only the possible numbers for it

class sudoku.sudoku.Number(v)[源代码]

can_see_by_group_number(p1)[源代码]

Check if the position, p1, can be seen of all this number’s group number” return: gn if can be seen by it, or None

setit(p1)[源代码]

class sudoku.sudoku.Point(x, y)[源代码]

can_see(p1)[源代码]

this position can see p1? the value can’t be 3 or 7 it means the same pos rtn: 0: can’t see p1

1: can see it in x line 2: can see it in y line 4: can see it in the box
can_see_those(posList)[源代码]

check this position can see which positions in the posList, a [(x, y),...] list

class sudoku.sudoku.SolveMethod(fun, idx, name='', level=0, obvious=True)[源代码]

exception sudoku.sudoku.SudokuDone(x, y, v)[源代码]

exception sudoku.sudoku.SudokuError(x, y, v, t)[源代码]

exception sudoku.sudoku.SudokuStop[源代码]

exception sudoku.sudoku.SudokuWhenPosSet(x, y, v)[源代码]

sudoku.sudoku.check_inobvious_number(m, first=1, only=False)[源代码]

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

sudoku.sudoku.check_line_last_possible_for_number(m, first=1, only=False)[源代码]

sudoku.sudoku.check_obvious_number(m, first=1, only=False)[源代码]

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

sudoku.sudoku.compare_result(m, emu, result)[源代码]

sudoku.sudoku.emulator(m, x, y, v, targets=, []checkval=0)[源代码]

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

sudoku.sudoku.fill_last_position_by_setting(m, sets)[源代码]

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

sudoku.sudoku.fill_last_position_of_group(m, first=1, only=False)[源代码]

sudoku.sudoku.fill_only_one_possible(m, first=1, only=False)[源代码]

Args:
m: Matrix Object first (int): the first number of checking only (bool): just check the first number or not
Returns:
in the tuple format (sets, reduces, method Index to restart using, first, only)
sudoku.sudoku.guess(m, idx=0, first=0, only=False)[源代码]

Guess Method

sudoku.sudoku.reduce_by_emulate_possible_in_one_position(m, first=1, only=False)[源代码]

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.

sudoku.sudoku.reduce_by_emulate_possible_number_in_group(m, first=1, only=False)[源代码]

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.

sudoku.sudoku.reduce_by_group_number(m, first=1, only=False)[源代码]

sudoku.sudoku.reduce_by_two_possible_in_one_position(m, first=1, only=False)[源代码]

sudoku.sudoku.reg_method()[源代码]

sudoku.sudoku.set_obvious_method_for_pos(m, method1, p1, v)[源代码]

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

sudoku.sudoku.solve(file, loop_limit=0, rec_limit=0, check=None, level_limit=0, emu_limits=2, use_try=True, use_emu=False)[源代码]

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

sudoku.sudoku.try_error(m=None, file='', depth=0)[源代码]

Try Error Method, only fill the first possible postion

sudoku.sudoku.update_chain(m, first=1, only=False)[源代码]

= 0)。”检查与更新Matrix 物件(m)的链结状况与资讯，并取得链节总数(= 0)。

sudoku.sudoku.update_group_number(m, num)[源代码]

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

sudoku.sudoku.update_indirect_group_number(m, num, amt=0, start=0, first=1, only=False)[源代码]

Update in-direct Group Number, formed by the assigned number and groupnumber already known, a recursive function

sudoku.sudoku.write_down_possible(m, first=1, only=False)[源代码]