示例#1
0
def watchForBall(player):
    """
    The player is at home, waiting for the ball to be within box.
    """

    if player.firstFrame():
        # print "-----------Player at home - Watching for ball-----------"
        player.brain.tracker.trackBall()
        player.brain.nav.stand()

    # I commented this out because we were getting strange oscillations
    # between this and positonAtHome, and honestly we never go here unless
    # we are already at home... dumb...
    # if transitions.tooFarFromHome(player, 50, 20):
    #     return player.goLater('positionAtHome')

    if role.isFirstChaser(player.role):
        if player.stateTime >= tracking.INITIALIZE_HEADING_TIME + tracking.FULL_WIDE_PAN_TIME:
                return player.goNow('spinAtHome')
    elif role.isStriker(player.role):
        if player.stateTime >= tracking.INITIALIZE_HEADING_TIME + tracking.FULL_WIDE_PAN_TIME * 2:
            return player.goNow('spinAtHome')
    else:
        if player.stateTime >= tracking.INITIALIZE_HEADING_TIME + tracking.FULL_WIDE_PAN_TIME * 2:
            return player.goNow('spinAtHome')
示例#2
0
def shouldCedeClaim(player):
    if not player.useClaims:
        return False

    playerWeight = weightedDistAndHeading(player.brain.ball.distance, \
                                              player.brain.loc.h, player.brain.ball.bearing_deg)
    for mate in player.brain.teamMembers:
        if (mate.playerNumber == player.brain.playerNumber):
            continue
        if not mate.claimedBall or not mate.active or mate.fallen:
            continue

        # Now we get into actual claims
        if ((player.brain.time - mate.claimTime) > claimExpiration):
            print "claim expired"
            continue  # That claim has expired (Comm is probably lagging)

        mateWeight = weightedDistAndHeading(mate.ballDist, mate.h,
                                            mate.ballBearing)

        # sigmoid function so that the difference increases slowly at close distances but
        # grows quickly at mid-range to far distances and at very far distances, asymptotically
        # approaches a maximum. uses the distance of the close robot
        if player.brain.ball.distance < mate.ballDist:
            closerDistance = player.brain.ball.distance
        else:
            closerDistance = mate.ballDist
        closeWeightDifference = 25 + 150 / (1 + math.e**
                                            (6.25 - .05 * closerDistance))
        if (math.fabs(mateWeight - playerWeight) < closeWeightDifference):
            if roleConstants.isFirstChaser(mate.role):
                player.roleOfClaimer = mate.role
                player.claimedBall = False
                return True
            elif player.role < mate.role and not roleConstants.isFirstChaser(
                    player.role):
                player.roleOfClaimer = mate.role
                player.claimedBall = False
                return True
        elif (mateWeight < playerWeight):
            player.roleOfClaimer = mate.role
            player.claimedBall = False
            return True

    player.claimedBall = True
    return False
示例#3
0
def shouldCedeClaim(player):
    if not player.useClaims:
        return False

    playerWeight = weightedDistAndHeading(player.brain.ball.distance, \
                                              player.brain.loc.h, player.brain.ball.bearing_deg)
    for mate in player.brain.teamMembers:
        if (mate.playerNumber == player.brain.playerNumber):
            continue
        if not mate.claimedBall or not mate.active or mate.fallen:
            continue

        # Now we get into actual claims
        if ((player.brain.time - mate.claimTime) > claimExpiration):
            print "claim expired"
            continue # That claim has expired (Comm is probably lagging)

        mateWeight = weightedDistAndHeading(mate.ballDist, mate.h, mate.ballBearing)

        # sigmoid function so that the difference increases slowly at close distances but
        # grows quickly at mid-range to far distances and at very far distances, asymptotically
        # approaches a maximum. uses the distance of the close robot
        if player.brain.ball.distance < mate.ballDist:
            closerDistance = player.brain.ball.distance
        else:
            closerDistance = mate.ballDist
        closeWeightDifference = 25 + 150/(1 + math.e**(6.25 - .05*closerDistance))
        if (math.fabs(mateWeight - playerWeight) < closeWeightDifference):
            if roleConstants.isFirstChaser(mate.role):
                player.roleOfClaimer =  mate.role
                player.claimedBall = False
                return True
            elif player.role < mate.role and not roleConstants.isFirstChaser(player.role):
                player.roleOfClaimer =  mate.role
                player.claimedBall = False
                return True
        elif (mateWeight < playerWeight):
            player.roleOfClaimer =  mate.role
            player.claimedBall = False
            return True

    player.claimedBall = True
    return False
示例#4
0
def branchOnRole(player):
    """
    Chasers are going to have a different behavior again.
    We will branch on behavior based on role here
    """

    # print "----------In branch on role----------"

    # print "Entered Branch on Role"
    # print "----- evenDefenderIsForward, lastEvenDefenderForwardVal ----"
    # print player.brain.evenDefenderIsForward, lastEvenDefenderForwardVal

    # global lastEvenDefenderForwardVal
    # player.brain.evenDefenderIsForward = not lastEvenDefenderForwardVal
    # newEvenDefenderForwardVal = True
    # print("TIME SINCE PLAYING:", player.brain.gameController.timeSincePlaying)
    if role.isFirstChaser(player.role):
        if transitions.shouldFindSharedBall(player) and player.brain.gameController.timeSincePlaying > 75:
            return player.goNow('searchFieldForSharedBall')
        return player.goNow('playerFourSearchBehavior') 
    elif role.isStriker(player.role):
        return player.goNow('playerFiveSearchBehavior')
    elif role.isLeftDefender(player.role):

        # print "Player Brain Left Forward 1: " + str(leftDefenderIsForward)

        # if (player.brain.sharedBall.ball_on) and (player.brain.sharedBall.x < NogginConstants.MIDFIELD_X):

            # print "WE ARE IN HERE"

            # return player.goNow('leftDefenderBack')
        if leftDefenderIsForward:

            # print "Changing to False"

            global leftDefenderIsForward

            leftDefenderIsForward = False

            # print "Player Brain Left Forward 2: " + str(leftDefenderIsForward)

            return player.goNow('leftDefenderForward')
        else:

            # print "Changing to True"

            global leftDefenderIsForward

            leftDefenderIsForward = True

            # print "Player Brain Left Forward 3: " + str(leftDefenderIsForward)

            return player.goNow('leftDefenderBack')
    else:
        return player.goNow('positionAtHome')
示例#5
0
def doSecondHalfSpin(player):
    """
    Keep spinning in the same direction.
    """
    if player.firstFrame():
        player.setWalk(0, 0, nav.QUICK_SPEED)
        player.brain.tracker.lookToSpinDirection(1)

    while player.stateTime < chaseConstants.SPUN_ONCE_TIME_THRESH / 2:
        return player.stay()

    if role.isFirstChaser(player.role):
        return player.goNow('searchFieldByQuad')
    return player.goNow('playOffBall')
示例#6
0
def ballNotInBufferedBox(player):
    """
    A transition which allows a stretching of a box so that the box isn't
    so ridged. Intended use is for in approachBall, ensuring that we don't loop
    between approachBall and positionAtHome if the ball is close to the edge of the box.
    """
    ball = player.brain.ball
    buf = role.boxBuffer
    inBox = (ball.x > player.box[0][0] - buf and ball.y > player.box[0][1] - buf and \
            ball.x < player.box[0][0] + player.box[1] + buf and \
            ball.y < player.box[0][1] + player.box[2] + buf)

    return (ball.vis.frames_off > chaseConstants.BALL_OFF_THRESH
            or (not inBox and not role.isFirstChaser(player.role)))
示例#7
0
def doSecondHalfSpin(player):
    """
    Keep spinning in the same direction.
    """
    if player.firstFrame():
        player.setWalk(0, 0, nav.QUICK_SPEED)
        player.brain.tracker.lookToSpinDirection(1)

    while player.stateTime < chaseConstants.SPUN_ONCE_TIME_THRESH / 2:
        return player.stay()

    if role.isFirstChaser(player.role):
        return player.goNow('searchFieldByQuad')
    return player.goNow('playOffBall')
def ballNotInBufferedBox(player):
    """
    A transition which allows a stretching of a box so that the box isn't
    so ridged. Intended use is for in approachBall, ensuring that we don't loop
    between approachBall and positionAtHome if the ball is close to the edge of the box.
    """
    ball = player.brain.ball
    buf = role.boxBuffer
    inBox = (ball.x > player.box[0][0] - buf and ball.y > player.box[0][1] - buf and \
            ball.x < player.box[0][0] + player.box[1] + buf and \
            ball.y < player.box[0][1] + player.box[2] + buf)

    return (ball.vis.frames_off > chaseConstants.BALL_OFF_THRESH or 
            (not inBox and not role.isFirstChaser(player.role)))
def getSupporterPosition(player, r):
    """
    Returns a position to stand at to support teammate who is chasing the ball.
    Used in positionAsSupporter in PlayOffBallStates.
    """
    if role.isLeftDefender(r):
        return leftDefender(player)
    elif role.isRightDefender(r):
        return rightDefender(player)
    elif role.isFirstChaser(r):
        return chaser(player)
    elif role.isStriker(r):
        return striker(player)
    else: # cherry picker
        return cherryPicker(player)
示例#10
0
def getSupporterPosition(player, r):
    """
    Returns a position to stand at to support teammate who is chasing the ball.
    Used in positionAsSupporter in PlayOffBallStates.
    """
    if role.isLeftDefender(r):
        return leftDefender(player)
    elif role.isRightDefender(r):
        return rightDefender(player)
    elif role.isFirstChaser(r):
        return chaser(player)
    elif role.isStriker(r):
        return striker(player)
    else:  # cherry picker
        return cherryPicker(player)
示例#11
0
def doPan(player):
    """
    Wide pan for 5 seconds.
    """

    if player.firstFrame():
        # print "------------Doing Pan-------------"

        player.stand()
        player.brain.tracker.trackBall()

    if player.stateTime >= tracking.INITIALIZE_HEADING_TIME + tracking.FULL_WIDE_PAN_TIME:
        if role.isFirstChaser(player.role):
            return player.goNow('playerFourSearchBehavior')
        elif role.isStriker(player.role):
            return player.goNow('playerFiveSearchBehavior')
        else:
            return player.goNow('doSecondHalfSpin')
示例#12
0
def positionAtHome(player):
    """
    Go to the player's home position. Defenders look in the direction of the 
    shared ball if it is on with reliability >= 2. Cherry pickers look in the direction
    of the shared ball if it is on with reliability >= 1.
    """

    if role.isFirstChaser(player.role) and transitions.shouldFindSharedBall(player):
        return player.goLater('searchFieldForSharedBall')

    if player.brain.ball.vis.frames_off < 10:
        ball = player.brain.ball
        bearing = ball.bearing_deg
    elif player.brain.sharedBall.ball_on:
        ball = player.brain.sharedBall
        bearing = degrees(atan2(ball.y - player.brain.loc.y,
                        ball.x - player.brain.loc.x)) - player.brain.loc.h
    else:
        ball = None
        home = player.homePosition

    if ball != None:
        if role.isLeftDefender(player.role):
            home = findDefenderHome(True, ball, bearing + player.brain.loc.h)
        elif role.isRightDefender(player.role):
            home = findDefenderHome(False, ball, bearing + player.brain.loc.h)
        elif role.isStriker(player.role):
            home = findStrikerHome(ball, bearing + player.brain.loc.h)
        else:
            home = player.homePosition

    if player.firstFrame():
        if role.isCherryPicker(player.role):
            player.brain.tracker.repeatBasicPan()
        else:
            player.brain.tracker.trackBall()
        
        fastWalk = role.isChaser(player.role)
        player.brain.nav.goTo(home, precision = nav.HOME,
                              speed = nav.QUICK_SPEED, avoidObstacles = True,
                              fast = fastWalk, pb = False)

    player.brain.nav.updateDest(home)
示例#13
0
def panAtWayPoint(player):

    if player.firstFrame():
        player.stand()
        player.brain.tracker.trackBall()

    # if role.isFirstChaser(player.role) and not playerFourSearchBehavior.pointIndex % len(playerFourPoints) == 0:
    #     if player.stateTime >= FULL_WIDE_PAN_TIME:
    #         return player.goNow("playerFourSearchBehavior")

    # elif player.stateTime >= FULL_WIDE_PAN_TIME * 2:
    #     return player.goNow("spinAtHome")

    if role.isFirstChaser(player.role) and not playerFourSearchBehavior.pointIndex % len(playerFourPoints) == 0:
        if player.stateTime >= tracking.INITIALIZE_HEADING_TIME + tracking.FULL_WIDE_PAN_TIME:
            return player.goNow("playerFourSearchBehavior")
    elif role.isStriker(player.role):
        if player.stateTime >= tracking.INITIALIZE_HEADING_TIME + tracking.FULL_WIDE_PAN_TIME * 2:
            return player.goNow('spinAtHome')
    else:
        if player.stateTime >= tracking.INITIALIZE_HEADING_TIME + tracking.FULL_WIDE_PAN_TIME:
            return player.goNow('spinAtHome')
示例#14
0
def shouldFindSharedBall(player):
    return (role.isFirstChaser(player.role)
            and player.brain.ball.vis.frames_off > 10
            and player.brain.sharedBall.ball_on
            and player.brain.sharedBall.reliability >= 1)
示例#15
0
def shouldFindSharedBall(player):
    return (role.isFirstChaser(player.role) and
            player.brain.ball.vis.frames_off > 10 and
            player.brain.sharedBall.ball_on and
            player.brain.sharedBall.reliability >= 1)