Exemplo n.º 1
0
def chase(player):
    """
    Method to determine which chase state should be used.
    We dump the robot into this state when we our switching from something else.
    """
    player.isChasing = True
    player.hasAlignedOnce = False
    if player.brain.playbook.role == pbc.GOALIE:
        if transitions.shouldScanFindBall(player):
            return player.goNow('scanFindBall')
        elif transitions.shouldApproachBall(player):
            return player.goNow('approachBall')
        elif transitions.shouldKick(player):
            return player.goNow('waitBeforeKick')
        elif transitions.shouldTurnToBall_ApproachBall(player):
            return player.goNow('turnToBall')
        else:
            return player.goNow('scanFindBall')

    if transitions.shouldScanFindBall(player):
        return player.goNow('scanFindBall')
    elif transitions.shouldApproachBallWithLoc(player):
        return player.goNow('approachBallWithLoc')
    elif transitions.shouldApproachBall(player):
        return player.goNow('approachBall')
    elif transitions.shouldKick(player):
        return player.goNow('waitBeforeKick')
    elif transitions.shouldTurnToBall_ApproachBall(player):
        return player.goNow('turnToBall')
    else:
        return player.goNow('scanFindBall')
Exemplo n.º 2
0
def chase(player):
    """
    Method to determine which chase state should be used.
    We dump the robot into this state when we our switching from something else.
    """
    player.isChasing = True
    player.hasAlignedOnce = False

    if player.brain.play.isRole(GOALIE):
        if transitions.shouldScanFindBall(player):
            return player.goNow('scanFindBall')
        elif transitions.shouldApproachBall(player):
            return player.goNow('approachBall')
        elif transitions.shouldKick(player):
            return player.goNow('waitBeforeKick')
        elif transitions.shouldTurnToBall_ApproachBall(player):
            return player.goNow('turnToBall')
        else:
            return player.goNow('scanFindBall')

    if transitions.shouldScanFindBall(player):
        return player.goNow('scanFindBall')
    elif transitions.shouldApproachBallWithLoc(player):
        return player.goNow('approachBallWithLoc')
    elif transitions.shouldApproachBall(player):
        return player.goNow('approachBall')
    elif transitions.shouldKick(player):
        return player.goNow('waitBeforeKick')
    elif transitions.shouldTurnToBall_ApproachBall(player):
        return player.goNow('turnToBall')
    else:
        return player.goNow('scanFindBall')
Exemplo n.º 3
0
def waitBeforeKick(player):
    """
    Stop before we kick to make sure we want to kick
    """
    player.inKickingState = True
    if player.firstFrame():
        player.brain.CoA.setRobotGait(player.brain.motion)
        player.stopWalking()

    if not player.brain.nav.isStopped():
        return player.stay()

    if transitions.shouldKick(player):
        return player.goLater('getKickInfo')
    elif transitions.shouldApproachForKick(player):
        player.brain.tracker.trackBall()
        player.inKickingState = False
        return player.goLater('approachBall')
    elif transitions.shouldScanFindBall(player):
        player.inKickingState = False
        player.brain.tracker.trackBall()
        return player.goLater('scanFindBall')
    elif transitions.shouldRepositionForKick(player):
        player.brain.tracker.trackBall()
        return player.goLater('positionForKick')

    # Just don't get stuck here!
    if player.counter > 50:
        return player.goNow('scanFindBall')
    return player.stay()
Exemplo n.º 4
0
def turnToBall(player):
    """
    Rotate to align with the ball. When we get close, we will approach it
    """
    ball = player.brain.ball

    if player.firstFrame():
        player.hasAlignedOnce = False
        player.brain.tracker.trackBall()
        player.brain.CoA.setRobotGait(player.brain.motion)

    # Determine the speed to turn to the ball
    turnRate = MyMath.clip(ball.bearing * constants.BALL_SPIN_GAIN,
                           -constants.BALL_SPIN_SPEED,
                           constants.BALL_SPIN_SPEED)

    # Avoid spinning so slowly that we step in place
    if fabs(turnRate) < constants.MIN_BALL_SPIN_MAGNITUDE:
        turnRate = MyMath.sign(turnRate) * constants.MIN_BALL_SPIN_MAGNITUDE

    if ball.on:
        player.setWalk(x=0, y=0, theta=turnRate)

    if transitions.shouldKick(player):
        return player.goNow('waitBeforeKick')
    elif transitions.shouldPositionForKick(player):
        return player.goNow('positionForKick')
    elif transitions.shouldApproachBall(player):
        return player.goLater('approachBall')
    elif transitions.shouldScanFindBall(player):
        return player.goLater('scanFindBall')

    return player.stay()
Exemplo n.º 5
0
def approachBall(player):
    """
    Once we are aligned with the ball, approach it
    """
    if player.firstFrame():
        player.brain.nav.chaseBall()
        player.hasAlignedOnce = False

    player.brain.tracker.trackBall()

    # Switch to other states if we should
    if player.penaltyKicking and \
           player.brain.ball.inOppGoalBox():
        return player.goNow('penaltyBallInOppGoalbox')

    elif player.brain.play.isRole(GOALIE) and goalTran.dangerousBall(player):
        return player.goNow('approachDangerousBall')

    elif transitions.shouldDribble(player):
        return player.goNow('dribble')

    elif transitions.shouldKick(player) or \
             transitions.shouldPositionForKick(player):
        return player.goNow('decideKick')

    elif player.brain.tracker.activeLocOn:
        if transitions.shouldScanFindBallActiveLoc(player):
            return player.goLater('scanFindBall')
    elif transitions.shouldScanFindBall(player):
        return player.goLater('scanFindBall')
    elif transitions.shouldSpinFindBallAgain(player):
        return player.goLater('spinFindBall')

    return player.stay()
Exemplo n.º 6
0
def turnToBall(player):
    """
    Rotate to align with the ball. When we get close, we will approach it
    """
    ball = player.brain.ball

    if player.firstFrame():
        player.hasAlignedOnce = False
        player.brain.tracker.trackBall()
        player.brain.CoA.setRobotGait(player.brain.motion)

    # Determine the speed to turn to the ball
    turnRate = MyMath.clip(ball.bearing*constants.BALL_SPIN_GAIN,
                           -constants.BALL_SPIN_SPEED,
                           constants.BALL_SPIN_SPEED)

    # Avoid spinning so slowly that we step in place
    if fabs(turnRate) < constants.MIN_BALL_SPIN_MAGNITUDE:
        turnRate = MyMath.sign(turnRate)*constants.MIN_BALL_SPIN_MAGNITUDE

    if ball.on:
        player.setSpeed(x=0,y=0,theta=turnRate)

    if transitions.shouldKick(player):
        return player.goNow('waitBeforeKick')
    elif transitions.shouldPositionForKick(player):
        return player.goNow('positionForKick')
    elif transitions.shouldApproachBall(player):
        return player.goLater('approachBall')
    elif transitions.shouldScanFindBall(player):
        return player.goLater('scanFindBall')

    return player.stay()
Exemplo n.º 7
0
def waitBeforeKick(player):
    """
    Stop before we kick to make sure we want to kick
    """
    player.inKickingState = True
    if player.firstFrame():
        player.brain.CoA.setRobotGait(player.brain.motion)
        player.stopWalking()

    if not player.brain.nav.isStopped():
        return player.stay()

    if transitions.shouldKick(player):
        return player.goLater('getKickInfo')
    elif transitions.shouldApproachForKick(player):
        player.brain.tracker.trackBall()
        player.inKickingState = False
        return player.goLater('approachBall')
    elif transitions.shouldScanFindBall(player):
        player.inKickingState = False
        player.brain.tracker.trackBall()
        return player.goLater('scanFindBall')
    elif transitions.shouldRepositionForKick(player):
        player.brain.tracker.trackBall()
        return player.goLater('positionForKick')

    # Just don't get stuck here!
    if player.counter > 50:
        return player.goNow('scanFindBall')
    return player.stay()
Exemplo n.º 8
0
def chaseAroundBox(player):
    if player.firstFrame():
        player.shouldNotChaseAroundBox = 0

        player.brain.CoA.setRobotGait(player.brain.motion)

    if transitions.shouldKick(player):
        return player.goNow('waitBeforeKick')
    elif transitions.shouldScanFindBall(player):
        return player.goLater('scanFindBall')
    elif transitions.shouldAvoidObstacle(
            player):  # Has potential to go into box!
        return player.goLater('avoidObstacle')

    if not transitions.shouldChaseAroundBox(player):
        player.shouldChaseAroundBox += 1
    else:
        player.shouldChaseAroundBox = 0
    if player.shouldChaseAroundBox > constants.STOP_CHASING_AROUND_BOX:
        return player.goLater('chase')

    ball = player.brain.ball
    my = player.brain.my
    if my.x > NogginConstants.MY_GOALBOX_RIGHT_X:
        # go to corner nearest ball
        if ball.y > NogginConstants.MY_GOALBOX_TOP_Y:
            player.brain.nav.goTo(
                RobotLocation(
                    NogginConstants.MY_GOALBOX_RIGHT_X +
                    constants.GOALBOX_OFFSET,
                    NogginConstants.MY_GOALBOX_TOP_Y +
                    constants.GOALBOX_OFFSET, NogginConstants.MY_GOAL_HEADING))

        if ball.y < NogginConstants.MY_GOALBOX_BOTTOM_Y:
            player.brain.nav.goTo(
                RobotLocation(
                    NogginConstants.MY_GOALBOX_RIGHT_X +
                    constants.GOALBOX_OFFSET,
                    NogginConstants.MY_GOALBOX_BOTTOM_Y -
                    constants.GOALBOX_OFFSET, NogginConstants.MY_GOAL_HEADING))

    if my.x < NogginConstants.MY_GOALBOX_RIGHT_X:
        # go to corner nearest ball
        if my.y > NogginConstants.MY_GOALBOX_TOP_Y:
            player.brain.nav.goTo(
                RobotLocation(
                    NogginConstants.MY_GOALBOX_RIGHT_X +
                    constants.GOALBOX_OFFSET,
                    NogginConstants.MY_GOALBOX_TOP_Y +
                    constants.GOALBOX_OFFSET, NogginConstants.MY_GOAL_HEADING))

        if my.y < NogginConstants.MY_GOALBOX_BOTTOM_Y:
            player.brain.nav.goTo(
                RobotLocation(
                    NogginConstants.MY_GOALBOX_RIGHT_X +
                    constants.GOALBOX_OFFSET,
                    NogginConstants.MY_GOALBOX_BOTTOM_Y -
                    constants.GOALBOX_OFFSET, NogginConstants.MY_GOAL_HEADING))
    return player.stay()
Exemplo n.º 9
0
def chaseAroundBox(player):
    if player.firstFrame():
        player.shouldNotChaseAroundBox = 0

        player.brain.CoA.setRobotGait(player.brain.motion)

    if transitions.shouldKick(player):
        return player.goNow('waitBeforeKick')
    elif transitions.shouldScanFindBall(player):
        return player.goLater('scanFindBall')
    elif transitions.shouldAvoidObstacle(player): # Has potential to go into box!
        return player.goLater('avoidObstacle')

    if not transitions.shouldChaseAroundBox(player):
        player.shouldChaseAroundBox += 1
    else :
        player.shouldChaseAroundBox = 0
    if player.shouldChaseAroundBox > constants.STOP_CHASING_AROUND_BOX:
        return player.goLater('chase')

    ball = player.brain.ball
    my = player.brain.my
    if my.x > NogginConstants.MY_GOALBOX_RIGHT_X:
        # go to corner nearest ball
        if ball.y > NogginConstants.MY_GOALBOX_TOP_Y:
            player.brain.nav.goTo(
                RobotLocation(NogginConstants.MY_GOALBOX_RIGHT_X +
                              constants.GOALBOX_OFFSET,
                              NogginConstants.MY_GOALBOX_TOP_Y +
                              constants.GOALBOX_OFFSET,
                              NogginConstants.MY_GOAL_HEADING ))

        if ball.y < NogginConstants.MY_GOALBOX_BOTTOM_Y:
            player.brain.nav.goTo(
                RobotLocation(NogginConstants.MY_GOALBOX_RIGHT_X +
                              constants.GOALBOX_OFFSET,
                              NogginConstants.MY_GOALBOX_BOTTOM_Y -
                              constants.GOALBOX_OFFSET,
                              NogginConstants.MY_GOAL_HEADING ))

    if my.x < NogginConstants.MY_GOALBOX_RIGHT_X:
        # go to corner nearest ball
        if my.y > NogginConstants.MY_GOALBOX_TOP_Y:
            player.brain.nav.goTo(
                RobotLocation( NogginConstants.MY_GOALBOX_RIGHT_X +
                               constants.GOALBOX_OFFSET,
                               NogginConstants.MY_GOALBOX_TOP_Y +
                               constants.GOALBOX_OFFSET,
                               NogginConstants.MY_GOAL_HEADING ))

        if my.y < NogginConstants.MY_GOALBOX_BOTTOM_Y:
            player.brain.nav.goTo(
                RobotLocation( NogginConstants.MY_GOALBOX_RIGHT_X +
                               constants.GOALBOX_OFFSET,
                               NogginConstants.MY_GOALBOX_BOTTOM_Y -
                               constants.GOALBOX_OFFSET,
                               NogginConstants.MY_GOAL_HEADING ))
    return player.stay()
Exemplo n.º 10
0
def goalieChase(player):
    """
    TODO: make goalie more aggressive (different transitions?)
    """
    if transitions.shouldScanFindBall(player):
        return player.goNow('scanFindBall')
    elif transitions.shouldApproachBall(player):
        return player.goNow('approachBall')
    elif transitions.shouldKick(player):
        return player.goNow('waitBeforeKick')
    else:
        return player.goNow('scanFindBall')
Exemplo n.º 11
0
def approachBall(player):
    """
    Once we are alligned with the ball, approach it
    """
    if player.firstFrame():
        player.hasAlignedOnce = False
        player.brain.tracker.trackBall()
        player.brain.CoA.setRobotGait(player.brain.motion)

    #if player.brain.ball.locDist > constants.APPROACH_ACTIVE_LOC_DIST:
    if transitions.shouldActiveLoc(player):
        player.brain.tracker.activeLoc()
    else:
        player.brain.tracker.trackBall()


    if player.penaltyKicking and \
            player.ballInOppGoalBox():
        return player.goNow('penaltyBallInOppGoalbox')

    # Switch to other states if we should
    if player.brain.play.isRole(GOALIE):
        if transitions.shouldKick(player):
            return player.goNow('waitBeforeKick')
        elif transitions.shouldPositionForKick(player):
            return player.goNow('positionForKick')
        elif transitions.shouldTurnToBall_ApproachBall(player):
            return player.goLater('turnToBall')
        elif not player.brain.tracker.activeLocOn and \
                transitions.shouldScanFindBall(player):
            return player.goLater('scanFindBall')
    else:
        if transitions.shouldDribble(player):
            return player.goNow('dribble')
        elif transitions.shouldKick(player):
            return player.goNow('waitBeforeKick')
        elif transitions.shouldPositionForKick(player):
            return player.goNow('positionForKick')

    return approachBallWalk(player)
Exemplo n.º 12
0
def approachBall(player):
    """
    Once we are alligned with the ball, approach it
    """
    if player.firstFrame():
        player.hasAlignedOnce = False
        player.brain.tracker.trackBall()
        player.brain.CoA.setRobotGait(player.brain.motion)

    #if player.brain.ball.locDist > constants.APPROACH_ACTIVE_LOC_DIST:
    if transitions.shouldActiveLoc(player):
        player.brain.tracker.activeLoc()
    else :
        player.brain.tracker.trackBall()


    if player.penaltyKicking and \
            player.ballInOppGoalBox():
        return player.goNow('penaltyBallInOppGoalbox')

    # Switch to other states if we should
    if player.brain.playbook.role == pbc.GOALIE:
        if transitions.shouldKick(player):
            return player.goNow('waitBeforeKick')
        elif transitions.shouldPositionForKick(player):
            return player.goNow('positionForKick')
        elif transitions.shouldTurnToBall_ApproachBall(player):
            return player.goLater('turnToBall')
        elif not player.brain.tracker.activeLocOn and \
                transitions.shouldScanFindBall(player):
            return player.goLater('scanFindBall')
    else:
        if transitions.shouldDribble(player):
            return player.goNow('dribble')
        elif transitions.shouldKick(player):
            return player.goNow('waitBeforeKick')
        elif transitions.shouldPositionForKick(player):
            return player.goNow('positionForKick')

    return approachBallWalk(player)
Exemplo n.º 13
0
def positionForKick(player):
    """
    State to align on the ball once we are near it
    """
    if player.firstFrame():
        kick = player.brain.kickDecider.kickInfo.getKick()
        player.brain.kickDecider.currentKick = kick

        if kick is None:
            player.angleToOrbit = player.brain.kickDecider.kickInfo.orbitAngle
            return player.goLater('orbitBall')

        player.brain.kickDecider.kickInfo = \
            KickInformation.KickInformation(player)

        player.brain.nav.kickPosition(kick)
        player.inKickingState = True
        player.ballTooFar = 0

    player.brain.tracker.trackBall()

    # something has gone wrong, maybe the ball was moved?
    if (player.brain.ball.dist > PFK_BALL_CLOSE_ENOUGH or
        player.brain.ball.framesOff > PFK_BALL_VISION_FRAMES):
        player.ballTooFar += 1
        if player.ballTooFar > BUFFER_FRAMES_THRESHOLD:
            return player.goNow('chase')
    else:
        player.ballTooFar = 0

    # Leave this state if necessary
    if transitions.shouldKick(player):
        return player.goNow('kickBallExecute')

    if player.brain.tracker.activeLocOn:
        if transitions.shouldScanFindBallActiveLoc(player):
            player.inKickingState = False
            return player.goLater('scanFindBall')
    else:
        if transitions.shouldScanFindBall(player):
            player.inKickingState = False
            return player.goLater('scanFindBall')

    if transitions.shouldApproachFromPositionForKick(player):
        player.inKickingState = False
        return player.goLater('approachBall')

    if not player.brain.play.isRole(GOALIE):
        if transitions.shouldDribble(player):
            return player.goNow('dribble')

    return player.stay()
Exemplo n.º 14
0
def penaltyKickShortDribble(player):
    if player.firstFrame():
        player.penaltyMadeFirstKick = True
    if transitions.shouldStopPenaltyKickDribbling(player):

        if transitions.shouldKick(player):
            return player.goNow('waitBeforeKick')
        elif transitions.shouldPositionForKick(player):
            return player.goNow('positionForKick')
        elif transitions.shouldApproachBall(player):
            return player.goNow('approachBall')

    return ChaseBallStates.approachBallWalk(player)
Exemplo n.º 15
0
def penaltyKickShortDribble(player):
    if player.firstFrame():
        player.penaltyMadeFirstKick = True
    if transitions.shouldStopPenaltyKickDribbling(player):

        if transitions.shouldKick(player):
            return player.goNow('waitBeforeKick')
        elif transitions.shouldPositionForKick(player):
            return player.goNow('positionForKick')
        elif transitions.shouldApproachBall(player):
            return player.goNow('approachBall')

    return ChaseBallStates.approachBallWalk(player)
Exemplo n.º 16
0
def positionForKick(player):
    """
    State to align on the ball once we are near it
    """
    if player.firstFrame():
        player.brain.CoA.setRobotSlowGait(player.brain.motion)

    ball = player.brain.ball

    player.inKickingState = True
    # Leave this state if necessary
    if transitions.shouldKick(player):
        player.brain.CoA.setRobotGait(player.brain.motion)
        return player.goNow('waitBeforeKick')
    elif transitions.shouldScanFindBall(player):
        player.inKickingState = False
        player.brain.CoA.setRobotGait(player.brain.motion)
        return player.goLater('scanFindBall')
    elif transitions.shouldTurnToBallFromPositionForKick(player):
        player.inKickingState = False
        player.brain.CoA.setRobotGait(player.brain.motion)
        return player.goLater('turnToBall')
    elif transitions.shouldApproachFromPositionForKick(player):
        player.inKickingState = False
        player.brain.CoA.setRobotGait(player.brain.motion)
        return player.goLater('approachBall')

    # Determine approach speed
    targetY = ball.relY

    sY = MyMath.clip(targetY * constants.PFK_Y_GAIN,
                     constants.PFK_MIN_Y_SPEED,
                     constants.PFK_MAX_Y_SPEED)

    sY = max(constants.PFK_MIN_Y_MAGNITUDE,sY) * MyMath.sign(sY)

    if transitions.shouldApproachForKick(player):
        targetX = (ball.relX -
                   (constants.BALL_KICK_LEFT_X_CLOSE +
                    constants.BALL_KICK_LEFT_X_FAR) / 2.0)
        sX = MyMath.clip(ball.relX * constants.PFK_X_GAIN,
                         constants.PFK_MIN_X_SPEED,
                         constants.PFK_MAX_X_SPEED)
    else:
        sX = 0.0

    if ball.on:
        player.setSpeed(sX,sY,0)
    return player.stay()
Exemplo n.º 17
0
def positionForKick(player):
    """
    State to align on the ball once we are near it
    """
    if player.firstFrame():
        player.brain.CoA.setRobotSlowGait(player.brain.motion)

    ball = player.brain.ball

    player.inKickingState = True
    # Leave this state if necessary
    if transitions.shouldKick(player):
        player.brain.CoA.setRobotGait(player.brain.motion)
        return player.goNow('waitBeforeKick')
    elif transitions.shouldScanFindBall(player):
        player.inKickingState = False
        player.brain.CoA.setRobotGait(player.brain.motion)
        return player.goLater('scanFindBall')
    elif transitions.shouldTurnToBallFromPositionForKick(player):
        player.inKickingState = False
        player.brain.CoA.setRobotGait(player.brain.motion)
        return player.goLater('turnToBall')
    elif transitions.shouldApproachFromPositionForKick(player):
        player.inKickingState = False
        player.brain.CoA.setRobotGait(player.brain.motion)
        return player.goLater('approachBall')

    # Determine approach speed
    targetY = ball.relY

    sY = MyMath.clip(targetY * constants.PFK_Y_GAIN, constants.PFK_MIN_Y_SPEED,
                     constants.PFK_MAX_Y_SPEED)

    sY = max(constants.PFK_MIN_Y_MAGNITUDE, sY) * MyMath.sign(sY)

    if transitions.shouldApproachForKick(player):
        #        targetX = (ball.relX -
        #                   (constants.BALL_KICK_LEFT_X_CLOSE +
        #                    constants.BALL_KICK_LEFT_X_FAR) / 2.0)
        sX = MyMath.clip(ball.relX * constants.PFK_X_GAIN,
                         constants.PFK_MIN_X_SPEED, constants.PFK_MAX_X_SPEED)
    else:
        sX = 0.0

    if ball.on:
        player.setWalk(sX, sY, 0)
    return player.stay()
Exemplo n.º 18
0
def dribble(player):
    """
    Keep running at the ball, but dribble
    """
    if player.firstFrame():
        player.brain.CoA.setRobotDribbleGait(player.brain.motion)

    # if we should stop dribbling, see what else we should do
    if transitions.shouldStopDribbling(player):

        if transitions.shouldKick(player):
            return player.goNow('waitBeforeKick')
        elif transitions.shouldPositionForKick(player):
            return player.goNow('positionForKick')
        elif transitions.shouldApproachBall(player):
            return player.goNow('approachBall')

    return approachBallWalk(player)
Exemplo n.º 19
0
def dribble(player):
    """
    Keep running at the ball, but dribble
    """
    if player.firstFrame():
        player.brain.CoA.setRobotDribbleGait(player.brain.motion)

    # if we should stop dribbling, see what else we should do
    if transitions.shouldStopDribbling(player):

        if transitions.shouldKick(player):
            return player.goNow('waitBeforeKick')
        elif transitions.shouldPositionForKick(player):
            return player.goNow('positionForKick')
        elif transitions.shouldApproachBall(player):
            return player.goNow('approachBall')

    return approachBallWalk(player)
Exemplo n.º 20
0
def chase(player):
    """
    Method to determine which chase state should be used.
    We dump the robot into this state when we are switching from something else.
    """
    player.isChasing = True
    player.hasAlignedOnce = False

    if player.brain.play.isRole(GOALIE):
        return player.goNow('goalieChase')

    if transitions.shouldScanFindBall(player):
        return player.goNow('scanFindBall')
    elif transitions.shouldApproachBall(player):
        return player.goNow('approachBall')
    elif transitions.shouldKick(player):
        return player.goNow('waitBeforeKick')
    else:
        return player.goNow('scanFindBall')
Exemplo n.º 21
0
def approachBallWithLoc(player):
    if player.firstFrame():
        player.brain.CoA.setRobotGait(player.brain.motion)
        player.hasAlignedOnce = False

    nav = player.brain.nav
    my = player.brain.my
    if player.brain.play.isRole(GOALIE):
        if transitions.shouldKick(player):
            player.brain.CoA.setRobotGait(player.brain.motion)
            return player.goNow('waitBeforeKick')
        elif transitions.shouldPositionForKickFromApproachLoc(player):
            player.brain.CoA.setRobotGait(player.brain.motion)
            return player.goLater('positionForKick')
        elif my.locScoreFramesBad > constants.APPROACH_NO_LOC_THRESH:
            player.brain.CoA.setRobotGait(player.brain.motion)
            return player.goLater('approachBall')
        elif not player.brain.tracker.activeLocOn and \
                transitions.shouldScanFindBall(player):
            player.brain.CoA.setRobotGait(player.brain.motion)
            return player.goLater('scanFindBall')
    else:
        if transitions.shouldKick(player):
            player.brain.CoA.setRobotGait(player.brain.motion)
            return player.goNow('waitBeforeKick')
        elif transitions.shouldPositionForKickFromApproachLoc(player):
            player.brain.CoA.setRobotGait(player.brain.motion)
            return player.goLater('positionForKick')
        elif transitions.shouldNotGoInBox(player):
            player.brain.CoA.setRobotGait(player.brain.motion)
            return player.goLater('ballInMyBox')
        elif transitions.shouldChaseAroundBox(player):
            player.brain.CoA.setRobotGait(player.brain.motion)
            return player.goLater('chaseAroundBox')
        elif transitions.shouldAvoidObstacleDuringApproachBall(player):
            player.brain.CoA.setRobotGait(player.brain.motion)
            return player.goLater('avoidObstacle')
        elif my.locScoreFramesBad > constants.APPROACH_NO_LOC_THRESH:
            player.brain.CoA.setRobotGait(player.brain.motion)
            return player.goLater('approachBall')
        elif not player.brain.tracker.activeLocOn and \
                transitions.shouldScanFindBall(player):
            player.brain.CoA.setRobotGait(player.brain.motion)
            return player.goLater('scanFindBall')
        elif player.brain.tracker.activeLocOn and \
                transitions.shouldScanFindBallActiveLoc(player):
            player.brain.CoA.setRobotGait(player.brain.motion)
            return player.goLater('scanFindBall')

    #if player.brain.ball.locDist > constants.APPROACH_ACTIVE_LOC_DIST:
    if transitions.shouldActiveLoc(player):
        player.brain.tracker.activeLoc()
    else:
        player.brain.tracker.trackBall()

    dest = player.getApproachPosition()
    useOmni = my.dist(dest) <= \
        constants.APPROACH_OMNI_DIST
    changedOmni = False

    if useOmni != nav.movingOmni():
        player.changeOmniGoToCounter += 1
    else:
        player.changeOmniGoToCounter = 0
    if player.changeOmniGoToCounter > PositionConstants.CHANGE_OMNI_THRESH:
        changedOmni = True

    if player.firstFrame() or \
           nav.dest != dest or \
           changedOmni:
        if not useOmni:
            player.brain.CoA.setRobotGait(player.brain.motion)
            nav.goTo(dest)
        else:
            player.brain.CoA.setRobotSlowGait(player.brain.motion)
            nav.omniGoTo(dest)

    return player.stay()
Exemplo n.º 22
0
def approachBallWithLoc(player):
    if player.firstFrame():
        player.brain.CoA.setRobotGait(player.brain.motion)
        player.hasAlignedOnce = False

    nav = player.brain.nav
    my = player.brain.my
    if player.brain.playbook.role == pbc.GOALIE:
        if transitions.shouldKick(player):
            player.brain.CoA.setRobotGait(player.brain.motion)
            return player.goNow('waitBeforeKick')
        elif transitions.shouldPositionForKickFromApproachLoc(player):
            player.brain.CoA.setRobotGait(player.brain.motion)
            return player.goLater('positionForKick')
        elif my.locScoreFramesBad > constants.APPROACH_NO_LOC_THRESH:
            player.brain.CoA.setRobotGait(player.brain.motion)
            return player.goLater('approachBall')
        elif not player.brain.tracker.activeLocOn and \
                transitions.shouldScanFindBall(player):
            player.brain.CoA.setRobotGait(player.brain.motion)
            return player.goLater('scanFindBall')
    else:
        if transitions.shouldKick(player):
            player.brain.CoA.setRobotGait(player.brain.motion)
            return player.goNow('waitBeforeKick')
        elif transitions.shouldPositionForKickFromApproachLoc(player):
            player.brain.CoA.setRobotGait(player.brain.motion)
            return player.goLater('positionForKick')
        elif transitions.shouldNotGoInBox(player):
            player.brain.CoA.setRobotGait(player.brain.motion)
            return player.goLater('ballInMyBox')
        elif transitions.shouldChaseAroundBox(player):
            player.brain.CoA.setRobotGait(player.brain.motion)
            return player.goLater('chaseAroundBox')
        elif transitions.shouldAvoidObstacleDuringApproachBall(player):
            player.brain.CoA.setRobotGait(player.brain.motion)
            return player.goLater('avoidObstacle')
        elif my.locScoreFramesBad > constants.APPROACH_NO_LOC_THRESH:
            player.brain.CoA.setRobotGait(player.brain.motion)
            return player.goLater('approachBall')
        elif not player.brain.tracker.activeLocOn and \
                transitions.shouldScanFindBall(player):
            player.brain.CoA.setRobotGait(player.brain.motion)
            return player.goLater('scanFindBall')
        elif player.brain.tracker.activeLocOn and \
                transitions.shouldScanFindBallActiveLoc(player):
            player.brain.CoA.setRobotGait(player.brain.motion)
            return player.goLater('scanFindBall')

    #if player.brain.ball.locDist > constants.APPROACH_ACTIVE_LOC_DIST:
    if transitions.shouldActiveLoc(player):
        player.brain.tracker.activeLoc()
    else :
        player.brain.tracker.trackBall()

    dest = player.getApproachPosition()
    useOmni = MyMath.dist(my.x, my.y, dest[0], dest[1]) <= \
        constants.APPROACH_OMNI_DIST
    changedOmni = False

    if useOmni != nav.movingOmni:
        player.changeOmniGoToCounter += 1
    else :
        player.changeOmniGoToCounter = 0
    if player.changeOmniGoToCounter > PositionConstants.CHANGE_OMNI_THRESH:
        changedOmni = True

    if player.firstFrame() or \
            nav.destX != dest[0] or \
            nav.destY != dest[1] or \
            nav.destH != dest[2] or \
            changedOmni:
        if not useOmni:
            player.brain.CoA.setRobotGait(player.brain.motion)
            nav.goTo(dest)
        else:
            player.brain.CoA.setRobotSlowGait(player.brain.motion)
            nav.omniGoTo(dest)

    return player.stay()