本文整理汇总了Python中interpreter.Interpreter.obstacleInWay方法的典型用法代码示例。如果您正苦于以下问题:Python Interpreter.obstacleInWay方法的具体用法?Python Interpreter.obstacleInWay怎么用?Python Interpreter.obstacleInWay使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类interpreter.Interpreter
的用法示例。
在下文中一共展示了Interpreter.obstacleInWay方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from interpreter import Interpreter [as 别名]
# 或者: from interpreter.Interpreter import obstacleInWay [as 别名]
class Policy:
def __init__(self, comm, predictionFactor):
self.comm = comm
self.predictionFactor = predictionFactor
self.intp = Interpreter()
self.tankPlans = {}
def newStatus(self, status):
if not self.processStatus(status):
return
self.intp.statusUpdate(status)
self.doAttacks()
## Check if any tank is in danger, move away (Do predictive calculations by observing past status and extrapolating?)
self.evade()
self.offensivePositioning()
def processStatus(self, status):
if "map" not in status:
print "missing map"
print status
return False
if "players" not in status:
print "missing players"
print status
return False
self.myTanks = []
self.myTankIds = []
self.enemyTanks = []
for player in status["players"]:
if player["name"] == credentials.username:
self.myTanks = player["tanks"]
for tank in self.myTanks:
self.myTankIds.append(tank["id"])
if tank["id"] not in self.tankPlans:
self.tankPlans[tank["id"]] = {"lasti": 0, "lastDirection": 0, "lastAngle": 0, "lastThreat": 0}
else:
self.enemyTanks += player["tanks"]
return True
def gameRefresh(self):
self.tankPlans = {}
self.intp.refresh()
def doAttacks(self):
## Check if any tank should attack
for myTank in self.myTanks:
target = self.intp.whoWouldIShoot(myTank)
# Check that we would be firing at enemy
if target:
if target["id"] not in self.myTankIds:
self.comm.fire(myTank["id"])
else:
self.comm.stop(myTank["id"], "FIRE")
"""
Makes neccessary evasion movements
if evading the "predictedPosition" for the next update is appended to the tank
"""
def evade(self):
for myTank in self.myTanks:
threatGrid = np.zeros(7)
for i in range(7):
if i == 0:
newPosition = myTank["position"]
else:
angle = 2 * np.pi * i / 6
newPosition = mathHelper.getLineEndpoint(myTank["position"], 2 * myTank["hitRadius"], angle)
# TODO: Dodge enemy turrets
enemyThreats = self.intp.getThreatsToA(myTank, self.enemyTanks)
for enemyTank in enemyThreats:
if self.intp.canAshootB(enemyTank["tank"]["id"], myTank["id"]):
strikeDist = mathHelper.distanceBetween(myTank["position"], enemyTank["tank"]["position"])
strikeDist -= self.intp.avgPeriod * enemyTank["tank"]["speed"]
threatGrid[i] = max(1 / strikeDist, threatGrid[i])
for projectile in self.intp.projectiles:
A = projectile["position"]
B = mathHelper.getLineEndpoint(A, projectile["range"], projectile["direction"])
strikeDist = mathHelper.circleOnLine(A, B, newPosition, myTank["hitRadius"])
if strikeDist != False:
threatGrid[i] = max(1 / strikeDist, threatGrid[i])
if self.intp.obstacleInWay(newPosition, myTank["collisionRadius"]):
threatGrid[i] = max(10, threatGrid[i])
i = np.argmin(threatGrid)
# if self.tankPlans[myTank['id']]['lastThreat'] <= threatGrid[i]:
# i = self.tankPlans[myTank['id']]['lasti']
# direction = 0
# myNewAngle = 0
# if i == self.tankPlans[myTank['id']]['lasti'] and i!= 0:
#.........这里部分代码省略.........