本文整理汇总了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