Beispiel #1
0
def clearBall(player):
    """
    Get the ball out of our zone!
    """
    # Get references to the collected data
    myLeftPostBearing =  player.kickDecider.myLeftPostBearing
    myRightPostBearing = player.kickDecider.myRightPostBearing
    oppLeftPostBearing = player.kickDecider.oppLeftPostBearing
    oppRightPostBearing = player.kickDecider.oppRightPostBearing

    # Things to do if we saw our own goal
    # Saw the opponent goal

    if abs(player.brain.my.h) > constants.ORBIT_OWN_GOAL_HEADING_THRESH and \
            (helpers.inTopOfField(player) or helpers.inBottomOfField(player) ):
        return player.goLater('orbitBeforeKick')

    if oppLeftPostBearing is not None and \
            oppRightPostBearing is not None:

        avgOppBearing = (oppLeftPostBearing + oppRightPostBearing)/2
        if fabs(avgOppBearing) < constants.ALIGN_FOR_KICK_BEARING_THRESH:
            if constants.DEBUG_KICKS: print ("\t\t Straight 1")
            player.bigKick = True
            return player.goLater('kickBallStraight')

        elif avgOppBearing > constants.ALIGN_FOR_KICK_BEARING_THRESH:
            if constants.DEBUG_KICKS: print ("\t\t Left 5")
            return player.goLater('kickBallLeft')
        elif avgOppBearing < -constants.ALIGN_FOR_KICK_BEARING_THRESH:
            if constants.DEBUG_KICKS: print ("\t\t Right 5")
            return player.goLater('kickBallRight')

    elif player.kickDecider.sawOwnGoal:
        if myLeftPostBearing is not None and myRightPostBearing is not None:
            # Goal in front
            avgMyGoalBearing = (myRightPostBearing + myLeftPostBearing)/2

            if avgMyGoalBearing > 0:
                if constants.DEBUG_KICKS: print ("\t\tright 1")
                return player.goLater('kickBallRight')
            else :
                if constants.DEBUG_KICKS: print ("\t\tleft 1")
                return player.goLater('kickBallLeft')
        else :
            postBearing = 0.0
            if myLeftPostBearing is not None:
                postBearing = myLeftPostBearing
            else :
                postBearing = myRightPostBearing
            if postBearing > 0:
                return player.goLater('kickBallRight')
            else :
                return player.goLater('kickBallLeft')
    else:
        # use localization for kick
        my = player.brain.my

        if helpers.inCenterOfField(player):
            if abs(my.h) <= constants.CLEAR_CENTER_FIELD_STRAIGHT_ANGLE:
                if constants.DEBUG_KICKS: print ("\t\tcenter1")
                player.bigKick = True
                return player.goLater('kickBallStraight')
            elif my.h < -constants.CLEAR_CENTER_FIELD_STRAIGHT_ANGLE:
                if constants.DEBUG_KICKS: print ("\t\tcenter2")
                return player.goLater('kickBallLeft')
            elif my.h > constants.CLEAR_CENTER_FIELD_STRAIGHT_ANGLE:
                if constants.DEBUG_KICKS: print ("\t\tcenter3")
                return player.goLater('kickBallRight')

        elif helpers.inTopOfField(player):
            if constants.FACING_SIDELINE_ANGLE < my.h:
                if constants.DEBUG_KICKS: print ("\t\ttop1")
                return player.goLater('kickBallRight')
            elif my.h < -90:
                if constants.DEBUG_KICKS: print ("\t\ttop3")
                return player.goLater('kickBallLeft')
            else :
                if constants.DEBUG_KICKS: print ("\t\ttop4")
                player.bigKick = True
                return player.goLater('kickBallStraight')

        elif helpers.inBottomOfField(player):
            if -constants.FACING_SIDELINE_ANGLE > my.h:
                if constants.DEBUG_KICKS: print ("\t\tbottom1")
                return player.goLater('kickBallLeft')
            elif my.h > 90:
                if constants.DEBUG_KICKS: print ("\t\tbottom3")
                return player.goLater('kickBallRight')
            else :
                if constants.DEBUG_KICKS: print ("\t\tbottom4")
                player.bigKick = True
                return player.goLater('kickBallStraight')
    player.bigKick = False
    return player.goLater('kickBallStraight')
Beispiel #2
0
def shootBall(player):
    """
    Put it in the hole!
    """
    # Get references to the collected data
    myLeftPostBearing =  player.kickDecider.myLeftPostBearing
    myRightPostBearing = player.kickDecider.myRightPostBearing
    oppLeftPostBearing = player.kickDecider.oppLeftPostBearing
    oppRightPostBearing = player.kickDecider.oppRightPostBearing
    my = player.brain.my

    if oppLeftPostBearing is not None and \
            oppRightPostBearing is not None:

        if (oppRightPostBearing < -constants.KICK_STRAIGHT_POST_BEARING and
            oppLeftPostBearing > constants.KICK_STRAIGHT_POST_BEARING):
            player.bigKick = True
            return player.goLater('kickBallStraight')

        avgOppBearing = (oppLeftPostBearing + oppRightPostBearing)/2
        if fabs(avgOppBearing) < constants.KICK_STRAIGHT_BEARING_THRESH:
            if constants.DEBUG_KICKS: print ("\t\t Straight 1")
            player.bigKick = True
            return player.goLater('kickBallStraight')

        elif fabs(avgOppBearing) < constants.ALIGN_FOR_KICK_BEARING_THRESH and \
                not player.hasAlignedOnce:
            if constants.DEBUG_KICKS: print ("\t\t Align 1")
            player.angleToAlign = avgOppBearing
            player.bigKick = True
            return player.goLater('alignOnBallStraightKick')

        elif avgOppBearing > constants.ALIGN_FOR_KICK_BEARING_THRESH:
            if constants.DEBUG_KICKS: print ("\t\t Left 5")
            return player.goLater('kickBallLeft')
        elif avgOppBearing < -constants.ALIGN_FOR_KICK_BEARING_THRESH:
            if constants.DEBUG_KICKS: print ("\t\t Right 5")
            return player.goLater('kickBallRight')

    elif myLeftPostBearing is not None and myRightPostBearing is not None:

        avgMyGoalBearing = (myRightPostBearing + myLeftPostBearing)/2
        if helpers.inCenterOfField(player):
            if constants.DEBUG_KICKS: print ("\t\tcenterfieldkick")
            if avgMyGoalBearing > 0:
                return player.goLater('kickBallRight')
            else :
                return player.goLater('kickBallLeft')
        elif helpers.inTopOfField(player):
            if constants.DEBUG_KICKS: print ("\t\ttopfieldkick")
            if 90 > avgMyGoalBearing > -30:
                return player.goLater('kickBallRight')
            elif avgMyGoalBearing < -30:
                return player.goLater('kickBallLeft')
            else :
                return player.goLater('kickBallStraight')
        elif helpers.inBottomOfField(player):
            if constants.DEBUG_KICKS: print ("\t\tbottomfieldkick")
            if -90 < avgMyGoalBearing < 30:
                return player.goLater('kickBallRight')
            elif avgMyGoalBearing > 30:
                return player.goLater('kickBallLeft')
            else :
                return player.goLater('kickBallStraight')

    # if somehow we didn't return already with our kick choice,
    # use localization for kick
    if player.kickObjective == constants.OBJECTIVE_SHOOT_CLOSE:
        return player.goNow('shootBallClose')
    else :
        return player.goNow('shootBallFar')