예제 #1
0
def calculateHomePosition(player):
    """
    Calculate home position.
    """
    # We've seen the ball recently enough
    if player.brain.ball.vis.frames_off < 20:
        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

    if ball != None and not (role.isDefender(player.role) and NogginConstants.FIXED_D_HOME):
        if role.isLeftDefender(player.role):
            home = findDefenderHomeWithBall(player, True, ball, bearing + player.brain.loc.h)
        elif role.isRightDefender(player.role):
            home = findDefenderHomeWithBall(player, False, ball, bearing + player.brain.loc.h)
        elif role.isStriker(player.role):
            home = findStrikerHome(ball, bearing + player.brain.loc.h)
        else:
            home = player.homePosition
    else:
        if role.isLeftDefender(player.role):
            home = findDefenderHomeNoBall(player, True)
        elif role.isRightDefender(player.role):
            home = findDefenderHomeNoBall(player, False)
        else:
            home = player.homePosition
        
    return home
예제 #2
0
def calculateHomePosition(player):
    """
    Calculate home position.
    """
    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

    if ball != None and not (role.isDefender(player.role)
                             and NogginConstants.FIXED_D_HOME):
        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
    else:
        home = player.homePosition

    return home
예제 #3
0
def tooFarFromHome(threshold, player):
    """
    Returns true if LOC thinks we're more than *distance* away from our home
    position
    """
    if player.brain.ball.vis.frames_off < 10:
        ball = player.brain.ball
    elif player.brain.sharedBall.ball_on:
        ball = player.brain.sharedBall
    else:
        ball = None
        home = player.homePosition

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

    distance = ((player.brain.loc.x - home.x) ** 2 + (player.brain.loc.y - home.y) ** 2) ** 0.5

    return distance > threshold
예제 #4
0
def getSupporterPosition(player, role):
    """
    Returns a position to stand at to support teammate who is chasing the ball.
    Used in positionAsSupporter in PlayOffBallStates.
    """
    if RoleConstants.isLeftDefender(role):
        return leftDefender(player)
    elif RoleConstants.isRightDefender(role):
        return rightDefender(player)
    elif RoleConstants.isChaser(role):
        return chaser(player)
    else: # cherry picker
        return cherryPicker(player)
예제 #5
0
def getSupporterPosition(player, role):
    """
    Returns a position to stand at to support teammate who is chasing the ball.
    Used in positionAsSupporter in PlayOffBallStates.
    """
    if RoleConstants.isLeftDefender(role):
        return leftDefender(player)
    elif RoleConstants.isRightDefender(role):
        return rightDefender(player)
    elif RoleConstants.isChaser(role):
        return chaser(player)
    else:  # cherry picker
        return cherryPicker(player)
예제 #6
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)