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


Python Location.distTo方法代码示例

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


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

示例1: notTowardOurGoal

# 需要导入模块: from objects import Location [as 别名]
# 或者: from objects.Location import distTo [as 别名]
    def notTowardOurGoal(self, kick):
        # do not kick into our goalbox
        ball = self.brain.ball

        inBox = (
            ball.x > nogginC.GREEN_PAD_X
            and ball.x < nogginC.BLUE_GOALBOX_RIGHT_X
            and ball.y < nogginC.BLUE_GOALBOX_TOP_Y
            and ball.y > nogginC.BLUE_GOALBOX_BOTTOM_Y
        )
        intoBox = (
            kick.destinationX > nogginC.GREEN_PAD_X
            and kick.destinationX < nogginC.BLUE_GOALBOX_RIGHT_X
            and kick.destinationY < nogginC.BLUE_GOALBOX_TOP_Y
            and kick.destinationY > nogginC.BLUE_GOALBOX_BOTTOM_Y
        )

        print "inBox returned"
        if intoBox and not inBox:
            return False

        else:
            goalCenter = Location(nogginC.FIELD_WHITE_LEFT_SIDELINE_X, nogginC.MIDFIELD_Y)
            ball = Location(ball.x, ball.y)
            kickDestination = Location(kick.destinationX, kick.destinationY)

            return goalCenter.distTo(ball) < goalCenter.distTo(kickDestination)
开发者ID:nbitesGuest,项目名称:nbites,代码行数:29,代码来源:KickDecider.py

示例2: flipLocFilter

# 需要导入模块: from objects import Location [as 别名]
# 或者: from objects.Location import distTo [as 别名]
    def flipLocFilter(self):
        """
        Check where the goalie sees the ball and where we do.
        Record if we're generally correct, or if our flipped location
        is generally correct, or if neither one agrees with the goalie.
        NOTE: ignore whenever the ball is in the middle 2x2 meter box.
        """
        # Get goalie data
        for mate in self.teamMembers:
            if mate.isDefaultGoalie() and mate.active:
                if mate.ballOn and self.ball.vis.on:
                    # calculate global ball coordinates
                    # note: assume goalie is in center of goal.
                    goalie_x = Constants.FIELD_WHITE_LEFT_SIDELINE_X
                    goalie_y = Constants.MIDFIELD_Y

                    ball_x = goalie_x + (mate.ballDist * math.cos(mate.ballBearing))
                    ball_y = goalie_y + (mate.ballDist * math.sin(mate.ballBearing))
                    goalie_ball_location = Location(ball_x, ball_y)

                    # check against my data
                    my_ball_location = Location(self.ball.x, self.ball.y)
                    flipped_ball_location = Location(Constants.FIELD_GREEN_WIDTH - self.ball.x,
                                                     Constants.FIELD_GREEN_HEIGHT - self.ball.y)

                    if (mate.ballDist < 250 and
                        self.loc.x > Constants.MIDFIELD_X and
                        self.ball.x > Constants.MIDFIELD_X):
                        # I'm probably flipped!
                        self.updateFlipFilters(-1)

                        print "Goalie saw the ball close, and I think I and it are far."
                        print "Goalie sees ball at: " + str(goalie_ball_location)

                        break

                    if (goalie_ball_location.inCenterCenter() or
                        my_ball_location.inCenterCenter()):
                        # Ball is too close to the middle of the field. Risky.
                        self.updateFlipFilters(0)
                        break

                    if my_ball_location.distTo(goalie_ball_location) < 70:
                        # I'm probably in the right place!
                        self.updateFlipFilters(1)
                    elif flipped_ball_location.distTo(goalie_ball_location) < 70:
                        # I'm probably flipped!
                        self.updateFlipFilters(-1)
                    else:
                        # I don't agree with the goalie. Ignore.
                        self.updateFlipFilters(0)

        # If I've decided I should flip enough times, actually do it.
        if (len(self.flipFilter) == 10 and
            sum(self.flipFilter) > 6):
            self.flipLoc()
            # Reset filters! Don't want to flip again next frame.
            self.noFlipFilter = []
            self.flipFilter = []
开发者ID:northern-bites,项目名称:nbites,代码行数:61,代码来源:Brain.py

示例3: searchFieldForFlippedSharedBall

# 需要导入模块: from objects import Location [as 别名]
# 或者: from objects.Location import distTo [as 别名]
def searchFieldForFlippedSharedBall(player):
    """
    Flips the shared ball and searches for it.
    """
    sharedball = Location(-1*(player.brain.sharedBall.x-NogginConstants.MIDFIELD_X) + NogginConstants.MIDFIELD_X,
                          -1*(player.brain.sharedBall.y-NogginConstants.MIDFIELD_Y) + NogginConstants.MIDFIELD_Y)

    if player.firstFrame():
        player.brain.tracker.trackBall()
        player.brain.tracker.repeatWideSnapPan()
        player.sharedBallCloseCount = 0
        player.brain.nav.goTo(sharedball, precision = nav.GENERAL_AREA,
                              speed = speeds.SPEED_EIGHT, avoidObstacles = True,
                              fast = True, pb = False)

    if sharedball.distTo(player.brain.loc) < 100:
        player.sharedBallCloseCount += 1
    else:
        player.sharedBallCloseCount = 0

    if not transitions.shouldFindSharedBall(player):
        player.sharedBallOffCount += 1
    else:
        player.sharedBallOffCount = 0

    player.brain.nav.updateDest(sharedball)
开发者ID:northern-bites,项目名称:nbites,代码行数:28,代码来源:PlayOffBallStates.py

示例4: searchFieldForSharedBall

# 需要导入模块: from objects import Location [as 别名]
# 或者: from objects.Location import distTo [as 别名]
def searchFieldForSharedBall(player):
    """
    Searches the field for the shared ball.
    """
    sharedball = Location(player.brain.sharedBall.x, player.brain.sharedBall.y)

    if player.firstFrame():
        player.brain.tracker.trackBall()
        player.brain.tracker.repeatWideSnapPan()
        player.sharedBallCloseCount = 0
        player.sharedBallOffCount = 0
        player.brain.nav.goTo(sharedball, precision = nav.GENERAL_AREA,
                              speed = speeds.SPEED_EIGHT, avoidObstacles = True,
                              fast = True, pb = False)

    if sharedball.distTo(player.brain.loc) < 100:
        player.sharedBallCloseCount += 1
    else:
        player.sharedBallCloseCount = 0

    if not transitions.shouldFindSharedBall(player):
        player.sharedBallOffCount += 1
    else:
        player.sharedBallOffCount = 0

    player.brain.nav.updateDest(sharedball)
开发者ID:northern-bites,项目名称:nbites,代码行数:28,代码来源:PlayOffBallStates.py

示例5: obstacleAware

# 需要导入模块: from objects import Location [as 别名]
# 或者: from objects.Location import distTo [as 别名]
    def obstacleAware(self, clearing=False):
        motionKicksOnGoal = self.motionKicksAsapOnGoal()
        if motionKicksOnGoal:
            return motionKicksOnGoal

        # if self.checkObstacle(1, 75):
        #     inScrum = self.motionKicksInScrumAsap()
        #     if inScrum:
        #         return inScrum

        if not self.checkObstacle(1, 215) and not self.checkObstacle(1, 215) and not self.checkObstacle(8, 215):
            goalCenter = Location(nogginC.FIELD_WHITE_RIGHT_SIDELINE_X, nogginC.MIDFIELD_Y)
            ball = Location(self.brain.ball.x, self.brain.ball.y)
            if ball.distTo(goalCenter) <= 400:
                timeAndSpace = self.frontKicksOrbitIfSmall()
                if timeAndSpace:
                    return timeAndSpace
            elif clearing:
                clear = self.frontKicksClear()
                if clear:
                    return clear

        asap = self.motionKicksAsap()
        if asap:
            return asap

        return self.frontKickCrosses()
开发者ID:nbitesGuest,项目名称:nbites,代码行数:29,代码来源:KickDecider.py

示例6: shouldKickOff

# 需要导入模块: from objects import Location [as 别名]
# 或者: from objects.Location import distTo [as 别名]
 def shouldKickOff(self):
     """
     Tells the decider if we should kickOff. Also sets the player constant.
     """
     if self.brain.player.shouldKickOff:
         centerField = Location(NogginConstants.CENTER_FIELD_X,
                                NogginConstants.CENTER_FIELD_Y)
         self.brain.player.shouldKickOff = (centerField.distTo(self.brain.ball) <
                                            NogginConstants.CENTER_CIRCLE_RADIUS)
         return self.brain.player.shouldKickOff
     else:
         return False
开发者ID:gnmerritt,项目名称:nbites,代码行数:14,代码来源:KickInformation.py

示例7: timeForSomeHeroics

# 需要导入模块: from objects import Location [as 别名]
# 或者: from objects.Location import distTo [as 别名]
    def timeForSomeHeroics(self):
        asapOnGoal = self.allKicksIncludingBigKickAsapOnGoal()
        if asapOnGoal:
            return asapOnGoal

        # TODO hack for Brazil
        goalCenter = Location(nogginC.FIELD_WHITE_RIGHT_SIDELINE_X, nogginC.MIDFIELD_Y)
        ball = Location(self.brain.ball.x, self.brain.ball.y)
        if ball.distTo(goalCenter) <= 200:
            return self.frontKicksOrbit()

        return self.bigKicksOrbit()
开发者ID:emamanto,项目名称:nbites,代码行数:14,代码来源:KickDecider.py

示例8: findStrikerHome

# 需要导入模块: from objects import Location [as 别名]
# 或者: from objects.Location import distTo [as 别名]
def findStrikerHome(ball, hh):
    if not hasattr(findStrikerHome, 'upperHalf'):
        findStrikerHome.upperHalf = (ball.y - NogginConstants.CENTER_FIELD_Y) >= 0 

    # the buffer zone is twice this because its this distance on each side of midfield
    # the buffer keeps us from oscillating sides of the field when the ball is near the center line
    oscBuff = 50
    if findStrikerHome.upperHalf and (ball.y - NogginConstants.CENTER_FIELD_Y) < -1*oscBuff:
        findStrikerHome.upperHalf = False
    elif not findStrikerHome.upperHalf and (ball.y - NogginConstants.CENTER_FIELD_Y) > oscBuff:
        findStrikerHome.upperHalf = True

    goalCenter = Location(NogginConstants.FIELD_WHITE_RIGHT_SIDELINE_X, NogginConstants.MIDFIELD_Y)
    ballToGoal = Location(goalCenter.x - ball.x, goalCenter.y - ball.y) # vector

    # avoid divide by zeros
    if ballToGoal == Location(0, 0):
        ballToGoal = Location (1, 0)

    # the point at which we draw our normal vector from
    percentageToPivot = 0.8
    pivotPoint = Location(ball.x + ballToGoal.x*0.7, ball.y + ballToGoal.y*0.7)

    # two possible normal vectors. If ball.y is greater than midfield.y choose (dy, -dx)
    # else choose (-dy, dx)
    if findStrikerHome.upperHalf:
        normalVect = Location(ballToGoal.y, -1*ballToGoal.x)
    else:
        normalVect = Location(-1*ballToGoal.y, ballToGoal.x)

    # normalize the vector and make its magnitude to the desired value
    normalVectLength = 100
    normalizeMag = normalVectLength/normalVect.distTo(Location(0,0))
    normalVect.x *= normalizeMag
    normalVect.y *= normalizeMag

    strikerHome = RobotLocation(pivotPoint.x + normalVect.x , pivotPoint.y + normalVect.y, hh)

    # if for some reason you get placed off the field project back onto the field
    if strikerHome.x > NogginConstants.FIELD_WHITE_RIGHT_SIDELINE_X - 20:
        strikerHome.x = NogginConstants.FIELD_WHITE_RIGHT_SIDELINE_X - 20

    return strikerHome
开发者ID:northern-bites,项目名称:nbites,代码行数:45,代码来源:SupporterConstants.py

示例9: forwardProgress

# 需要导入模块: from objects import Location [as 别名]
# 或者: from objects.Location import distTo [as 别名]
    def forwardProgress(self, kick):
        goalCenter = Location(nogginC.FIELD_WHITE_RIGHT_SIDELINE_X, nogginC.MIDFIELD_Y)
        ball = Location(self.brain.ball.x, self.brain.ball.y)
        kickDestination = Location(kick.destinationX, kick.destinationY)

        return goalCenter.distTo(ball) > goalCenter.distTo(kickDestination)
开发者ID:coryalini,项目名称:nbites,代码行数:8,代码来源:KickDecider.py


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