You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.2 KiB
42 lines
1.2 KiB
# -*- encoding: utf-8 -*-
|
|
'''
|
|
@File : slove_show.py
|
|
@License : (C)Copyright 2018-2022
|
|
|
|
@Modify Time @Author @Version @Desciption
|
|
------------ ------- -------- -----------
|
|
2022/12/28 11:50 zart20 1.0 None
|
|
'''
|
|
import numpy as np
|
|
martix = np.load("martix.npy")
|
|
from gameui import *
|
|
from data import *
|
|
from opera import *
|
|
form = GuiForm()
|
|
|
|
|
|
def Solve_show(martix):
|
|
"""求解数组"""
|
|
# refresh(form, martix, [])
|
|
# time.sleep(1)
|
|
for row in range(9):
|
|
for col in range(9):
|
|
if martix[row, col] == 0:
|
|
possible = GetPossible(martix, row, col) # 所有的可能的数字
|
|
for value in possible:
|
|
martix[row, col] = value # 将可能的数组填入
|
|
refresh(form,martix, martix, [])
|
|
time.sleep(0.5)
|
|
if Solve_show(martix): # 继续深度优先遍历填入数字
|
|
|
|
return True # 填完最后一个数字
|
|
|
|
martix[row, col] = 0 # 如果当前填入的数字会导致后面无解则依然填入0表示空白待填
|
|
return False
|
|
# 当所有的数字填完,数独求解完毕
|
|
|
|
return True
|
|
|
|
Solve_show(martix)
|
|
|
|
print(martix) |