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


Python Interpreter.isShotClear方法代码示例

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


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

示例1: __init__

# 需要导入模块: from interpreter import Interpreter [as 别名]
# 或者: from interpreter.Interpreter import isShotClear [as 别名]

#.........这里部分代码省略.........
                if myNewAngle > 2 * np.pi:
                    myNewAngle -= 2 * np.pi

                if myNewAngle != reqAngle:
                    direction = "REV"
                else:
                    direction = "FWD"

                self.comm.move(myTank["id"], direction, 2 * myTank["hitRadius"])

                predictedDist = self.intp.avgPeriod * myTank["speed"]

                myTank["predictedPosition"] = mathHelper.getLineEndpoint(myTank["position"], predictedDist, myNewAngle)

            else:
                myTank["predictedPosition"] = myTank["position"]

            # self.tankPlans[myTank['id']]['lastDirection'] = direction
            # self.tankPlans[myTank['id']]['lasti'] = i
            # self.tankPlans[myTank['id']]['lastAngle'] = myNewAngle
            # self.tankPlans[myTank['id']]['lastThreat'] = threatGrid[i]

    """
    Should only move tanks not with a "predictedPosition" (because evade has already dictated a movement)

    This tries to account for predictedPosition in it's turret placing.
    Basically if we end up using the predicted and not the actual the prediction
    will pretend the enemy is not moving, otherwise the prediction will assume we
    are stationary and that the enmeny will continue to move.  Essentially, either
    way the prediction will overshoot it's exact required rotation by one period's
    to hopefully account for some movement.
    """

    def offensivePositioning(self):
        correlationArr = []
        myPredictedTanks = copy.deepcopy(self.myTanks)
        for myTank in myPredictedTanks:
            # Account for the predicted position
            myTank["actualPosition"] = myTank["position"]
            if "predictedPosition" in myTank:
                myTank["position"] = myTank["predictedPosition"]
            for enTank in self.enemyTanks:
                tempCor = self.intp.correlationAtoB(myTank, enTank)
                if tempCor["distance"] > PROJECTILE_RANGE + self.intp.avgPeriod * enTank["speed"] * 3:
                    tempCor["shootable"] = False
                else:
                    tempCor["shootable"] = self.intp.isShotClear(myTank["position"], enTank["position"])
                tempCor["turretChange"] = mathHelper.smallestAngleBetween(myTank["turret"], tempCor["angle"])
                correlationArr.append(tempCor)
        # Sort the array, smallest abs angle chang first
        correlationArr = sorted(correlationArr, key=lambda entry: np.absolute(entry["turretChange"]))

        remainingAttackers = copy.deepcopy(self.myTankIds)
        usedAttackers = {}
        enemyAttacked = {}
        for entry in correlationArr:
            # Check that the enemy is shootable
            if entry["shootable"]:
                # Check if attacking tank is available
                if entry["tankA"]["id"] not in usedAttackers:
                    # Check that enemy doesn't have too many attackers (max attackers = roundUp(remainingHeath/ProjDmg) + 1)
                    if (
                        entry["tankB"]["id"] not in enemyAttacked
                        or enemyAttacked[entry["tankB"]["id"]]
                        <= np.ceil(entry["tankB"]["health"] / PROJECTILE_DAMAGE) + 1
                    ):
                        # Check that attacker is actually close enough
                        if entry["distance"] < PROJECTILE_RANGE + self.intp.avgPeriod * entry["tankB"]["speed"]:
                            # assign the attaker to the enemy tank
                            remainingAttackers.remove(entry["tankA"]["id"])
                            entry["targetId"] = entry["tankB"]["id"]
                            usedAttackers[entry["tankA"]["id"]] = entry
                            if entry["tankB"]["id"] in enemyAttacked:
                                enemyAttacked[entry["tankB"]["id"]] += 1
                            else:
                                enemyAttacked[entry["tankB"]["id"]] = 0

        # assign any remaining attackers to enemies
        for attacker in remainingAttackers:
            # nobody to fire at so stop firinging
            self.comm.stop(myTank["id"], "FIRE")
            # Find closest enemy via path finding and assign that enemy
            myCorrelations = [cor for cor in correlationArr if cor["tankA"]["id"] == attacker]
            myCorrelations = sorted(myCorrelations, key=lambda entry: entry["distance"])
            for cor in myCorrelations:
                if cor["distance"] < PROJECTILE_RANGE + self.intp.avgPeriod * cor["tankB"]["speed"] * 2:
                    cor["targetId"] = cor["tankB"]["id"]
                    usedAttackers[attacker] = cor
                else:
                    break

            # find closest shootable friend and move somewhat close to them  (like 30 away?)

        # Rotate turret appropriately
        for attacker in usedAttackers:
            # add predicitve factor to rotation
            angleToRotate = usedAttackers[attacker]["turretChange"] * self.predictionFactor
            self.comm.rotateTurret(attacker, angleToRotate)

        return
开发者ID:C0dets,项目名称:PythonPractice,代码行数:104,代码来源:policy.py


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