本文整理汇总了Python中node.Node.setParent方法的典型用法代码示例。如果您正苦于以下问题:Python Node.setParent方法的具体用法?Python Node.setParent怎么用?Python Node.setParent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类node.Node
的用法示例。
在下文中一共展示了Node.setParent方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setParent
# 需要导入模块: from node import Node [as 别名]
# 或者: from node.Node import setParent [as 别名]
def setParent(self, parent):
if not parent:
if self.gui:
parent = self.gui.anchors["Center", "Center"]
else:
parent = render2d
Node.setParent(self, parent)
示例2: setParent
# 需要导入模块: from node import Node [as 别名]
# 或者: from node.Node import setParent [as 别名]
def setParent(self, parent):
if not parent and self.world:
parent = self.world.scene
Node.setParent(self, parent)
示例3: Node
# 需要导入模块: from node import Node [as 别名]
# 或者: from node.Node import setParent [as 别名]
checklisttime = 0
#Initial Node
n = Node(current, None)
queueofmoves.append(n)
closedlist = set(n.getStateBoardStringForHash())
#Search for a win at the beginning of the frontier
while not queueofmoves[0].state.isAWin():
print "Frontier: ", len(queueofmoves)
print "Closed: ", len(closedlist)
q = queueofmoves[0]
queueofmoves.popleft()
for a in q.state.whatCanMove():
n = Node(q.state.doAction(a), a)
#Check if the boards string rep is in the closed list
if n.getStateBoardStringForHash() not in closedlist:
n.setParent(q)
q.addChild(n)
queueofmoves.append(n)
closedlist.add(n.getStateBoardStringForHash())
elapsedtime = time.time() - elapsedtime
#Prepare and output moves
endmoves = [queueofmoves[0]]
currentnode = queueofmoves[0]
while currentnode.parent is not None:
moves = moves + 1
endmoves.append(currentnode.parent)
currentnode = currentnode.parent
print "The time it took for BFGS is", elapsedtime, "seconds."
print "The AI won, in", moves, "moves!"
raw_input("Press enter to see the moves taken!")
endmoves.pop()
示例4: HValueFromDistanceAndNumCars
# 需要导入模块: from node import Node [as 别名]
# 或者: from node.Node import setParent [as 别名]
print "We are going to do an A* Search on", boardname
current.printDisplay()
elapsedtime = time.time()
pqueue = []
pqueue.append(Node(current, None, 0, HValueFromDistanceAndNumCars(current)))
closedset = dict()
#Search for a win at the beginning of the frontier
while not pqueue[0].state.isAWin():
currentnode = pqueue.pop(0)
closedset[currentnode] = currentnode.depth
for a in currentnode.state.whatCanMove():
newstate = currentnode.state.doAction(a)
newnode = Node(newstate, a, currentnode.depth + 1, \
HValueFromDistanceAndNumCars(newstate))
if newnode not in closedset:
newnode.setParent(currentnode)
pqueue.append(newnode)
closedset[newnode] = newnode.depth
elif newnode in closedset and newnode.depth < closedset[newnode] :
if newnode in pqueue:
pqueue[pqueue.index(newnode)].depth = newnode.depth
pqueue[pqueue.index(newnode)].setParent(currentnode)
else:
newnode.setParent(currentnode)
pqueue.append(newnode)
closedset[newnode] = newnode.depth
pqueue.sort()
elapsedtime = time.time() - elapsedtime
#Prepare and output moves
示例5: Node
# 需要导入模块: from node import Node [as 别名]
# 或者: from node.Node import setParent [as 别名]
# print a
#Search for a win at the beginning of the frontier
while not stackofmoves[-1].state.isAWin():
s = stackofmoves[-1]
stackofmoves.pop()
#See if the current nodes depth is less than the iteration level
#If it is, we can still expand
if s.depth < iterationlevel:
for a in s.state.whatCanMove():
n = Node(s.state.doAction(a), a, s.depth + 1)
#Check if the boards string rep is in the closed list
if n.getStateBoardStringForHash() not in closedlist:
n.setParent(s)
s.addChild(n)
stackofmoves.append(n)
closedlist.add(n.getStateBoardStringForHash())
if len(stackofmoves) == 0:
s = []
stackofmoves = []
n = Node(current, None, 0)
closedlist = set()
closedlist.add(n.getStateBoardStringForHash())
stackofmoves.append(n)
iterationlevel += 1
elapsedtime = time.time() - elapsedtime
#Prepare and output moves
endmoves = [stackofmoves[-1]]
示例6: setParent
# 需要导入模块: from node import Node [as 别名]
# 或者: from node.Node import setParent [as 别名]
def setParent(self, parent):
if not parent:
parent = render
Node.setParent(self, parent)