本文整理汇总了Python中target.Target.createInteraction方法的典型用法代码示例。如果您正苦于以下问题:Python Target.createInteraction方法的具体用法?Python Target.createInteraction怎么用?Python Target.createInteraction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类target.Target
的用法示例。
在下文中一共展示了Target.createInteraction方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from target import Target [as 别名]
# 或者: from target.Target import createInteraction [as 别名]
def main():
# total number of interactions between 1 and infinity
validInter = False # flag for a valid user input
while validInter == False:
try:
totalInter = int(input("Enter total number of interactions (greater than or equal to 1): "))
except ValueError:
print("Do not enter non-numeric values.")
else:
if (totalInter >= 1):
validInter = True
else:
validInteractions = False
print("Input is out of range.")
# Set the target's probability of X or Y
validProb = False # flag for a valid user input
while validProb == False:
try:
probX = int(input("Probability of X-type Interactions for the target (1-100): "))
except ValueError:
print("Do not enter non-numeric values.")
else:
if (1 <= probX <= 100):
validProb = True
else:
validProb = False
print("Input is out of range.")
probY = 100 - probX # probabilty of Y interactions
#DEBUG
DEBUG.dprint("total # interactions: %r" % totalInter)
DEBUG.dprint("probability of X: %r" % probX)
# Pursuer class takes the two probabilities
aPursuer = Pursuer(totalInter)
aTarget = Target(probX, probY)
# Main Loop
i = 0 # flag
while i < totalInter:
# create an interaction for the pursuer and the target
interP = aPursuer.createInteraction()
interT = aTarget.createInteraction()
# DEBUG
DEBUG.dprint("aPursuer Interaction: %r" % interP)
DEBUG.dprint("aTarget Interaction: %r" % interT)
DEBUG.dprint("i: %r" % i)
# record and display the result
result = aPursuer.reportInteraction(interP, interT)
print(result)
i += 1 # update flag
if i >= 2:
aPursuer.adaptBehaviour(interP, interT)
targetX, targetY = aTarget.reportEnd()
aPursuer.reportEnd(targetX, targetY)