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


Python RoleConstants.isGoalie方法代码示例

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


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

示例1: determineRole

# 需要导入模块: import RoleConstants [as 别名]
# 或者: from RoleConstants import isGoalie [as 别名]
def determineRole(player):
    if not player.roleSwitching:
        return player.goLater(player.gameState)

    openSpaces = [True, True, True, True]
    for mate in player.brain.teamMembers:
        if mate.playerNumber == player.brain.playerNumber:
            continue
        if not roleConstants.isGoalie(mate.role) \
                and mate.frameSinceActive < 30:
            openSpaces[mate.role - 2] = False

    position = 0

    for i in range(4):
        if openSpaces[i] and roleConstants.canRoleSwitchTo(i+2):
            roleConstants.setRoleConstants(player, i+2)
            return player.goLater(player.gameState)
        elif openSpaces[i]:
            position = i+2

    if position == 0:
        print "Came out of penalty and found no open spaces!!!"

    roleConstants.setRoleConstants(player, i+2)
    return player.goLater(player.gameState)
开发者ID:dnav6987,项目名称:nbites,代码行数:28,代码来源:PenaltyStates.py

示例2: afterPenalty

# 需要导入模块: import RoleConstants [as 别名]
# 或者: from RoleConstants import isGoalie [as 别名]
def afterPenalty(player):

    if player.firstFrame():

        if DEBUG_PENALTY_STATES:
            print "Entering the 'afterPenalty' state."

        # pan for the ball
        player.brain.tracker.repeatWidePan()
        
        # reset state specific counters
        afterPenalty.goalLeft = 0
        afterPenalty.reset_loc = 0

    lines = player.brain.visionLines

    # Do we see the top of the goalbox
    for i in range(0, lines.line_size()):
        if lines.line(i).id == LineID.TopGoalbox:
            topGoalBox = lines.line(i).inner
            leftAngle = fabs(topGoalBox.t - pi) < .25
            # Goalbox to the left = 1 to the right = -1
            toLeft = 1 if leftAngle else -1
            afterPenalty.goalLeft += toLeft

    # If we've seen any landmark enough, reset localization.
    if fabs(afterPenalty.goalLeft) > OBJ_SEEN_THRESH:
        if DEBUG_PENALTY_STATES:
            print "Saw goalbox enough times"
        afterPenalty.reset_loc = copysign(1, afterPenalty.goalLeft)

    # Send the reset loc command.
    if afterPenalty.reset_loc != 0:
        if DEBUG_PENALTY_STATES:
            print "Sufficient sightings. reset_loc value is: " + str(afterPenalty.reset_loc)
        afterPenalty.goalLeft += afterPenalty.reset_loc
        afterPenalty.reset_loc = 0

    if fabs(afterPenalty.goalLeft) > 5 or player.stateTime > 15:
        if DEBUG_PENALTY_STATES:
            print "Consensus reached! Resetting loc. Is the goal to our right? " + str(afterPenalty.goalLeft < 0)
        # Yes, when goal_right is less than 0, our goal is to our right.
        # It seems counter intuitive, but that's how it works. -Josh Z
        if afterPenalty.goalLeft > 0:
            print "Goal is to left. Coming out of penalty"
        else:
            print "Goal is to right. Coming out of penalty"
        player.brain.resetLocalizationFromPenalty(afterPenalty.goalLeft < 0)
        if not roleConstants.isGoalie(player.role):
            return player.goNow('walkOut')
        return player.goLater(player.gameState)

    return player.stay()
开发者ID:joshimhoff,项目名称:nbites,代码行数:55,代码来源:PenaltyStates.py

示例3: afterPenalty

# 需要导入模块: import RoleConstants [as 别名]
# 或者: from RoleConstants import isGoalie [as 别名]
def afterPenalty(player):
    if player.brain.penalizedHack:
        return player.goLater(player.gameState)


    if player.firstFrame():
        if DEBUG_PENALTY_STATES:
            print "Entering the 'afterPenalty' state."

        afterPenalty.right = True
        afterPenalty.decidedSide = False
        player.brain.tracker.lookToAngle(-1 * angle)

        # state specific counters
        afterPenalty.rightDiff = 0
        afterPenalty.leftDiff = 0
        afterPenalty.cornerCOn = 0
        afterPenalty.cornerTOn = 0
        afterPenalty.cornerFrames = 0
        afterPenalty.stateCount = 0

    afterPenalty.stateCount += 1
    vis = player.brain.vision

    # Alternate between looking right and left
    if afterPenalty.stateCount % 70 == 0:
        if afterPenalty.right:
            afterPenalty.rightDiff += afterPenalty.cornerCOn - afterPenalty.cornerTOn
            if DEBUG_PENALTY_STATES:
                print "After Penalty right Diff: ", afterPenalty.rightDiff, " cOn: ", afterPenalty.cornerCOn, " tOn: ", afterPenalty.cornerTOn
            player.brain.tracker.lookToAngle(angle)
        else:
            player.brain.tracker.lookToAngle(-1* angle)
            afterPenalty.leftDiff += afterPenalty.cornerCOn - afterPenalty.cornerTOn
            if DEBUG_PENALTY_STATES:
                print "After Penalty left Diff: ", afterPenalty.leftDiff, " cOn: ", afterPenalty.cornerCOn, " tOn: ", afterPenalty.cornerTOn
        afterPenalty.right = not afterPenalty.right
        # Reset counters
        afterPenalty.cornerCOn = 0
        afterPenalty.cornerTOn = 0
        # afterPenalty.cornerFrames = 0

    foundCorner = False

    # Only count if we're looking right/left. Don't want to count goalbox corners
    if player.brain.tracker.isStopped():
        afterPenalty.cornerFrames += 1
        for i in range(0, vis.corner_size()):
            corner = vis.corner(i)
            if corner.id == 2:
                afterPenalty.cornerTOn += 1
            else:
                afterPenalty.cornerCOn += 1

    # China hack 2015. Please make this better
    if afterPenalty.stateCount > 140:
        if afterPenalty.rightDiff > 5 and afterPenalty.leftDiff <= 0:
            afterPenalty.decidedSide = True
            afterPenalty.right = True
        elif afterPenalty.rightDiff < -5 and afterPenalty.leftDiff >= 0:
            afterPenalty.decidedSide = True
            afterPenalty.right = False
        elif afterPenalty.leftDiff > 5 and afterPenalty.rightDiff <= 0:
            afterPenalty.decidedSide = True
            afterPenalty.right = False
        elif afterPenalty.leftDiff < -5 and afterPenalty.rightDiff >= 0:
            afterPenalty.decidedSide = True
            afterPenalty.right = True

    if afterPenalty.decidedSide or afterPenalty.stateCount > 300:
        player.brain.resetLocalizationFromPenalty(afterPenalty.right)
        if DEBUG_PENALTY_STATES:
            print "We've decided! ", afterPenalty.right, " LeftDiff: ", afterPenalty.leftDiff, " Right Diff: ", afterPenalty.rightDiff, " StateCount: ", afterPenalty.stateCount

        player.brain.tracker.repeatWidePan()

        if not roleConstants.isGoalie(player.role):
            return player.goNow('walkOut')
        return player.goLater(player.gameState)

    return player.stay()
开发者ID:dnav6987,项目名称:nbites,代码行数:83,代码来源:PenaltyStates.py

示例4: afterPenalty

# 需要导入模块: import RoleConstants [as 别名]
# 或者: from RoleConstants import isGoalie [as 别名]
def afterPenalty(player):

    if player.firstFrame():
        if DEBUG_PENALTY_STATES:
            print "Entering the 'afterPenalty' state."

        # Hackity Hackity Hack. Determine if we've been manually positioned or are actually coming out of penalty
        if player.brain.penalizedHack:
            closeRatio = player.brain.penalizedEdgeClose / float(player.brain.penalizedCount)
            print "Close ratio is: ", closeRatio
            if closeRatio < .5:
                player.brain.resetLocToCross()
                return player.goLater(player.gameState)

        afterPenalty.right = True
        afterPenalty.decidedSide = False
        player.brain.tracker.lookToAngle(-1 * angle)

        # state specific counters
        afterPenalty.rightDiff = 0
        afterPenalty.leftDiff = 0
        afterPenalty.cornerCOn = 0
        afterPenalty.cornerTOn = 0

        afterPenalty.leftHorizSum = 0
        afterPenalty.rightHorizSum = 0
        afterPenalty.stateCount = 0

    afterPenalty.stateCount += 1
    vis = player.brain.vision

    # Alternate between looking right and left
    if afterPenalty.stateCount % 70 == 0:
        if afterPenalty.right:
            afterPenalty.rightDiff += afterPenalty.cornerCOn - afterPenalty.cornerTOn
            if DEBUG_PENALTY_STATES:
                print "After Penalty right Diff: ", afterPenalty.rightDiff, " cOn: ", afterPenalty.cornerCOn, " tOn: ", afterPenalty.cornerTOn
                print "Right sum: ", afterPenalty.rightHorizSum
                #print "     right close: ", player.brain
            player.brain.tracker.lookToAngle(angle)
        else:
            player.brain.tracker.lookToAngle(-1* angle)
            afterPenalty.leftDiff += afterPenalty.cornerCOn - afterPenalty.cornerTOn
            if DEBUG_PENALTY_STATES:
                print "After Penalty left Diff: ", afterPenalty.leftDiff, " cOn: ", afterPenalty.cornerCOn, " tOn: ", afterPenalty.cornerTOn
                print "Left sum: ", afterPenalty.leftHorizSum
        afterPenalty.right = not afterPenalty.right
        # Reset counters
        afterPenalty.cornerCOn = 0
        afterPenalty.cornerTOn = 0

    foundCorner = False

    # Only count if we're looking right/left. Don't want to count anything while panning
    if player.brain.tracker.isStopped():
        if afterPenalty.right:
            afterPenalty.rightHorizSum += player.brain.vision.horizon_dist
        else:
            afterPenalty.leftHorizSum += player.brain.vision.horizon_dist

        for i in range(0, vis.corner_size()):
            corner = vis.corner(i)
            if corner.id == 2:
                afterPenalty.cornerTOn += 1
            else:
                afterPenalty.cornerCOn += 1

    # China hack 2015. Please make this better. Fairly arbitrary thresholds.
    # The idea is if we're flip-flopping between T and C classifications we
    # have bigger vision problems going on.
    if afterPenalty.stateCount > 140:
        if afterPenalty.rightDiff > 5 and afterPenalty.leftDiff <= 0:
            afterPenalty.decidedSide = True
            afterPenalty.right = True
        elif afterPenalty.rightDiff < -5 and afterPenalty.leftDiff >= 0:
            afterPenalty.decidedSide = True
            afterPenalty.right = False
        elif afterPenalty.leftDiff > 5 and afterPenalty.rightDiff <= 0:
            afterPenalty.decidedSide = True
            afterPenalty.right = False
        elif afterPenalty.leftDiff < -5 and afterPenalty.rightDiff >= 0:
            afterPenalty.decidedSide = True
            afterPenalty.right = True

    if afterPenalty.decidedSide or afterPenalty.stateCount > 300:
        if afterPenalty.decidedSide:
            player.brain.resetLocalizationFromPenalty(afterPenalty.right)
        else:
            # This is a backup. We would prefer to use corners to determine our side as fieldedge could be noisy
            print "Corners didn't work! defaulting to horizonDist"
            player.brain.resetLocalizationFromPenalty(afterPenalty.rightHorizSum < afterPenalty.leftHorizSum)
        if DEBUG_PENALTY_STATES:
            print "We've decided! ", afterPenalty.right, " LeftDiff: ", afterPenalty.leftDiff, \
                " Right Diff: ", afterPenalty.rightDiff, " StateCount: ", afterPenalty.stateCount
            print "RSUM: ", afterPenalty.rightHorizSum, " LSUM: ", afterPenalty.leftHorizSum

        player.brain.tracker.repeatWidePan()

        if not roleConstants.isGoalie(player.role):
            return player.goNow('walkOut')
#.........这里部分代码省略.........
开发者ID:coryalini,项目名称:nbites,代码行数:103,代码来源:PenaltyStates.py

示例5: afterPenalty

# 需要导入模块: import RoleConstants [as 别名]
# 或者: from RoleConstants import isGoalie [as 别名]

#.........这里部分代码省略.........
        player.brain.tracker.repeatWidePan()
        # reset state specific counters
        player.corner_l_sightings = 0
        player.goal_t_sightings = 0
        player.center_sightings = 0
        player.post_l_sightings = 0
        player.post_r_sightings = 0
        player.goal_right = 0
        player.reset_loc = 0

    vision = player.brain.interface.visionField
    # Do we see a corner?
    for i in range(0, vision.visual_corner_size()):
        corner = vision.visual_corner(i)
        for j in range(0, corner.poss_id_size()):
            poss_id = corner.poss_id(j)
            if (poss_id == corner.corner_id.L_INNER_CORNER or
                poss_id == corner.corner_id.L_OUTER_CORNER):
                # Saw an L-corner!
                if DEBUG_PENALTY_STATES:
                    print "Saw an L-corner!"
                player.corner_l_sightings += copysign(1, corner.visual_detection.bearing)
            if (poss_id == corner.corner_id.BLUE_GOAL_T or
                poss_id == corner.corner_id.YELLOW_GOAL_T):
                # Saw a goal T-corner!
                if DEBUG_PENALTY_STATES:
                    print "Saw a goal T-corner!"
                player.goal_t_sightings += copysign(1, corner.visual_detection.bearing)
            if (poss_id == corner.corner_id.CENTER_CIRCLE or
                poss_id == corner.corner_id.CENTER_T):
                # Saw a center corner (+ or T)
                if DEBUG_PENALTY_STATES:
                    print "Saw a center corner!"
                player.center_sightings += copysign(1, corner.visual_detection.bearing)

    # Do we see a goalpost?
    if vision.goal_post_l.visual_detection.on:
        # Saw a goalpost! (adjust for which goalpost)
        if DEBUG_PENALTY_STATES:
            print "Saw an l-post!"
        if not vision.goal_post_l.visual_detection.bearing == 0:
            player.post_l_sightings += (copysign(1, vision.goal_post_l.visual_detection.bearing) *
                                    copysign(1, 700 - vision.goal_post_l.visual_detection.distance))
    if vision.goal_post_r.visual_detection.on:
        # Saw a goalpost! (adjust for which goalpost)
        if DEBUG_PENALTY_STATES:
            print "Saw an r-post!"
        if not vision.goal_post_r.visual_detection.bearing == 0:
            player.post_r_sightings += (copysign(1, vision.goal_post_r.visual_detection.bearing) *
                                    copysign(1, 700 - vision.goal_post_r.visual_detection.distance))

    # If we've seen any landmark enough, reset localization.
    if fabs(player.corner_l_sightings) > OBJ_SEEN_THRESH:
        if DEBUG_PENALTY_STATES:
            print "Saw enough l-corners!"
        player.reset_loc = copysign(1, player.corner_l_sightings)

    if fabs(player.goal_t_sightings) > OBJ_SEEN_THRESH:
        if DEBUG_PENALTY_STATES:
            print "Saw enough goal t-corners!"
        player.reset_loc = copysign(1, player.goal_t_sightings)

    if fabs(player.center_sightings) > OBJ_SEEN_THRESH:
        if DEBUG_PENALTY_STATES:
            print "Saw enough center corners!"
        player.reset_loc = copysign(1, player.center_sightings) * -1

    if fabs(player.post_l_sightings) > OBJ_SEEN_THRESH:
        if DEBUG_PENALTY_STATES:
            print "Saw enough l-posts!"
        player.reset_loc = copysign(1, player.post_l_sightings)

    if fabs(player.post_r_sightings) > OBJ_SEEN_THRESH:
        if DEBUG_PENALTY_STATES:
            print "Saw enough r-posts!"
        player.reset_loc = copysign(1, player.post_r_sightings)

    # Send the reset loc command.
    if player.reset_loc != 0:
        if DEBUG_PENALTY_STATES:
            print "Sufficient sightings. reset_loc value is: " + str(player.reset_loc)
        player.goal_right += player.reset_loc
        player.corner_l_sightings = 0
        player.goal_t_sightings = 0
        player.center_sightings = 0
        player.post_l_sightings = 0
        player.post_r_sightings = 0
        player.reset_loc = 0

    if fabs(player.goal_right) > 5 or player.stateTime > 15:
        if DEBUG_PENALTY_STATES:
            print "Consensus reached! Resetting loc. Is the goal to our right? " + str(player.goal_right < 0)
        # Yes, when goal_right is less than 0, our goal is to our right.
        # It seems counter intuitive, but that's how it works. -Josh Z
        player.brain.resetLocalizationFromPenalty(player.goal_right < 0)
        if not roleConstants.isGoalie(player.role):
            return player.goNow('walkOut')
        return player.goLater(player.gameState)

    return player.stay()
开发者ID:bill-silver,项目名称:nbites,代码行数:104,代码来源:PenaltyStates.py


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