資源簡介
8數碼問題的python解決方案(代碼)
代碼片段和文件信息
from?queue?import?Queue
import?copy
‘‘‘設置數據結構‘‘‘
class?Node:
????layout=[]
????depth=-1
????parent=None
????price=-1
????def?__init__(selfparentlayout=[]depth=-1price=-1):
????????self.layout=layout
????????self.depth=depth
????????self.parent=parent
????????self.price=price
????def?__repr__(self):
????????‘‘‘用來定義Node的字符輸出,print為輸出data‘‘‘
????????if?len(self.layout)==3:
????????????string=str(self.layout[0])+‘\n‘+str(self.layout[1])+‘\n‘+str(self.layout[2])
????????????return?string
????????else:
????????????return?str(self.layout)
????def?setLayout(selflayout):
????????self.layout=layout
????????return?layout
????def?setDeepth(selfdeepth):
????????self.depth=deepth
????????return?deepth
????def?setParent(selfparent):
????????self.parent=parent
????????return?parent
????def?setPrice(selfprice):
????????self.price=price
????????return?price
????def?hasParent(self):
????????return?self.parent?is?not?None
????def?toString(self):
?
- 上一篇:機器學習神經網絡資源
- 下一篇:python 多張圖片黑底白字轉白底黑字
評論
共有 條評論