本文整理匯總了Python中plan.Plan.action方法的典型用法代碼示例。如果您正苦於以下問題:Python Plan.action方法的具體用法?Python Plan.action怎麽用?Python Plan.action使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類plan.Plan
的用法示例。
在下文中一共展示了Plan.action方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: random_plan
# 需要導入模塊: from plan import Plan [as 別名]
# 或者: from plan.Plan import action [as 別名]
def random_plan(self):
p = Plan()
# Choose start condition AND INSTANTIATE IT:
start_condition = random.choice(p.Conditionals)()
start_condition.height = 1
p.action = start_condition
p.this_conditionals.append(start_condition)
done = False
while not done:
done = True
# Update conditionals if not marked (marked = already dealt with)
# and stop when hitting the max depth
for c in p.this_conditionals:
if c.marked == 0:
done = False
c.marked = 1
# Add a random expression:
expression = random.choice(p.Expressions)()
expression.obs1 = random.choice(p.Observations)
expression.obs2 = random.choice(p.Observations)
expression.depth = c.depth + 1
expression.marked = 1
expression.set_map(p)
c.expression = expression
# Must add terminal actions if we hit the max depth (minus 2)
if c.depth == self.max-2:
for key in c.options.keys():
axn = random.choice(p.Actions)
axn.depth = c.depth + 1
c.options[key] = axn
# Otherwise, we can add either a terminal action OR another conditional:
else:
for key in c.options.keys():
condition_or_action = random.random()
if condition_or_action < .5:
new_c = random.choice(p.Conditionals)()
new_c.depth = c.depth + 1
c.options[key] = new_c
p.this_conditionals.append(new_c)
else:
c.options[key] = random.choice(p.Actions)
return p