Example #1
0
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)
Example #2
0
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)
Example #3
0
def watchForBall(player):
    """
    The player is at home, waiting for the ball to be within box.
    """
    if player.firstFrame():
        player.brain.tracker.trackBall()
        player.brain.nav.stand()

    if transitions.tooFarFromHome(player, 50, 20):
        return player.goLater('positionAtHome')
Example #4
0
def watchForBall(player):
    """
    The player is at home, waiting for the ball to be within box.
    """
    if player.firstFrame():
        player.brain.tracker.trackBall()
        player.brain.nav.stand()

    if transitions.tooFarFromHome(player, 50, 20):
        return player.goLater('positionAtHome')
Example #5
0
def branchOnRole(player):
    """
    Chasers have different behavior than defenders, so we branch on
    role here.
    """
    if role.isChaser(player.role):
        if transitions.shouldFindSharedBall(player):
            return player.goNow('searchFieldForSharedBall')
        return player.goNow('searchFieldByQuad')
    return player.goNow('positionAtHome')
Example #6
0
def branchOnRole(player):
    """
    Chasers have different behavior than defenders, so we branch on
    role here.
    """
    if role.isChaser(player.role):
        if transitions.shouldFindSharedBall(player):
            return player.goNow('searchFieldForSharedBall')
        return player.goNow('searchFieldByQuad')
    return player.goNow('positionAtHome')
Example #7
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')
Example #8
0
def branchOnRole(player):
    """
    Chasers are going to have a different behavior again.
    We will branch on behavior based on role here
    """
    # print("TIME SINCE PLAYING:", player.brain.gameController.timeSincePlaying)
    if role.isChaser(player.role):
        if transitions.shouldFindSharedBall(player) and player.brain.gameController.timeSincePlaying > 75:
            return player.goNow('searchFieldForSharedBall')
        return player.goNow('searchFieldByQuad')
    return player.goNow('positionAtHome')
Example #9
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)
Example #10
0
    home = RobotLocation(player.homePosition.x, player.homePosition.y, player.homePosition.h)
    if (player.brain.sharedBall.ball_on and player.brain.sharedBall.reliability >= 2 and 
        role.isDefender(player.role)):
        sharedball = Location(player.brain.sharedBall.x, player.brain.sharedBall.y)
        home.h = player.brain.loc.getRelativeBearing(sharedball)
    elif (player.brain.sharedBall.ball_on and player.brain.sharedBall.reliability >= 1 and 
          role.isCherryPicker(player.role)):
        sharedball = Location(player.brain.sharedBall.x, player.brain.sharedBall.y)
        home.h = player.brain.loc.getRelativeBearing(sharedball)

    player.brain.nav.updateDest(home)

@superState('playOffBall')
@stay
@ifSwitchNow(transitions.tooFarFromHome(20), 'positionAtHome')
def watchForBall(player):
    """
    The player is at home, waiting for the ball to be within it's box (range)
    """
    if player.firstFrame():
        player.brain.nav.stand()

@superState('playOffBall')
@stay
@ifSwitchLater(shared.ballOffForNFrames(120), 'playOffBall')
def positionAsSupporter(player):
    if (role.isChaser(player.role) and role.isChaser(player.roleOfClaimer) and 
        player.brain.ball.distance > hypot(CHASER_DISTANCE, CHASER_DISTANCE)):
        fast = True
    else:
Example #11
0
    if player.firstFrame():
        if role.isCherryPicker(player.role):
            player.brain.tracker.repeatWidePan()
        else:
            player.brain.tracker.trackBall()
        fastWalk = role.isCherryPicker(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)

@superState('playOffBall')
@stay
@ifSwitchNow(transitions.tooFarFromHome(20), 'positionAtHome')
def watchForBall(player):
    """
    The player is at home, waiting for the ball to be within it's box (range)
    """
    if player.firstFrame():
        player.brain.nav.stand()

@superState('playOffBall')
@stay
@ifSwitchLater(shared.ballOffForNFrames(120), 'playOffBall')
def positionAsSupporter(player):
    if (role.isChaser(player.role) and role.isChaser(player.roleOfClaimer) and 
        player.brain.ball.distance > hypot(CHASER_DISTANCE, CHASER_DISTANCE)):
        fast = True
    else: