本文整理匯總了Python中PriorityQueue.PriorityQueue.clean方法的典型用法代碼示例。如果您正苦於以下問題:Python PriorityQueue.clean方法的具體用法?Python PriorityQueue.clean怎麽用?Python PriorityQueue.clean使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類PriorityQueue.PriorityQueue
的用法示例。
在下文中一共展示了PriorityQueue.clean方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: FindDirections
# 需要導入模塊: from PriorityQueue import PriorityQueue [as 別名]
# 或者: from PriorityQueue.PriorityQueue import clean [as 別名]
def FindDirections(self, curState):
pq = PriorityQueue(["dist", "changeDir"])
pq.add({"state": curState, "prev": None, "dist": 0 + self.heuristics(curState), "changeDir": 0, "step": 0})
cnt = 0
while True:
elem = pq.pop()
#print("Dir:", elem["state"].snake.curDir, "step:", elem["step"], "cnt: ", cnt)
ok_dirs = self._get_ok_dirs_(elem["state"])
#print ok_dirs
for d in ok_dirs:
nextState = elem["state"].GetNextState(d)
step = elem["step"] + 1
changeDir = 0
if d != elem["state"].snake.curDir:
changeDir = 1
dist = step + self.heuristics(nextState)
pq.add({"state": nextState, "prev": elem, "dist": dist, "changeDir":changeDir, "step": step} )
#if elem["step"] % 10 == 0:
# print elem["step"]
if pq.IsEmpty():
print "EMPTY!!!!", elem["step"]
if len(pq.storage) > 0:
elem = pq.storage.pop(0)
pq.add(elem)
"""
while len(pq.storage) > 0:
other = pq.storage.pop()
print other["step"], elem["step"]
if abs(other["step"] - elem["step"]) < elem["step"] * 0.1:
break
"""
print elem["state"].IsAppleEaten(), elem["state"].apple.GetApplePos()
#pq.add(other)
cnt += 1
if cnt >= 2000 or self._is_goal(elem["state"]) and elem["step"] > 0:
#print("step:", elem["step"], "cnt:", cnt, "empty:", pq.IsEmpty())
pq.clean()
while True:
self.directions.append(elem["state"].snake.curDir)
elem = elem["prev"]
if elem is None:
break
self.directions.pop() # remove the first direction (the state that already take a step)
return self.directions