Exemplo n.º 1
0
def approachBall(player):
    """
    Once we are aligned with the ball, approach it
    """
    # Switch to other states if we should
    if player.penaltyKicking and \
           player.brain.ball.inOppGoalBox():
        return player.goNow('penaltyBallInOppGoalbox')
    elif player.brain.tracker.activeLocOn:
        if transitions.shouldScanFindBallActiveLoc(player):
            return player.goLater('scanFindBall')
    elif transitions.shouldScanFindBall(player):
        return player.goLater('scanFindBall')
    elif player.brain.play.isRole(GOALIE) and goalTran.dangerousBall(player):
        return player.goNow('approachDangerousBall')
    elif transitions.shouldDribble(player):
        return player.goNow('dribble')
    elif transitions.shouldSpinToBallClose(player):
        return player.goNow('spinToBallClose')
    elif transitions.shouldStopBeforeKick(player):
        return player.goNow('stopBeforeKick')
    elif transitions.shouldPositionForKick(player):
        return player.goNow('decideKick')

    if player.firstFrame():
        player.brain.nav.chaseBall()
        player.hasAlignedOnce = False

    player.brain.tracker.trackBall()

    return player.stay()
Exemplo n.º 2
0
def spinToBallClose(player):
    """
    If the ball is really close to us, but we aren't facing it yet,
    stop and spin toward it, then decide your kick.
    """
    player.brain.tracker.trackBall()
    ball = player.brain.ball

    if (ball.relY > constants.SHOULD_STOP_Y or
        ball.relY < -1*constants.SHOULD_STOP_Y):
        spinDir = player.brain.my.spinDirToPoint(ball)
        player.setWalk(0, 0, spinDir*constants.BALL_SPIN_SPEED)
    else:
        if ball.dist > constants.SHOULD_START_DIST:
            player.brain.nav.chaseBall()
        else:
            player.stopWalking()
        return player.goNow('decideKick')
    if player.brain.tracker.activeLocOn:
        if transitions.shouldScanFindBallActiveLoc(player):
            return player.goLater('scanFindBall')
    elif transitions.shouldScanFindBall(player):
        return player.goLater('scanFindBall')

    return player.stay()
Exemplo n.º 3
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.º 4
0
def approachBallWalk(player):
    """
    Method that is used by both approach ball and dribble
    We use things as to when we should leave and how we should walk
    """

    if player.brain.playbook.role != pbc.GOALIE:
        if transitions.shouldNotGoInBox(player):
            return player.goLater('ballInMyBox')
        elif transitions.shouldChaseAroundBox(player):
            return player.goLater('chaseAroundBox')
        elif transitions.shouldApproachBallWithLoc(player):
            return player.goNow('approachBallWithLoc')
        elif transitions.shouldTurnToBall_ApproachBall(player):
            return player.goLater('turnToBall')
        elif not player.brain.tracker.activeLocOn and \
                transitions.shouldScanFindBall(player):
            return player.goLater('scanFindBall')
        elif player.brain.tracker.activeLocOn and \
                transitions.shouldScanFindBallActiveLoc(player):
            return player.goLater('scanFindBall')
        elif transitions.shouldAvoidObstacleDuringApproachBall(player):
            return player.goLater('avoidObstacle')

    # Determine our speed for approaching the ball
    ball = player.brain.ball
    if player.brain.playbook.role == pbc.GOALIE and goalTran.dangerousBall(player):
        return player.goNow('approachDangerousBall')

    if ball.dist < constants.APPROACH_WITH_GAIN_DIST:
        sX = MyMath.clip(ball.dist*constants.APPROACH_X_GAIN,
                         constants.MIN_APPROACH_X_SPEED,
                         constants.MAX_APPROACH_X_SPEED)
    else :
        sX = constants.MAX_APPROACH_X_SPEED

    # Determine the speed to turn to the ball
    sTheta = MyMath.clip(ball.bearing*constants.APPROACH_SPIN_GAIN,
                         -constants.APPROACH_SPIN_SPEED,
                         constants.APPROACH_SPIN_SPEED)
    # Avoid spinning so slowly that we step in place
    if fabs(sTheta) < constants.MIN_APPROACH_SPIN_MAGNITUDE:
        sTheta = 0.0

    # Set our walk towards the ball
    if ball.on:
        player.setSpeed(sX,0,sTheta)

    return player.stay()
Exemplo n.º 5
0
def approachBallWalk(player):
    """
    Method that is used by both approach ball and dribble
    We use things as to when we should leave and how we should walk
    """

    if not player.brain.play.isRole(GOALIE):
        if transitions.shouldNotGoInBox(player):
            return player.goLater('ballInMyBox')
        elif transitions.shouldChaseAroundBox(player):
            return player.goLater('chaseAroundBox')
        elif transitions.shouldApproachBallWithLoc(player):
            return player.goNow('approachBallWithLoc')
        elif transitions.shouldTurnToBall_ApproachBall(player):
            return player.goLater('turnToBall')
        elif not player.brain.tracker.activeLocOn and \
                transitions.shouldScanFindBall(player):
            return player.goLater('scanFindBall')
        elif player.brain.tracker.activeLocOn and \
                transitions.shouldScanFindBallActiveLoc(player):
            return player.goLater('scanFindBall')
        elif transitions.shouldAvoidObstacleDuringApproachBall(player):
            return player.goLater('avoidObstacle')

    # Determine our speed for approaching the ball
    ball = player.brain.ball
    if player.brain.play.isRole(GOALIE) and goalTran.dangerousBall(player):
        return player.goNow('approachDangerousBall')

    if ball.dist < constants.APPROACH_WITH_GAIN_DIST:
        sX = MyMath.clip(ball.dist * constants.APPROACH_X_GAIN,
                         constants.MIN_APPROACH_X_SPEED,
                         constants.MAX_APPROACH_X_SPEED)
    else:
        sX = constants.MAX_APPROACH_X_SPEED

    # Determine the speed to turn to the ball
    sTheta = MyMath.clip(ball.bearing * constants.APPROACH_SPIN_GAIN,
                         -constants.APPROACH_SPIN_SPEED,
                         constants.APPROACH_SPIN_SPEED)
    # Avoid spinning so slowly that we step in place
    if fabs(sTheta) < constants.MIN_APPROACH_SPIN_MAGNITUDE:
        sTheta = 0.0

    # Set our walk towards the ball
    if ball.on:
        player.setWalk(sX, 0, sTheta)

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

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

        player.inKickingState = True

        if transitions.shouldKickNow(player):
            return player.goLater('kickBallExecute')

        player.brain.nav.kickPosition(kick)

    player.brain.tracker.trackBall()

    # Leave this state if necessary
    if transitions.shouldStopAndKick(player):
        return player.goLater('preKickStop')
    if player.brain.tracker.activeLocOn:
        if transitions.shouldScanFindBallActiveLoc(player):
            player.inKickingState = False
            return player.goLater('scanFindBall')
    elif transitions.shouldScanFindBallKick(player):
        player.inKickingState = False
        return player.goLater('scanFindBall')
    elif transitions.shouldSpinToKick(player):
        return player.goLater('spinToKick')
    if transitions.shouldChaseFromPositionForKick(player):
        player.inKickingState = False
        return player.goLater('chase')
    if not player.brain.play.isRole(GOALIE):
        if transitions.shouldDribble(player):
            return player.goLater('dribble')

    if player.brain.nav.isStopped():
        kick = player.brain.kickDecider.getKick()
        player.brain.nav.kickPosition(kick)

    return player.stay()
Exemplo n.º 7
0
def spinToKick(player):
    """
    If the ball is behind the tip of our foot, but outside it, spin
    """
    player.brain.tracker.trackBall()
    ball = player.brain.ball

    if (ball.relY > constants.SHOULD_SPIN_TO_KICK_Y or
        ball.relY < -1*constants.SHOULD_SPIN_TO_KICK_Y):
        spinDir = player.brain.my.spinDirToPoint(ball)
        player.setWalk(0,0,spinDir*constants.BALL_SPIN_SPEED)
    else:
        if ball.dist > constants.SHOULD_SPIN_TO_KICK_DIST:
            player.brain.nav.chaseBall()
        else:
            player.stopWalking()
        return player.goNow('decideKick')
    if player.brain.tracker.activeLocOn:
        if transitions.shouldScanFindBallActiveLoc(player):
            return player.goLater('scanFindBall')
    elif transitions.shouldScanFindBall(player):
        return player.goLater('scanFindBall')

    return player.stay()
Exemplo n.º 8
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()
Exemplo n.º 9
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()