Exemple #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()
Exemple #2
0
def testDangerousBall(player):
    if player.counter % 100 == 0:
        if goalTran.dangerousBall(player):
            print "dangerous"
        else:
            print "not dangerous"

    return player.stay()
def testDangerousBall(player):
    if player.counter % 100 == 0:
        if goalTran.dangerousBall(player):
            print "dangerous"
        else:
            print "not dangerous"

    return player.stay()
Exemple #4
0
def chase(player):
    """
    Super State to determine what to do from various situations
    """
    if transitions.shouldFindBall(player):
        return player.goNow('findBall')

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

    else:
        return player.goNow('positionForKick')
Exemple #5
0
def chase(player):
    """
    Super State to determine what to do from various situations
    """
    if transitions.shouldFindBall(player):
        return player.goNow('findBall')

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

    else:
        return player.goNow('spinToBall')
Exemple #6
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()
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()
def approachDangerousBall(player):
    if player.firstFrame():
        player.stopWalking()
    #print "approach dangerous ball"
    #single steps towards ball and goal with spin
    player.setSteps(0, 0, 0, 0)

    if not goalTran.dangerousBall(player):
        return player.goLater('approachBall')
    if transitions.shouldScanFindBall(player):
        return player.goLater('scanFindBall')
    elif transitions.shouldTurnToBall_ApproachBall(player):
        return player.goLater('turnToBall')
    elif transitions.shouldSpinFindBall(player):
        return player.goLater('spinFindBall')

    return player.stay()
Exemple #9
0
def approachDangerousBall(player):
    if player.firstFrame():
        player.stopWalking()
    #print "approach dangerous ball"
    #single steps towards ball and goal with spin
    player.setSteps(0, 0, 0, 0)

    if not goalTran.dangerousBall(player):
        return player.goLater('approachBall')
    if transitions.shouldScanFindBall(player):
        return player.goLater('scanFindBall')
    elif transitions.shouldTurnToBall_ApproachBall(player):
        return player.goLater('turnToBall')
    elif transitions.shouldSpinFindBall(player):
        return player.goLater('spinFindBall')

    return player.stay()
Exemple #10
0
def approachDangerousBall(player):
    """adjusts position to be farther away from the ball
    if the goalie is too close to the ball while in
    the goal box"""
    if player.firstFrame():
        player.stopWalking()

    #move away from the ball so it is no longer dangerous
    if player.brain.nav.isStopped():
        if player.brain.ball.loc.relY > 0:
            player.brain.nav.walk(0, -15, 0)
        else:
            player.brain.nav.walk(0, 15, 0)

    if not goalTran.dangerousBall(player) or transitions.shouldFindBall(player):
        return player.goLater('chase')

    return player.stay()
Exemple #11
0
def approachDangerousBall(player):
    """adjusts position to be farther away from the ball
    if the goalie is too close to the ball while in
    the goal box"""
    if player.firstFrame():
        player.stopWalking()

    #move away from the ball so it is no longer dangerous
    if player.brain.nav.isStopped():
        if player.brain.ball.loc.relY > 0:
            player.brain.nav.walk(0, -15, 0)
        else:
            player.brain.nav.walk(0, 15, 0)

    if not goalTran.dangerousBall(player) or transitions.shouldFindBall(player):
        return player.goLater('chase')

    return player.stay()
Exemple #12
0
def approachDangerousBall(player):
    ball = player.brain.ball
    my = player.brain.my
    if player.firstFrame():
        player.stopWalking()

    #move away from the ball so it is no longer dangerous
    if player.brain.nav.isStopped():
        if ball.relY > 0:
            player.brain.nav.walk(0, -15, 0)
        else:
            player.brain.nav.walk(0, 15, 0)

    if not goalTran.dangerousBall(player):
        return player.goLater('chase')
    if transitions.shouldScanFindBall(player):
        return player.goLater('scanFindBall')

    return player.stay()
Exemple #13
0
def approachDangerousBall(player):
    if player.firstFrame():
        player.stopWalking()
    #print "approach dangerous ball"
    #single steps towards ball and goal with spin
    #player.setSteps(0, 0, 0, 0)
    ball = player.brain.ball
    my = player.brain.my
    if player.brain.nav.isStopped():
        if ball.dist >= 10:
            if ball.y > my.y + 7:
                player.brain.nav.walk(0, 10, 0)
            elif ball.y < my.y - 7:
                player.brain.nav.walk(0, -10, 0)

    if not goalTran.dangerousBall(player):
        return player.goLater('chase')
    if transitions.shouldScanFindBall(player):
        return player.goLater('scanFindBall')

    return player.stay()