当前位置: 首页>>代码示例>>Python>>正文


Python Interpreter.statusUpdate方法代码示例

本文整理汇总了Python中interpreter.Interpreter.statusUpdate方法的典型用法代码示例。如果您正苦于以下问题:Python Interpreter.statusUpdate方法的具体用法?Python Interpreter.statusUpdate怎么用?Python Interpreter.statusUpdate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在interpreter.Interpreter的用法示例。


在下文中一共展示了Interpreter.statusUpdate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from interpreter import Interpreter [as 别名]
# 或者: from interpreter.Interpreter import statusUpdate [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:
#.........这里部分代码省略.........
开发者ID:C0dets,项目名称:PythonPractice,代码行数:103,代码来源:policy.py


注:本文中的interpreter.Interpreter.statusUpdate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。