def orbitBeforeKick(player): """ State for circling the ball when we're facing our goal. """ brain = player.brain my = brain.my if player.firstFrame(): player.orbitStartH = my.h brain.CoA.setRobotGait(brain.motion) brain.tracker.trackBall() shotPoint = KickingHelpers.getShotCloseAimPoint(player) bearingToGoal = my.getRelativeBearing(shotPoint) spinDir = -MyMath.sign(bearingToGoal) player.brain.nav.orbitAngle(spinDir * 90) if not player.brain.tracker.activeLocOn and \ transitions.shouldScanFindBall(player): player.brain.CoA.setRobotGait(player.brain.motion) return player.goLater('scanFindBall') elif brain.ball.dist > constants.STOP_ORBIT_BALL_DIST: return player.goLater('chase') if player.brain.nav.isStopped() and not player.firstFrame(): return player.goLater('positionForKick') return player.stay()
def orbitBeforeKick(player): """ State for circling the ball when we're facing our goal. """ brain = player.brain my = brain.my if player.firstFrame(): player.orbitStartH = my.h brain.CoA.setRobotGait(brain.motion) brain.tracker.trackBall() shotPoint = KickingHelpers.getShotCloseAimPoint(player) bearingToGoal = MyMath.getRelativeBearing(my.x, my.y, my.h, shotPoint[0], shotPoint[1] ) spinDir = -MyMath.sign(bearingToGoal) player.brain.nav.orbitAngle(spinDir * 90) if not player.brain.tracker.activeLocOn and \ transitions.shouldScanFindBall(player): player.brain.CoA.setRobotGait(player.brain.motion) return player.goLater('scanFindBall') elif brain.ball.dist > constants.STOP_ORBIT_BALL_DIST: return player.goLater('chase') if player.brain.nav.isStopped() and not player.firstFrame(): return player.goLater('positionForKick') return player.stay()
def decideKick(player): if ChaseBallTransitions.shouldScanFindBall(player): player.inKickingState = False return player.goLater('scanFindBall') # Get references to the collected data myLeftPostBearing = player.kickDecider.myLeftPostBearing myRightPostBearing = player.kickDecider.myRightPostBearing oppLeftPostBearing = player.kickDecider.oppLeftPostBearing oppRightPostBearing = player.kickDecider.oppRightPostBearing player.printf(player.kickDecider) if player.penaltyKicking: return player.goNow('penaltyKickBall') player.kickObjective = helpers.getKickObjective(player) if player.kickObjective == constants.OBJECTIVE_CLEAR: return player.goNow('clearBall') elif player.kickObjective == constants.OBJECTIVE_SHOOT_FAR or \ player.kickObjective == constants.OBJECTIVE_SHOOT_CLOSE: return player.goNow('shootBall') elif player.kickObjective == constants.OBJECTIVE_KICKOFF: player.hasKickedOffKick = True player.bigKick = False return player.goNow('kickBallStraight') else : return player.goNow('clearBall')
def shouldStopPenaltyKickDribbling(player): """ While dribbling we should stop """ my = player.brain.my dribbleAimPoint = helpers.getShotCloseAimPoint(player) goalBearing = my.getRelativeBearing(dribbleAimPoint) return (inPenaltyKickStrikezone(player) or player.brain.ball.relX > constants.STOP_DRIBBLE_X or fabs(player.brain.ball.relY) > constants.STOP_DRIBBLE_Y or fabs(goalBearing) > constants.STOP_DRIBBLE_BEARING or player.counter > constants.STOP_PENALTY_DRIBBLE_COUNT)
def shouldStopPenaltyKickDribbling(player): """ While dribbling we should stop """ my = player.brain.my dribbleAimPoint = helpers.getShotCloseAimPoint(player) goalBearing = my.getRelativeBearing(dribbleAimPoint) return (inPenaltyKickStrikezone(player) or player.brain.ball.relX > constants.STOP_DRIBBLE_X or abs(player.brain.ball.relY) > constants.STOP_DRIBBLE_Y or abs(goalBearing) > constants.STOP_DRIBBLE_BEARING or player.counter > constants.STOP_PENALTY_DRIBBLE_COUNT)
def shootBallClose(player): """ Slam-dunk! """ my = player.brain.my shotAimPoint = helpers.getShotCloseAimPoint(player) leftPostBearing = MyMath.getRelativeBearing(my.x, my.y, my.h, NogginConstants. LANDMARK_OPP_GOAL_LEFT_POST_X, NogginConstants. LANDMARK_OPP_GOAL_LEFT_POST_Y) rightPostBearing = MyMath.getRelativeBearing(my.x, my.y, my.h, NogginConstants. LANDMARK_OPP_GOAL_RIGHT_POST_X, NogginConstants. LANDMARK_OPP_GOAL_RIGHT_POST_Y) # Am I looking between the posts? if (rightPostBearing < -constants.KICK_STRAIGHT_POST_BEARING and leftPostBearing > constants.KICK_STRAIGHT_POST_BEARING): return player.goNow('kickBallStraight') leftShotPointBearing = MyMath.getRelativeBearing(my.x, my.y, my.h, constants. SHOOT_AT_LEFT_AIM_POINT[0], constants. SHOOT_AT_LEFT_AIM_POINT[1]) rightShotPointBearing = MyMath.getRelativeBearing(my.x, my.y, my.h, constants. SHOOT_AT_RIGHT_AIM_POINT[0], constants. SHOOT_AT_RIGHT_AIM_POINT[1]) # Turn to the closer shot point if fabs(rightShotPointBearing) < fabs(leftShotPointBearing): angleToAlign = rightShotPointBearing else : angleToAlign = leftShotPointBearing if constants.SHOOT_BALL_SIDE_KICK_ANGLE > abs(angleToAlign) > \ constants.SHOOT_BALL_LOC_ALIGN_ANGLE and \ not player.hasAlignedOnce: player.angleToAlign = angleToAlign player.bigKick = False return player.goNow('alignOnBallStraightKick') elif angleToAlign > constants.SHOOT_BALL_SIDE_KICK_ANGLE: return player.goNow('kickBallLeft') elif angleToAlign < -constants.SHOOT_BALL_SIDE_KICK_ANGLE: return player.goNow('kickBallRight') else : player.bigKick = False return player.goLater('kickBallStraight')
def shouldStopDribbling(player): """ While dribbling we should stop """ my = player.brain.my dribbleAimPoint = helpers.getShotCloseAimPoint(player) goalBearing = my.getRelativeBearing(dribbleAimPoint) return (player.penaltyKicking or inOppGoalbox(player) or player.brain.ball.relX > constants.STOP_DRIBBLE_X or abs(player.brain.ball.relY) > constants.STOP_DRIBBLE_Y or abs(goalBearing) > constants.STOP_DRIBBLE_BEARING or player.brain.my.x < (NogginConstants.FIELD_WHITE_WIDTH / 3.0 + NogginConstants.GREEN_PAD_X))
def shouldStopDribbling(player): """ While dribbling we should stop """ my = player.brain.my dribbleAimPoint = helpers.getShotCloseAimPoint(player) goalBearing = my.getRelativeBearing(dribbleAimPoint) return (player.penaltyKicking or player.brain.my.inOppGoalbox() or player.brain.ball.relX > constants.STOP_DRIBBLE_X or fabs(player.brain.ball.relY) > constants.STOP_DRIBBLE_Y or fabs(goalBearing) > constants.STOP_DRIBBLE_BEARING or player.brain.my.x < ( NogginConstants.FIELD_WHITE_WIDTH / 3.0 + NogginConstants.GREEN_PAD_X))
def shouldDribble(player): """ Ball is in between us and the opp goal, let's dribble for a while """ my = player.brain.my dribbleAimPoint = helpers.getShotCloseAimPoint(player) goalBearing = my.getRelativeBearing(dribbleAimPoint) return (constants.USE_DRIBBLE and not player.penaltyKicking and 0 < player.brain.ball.relX < constants.SHOULD_DRIBBLE_X and 0 < abs(player.brain.ball.relY) < constants.SHOULD_DRIBBLE_Y and abs(goalBearing) < constants.SHOULD_DRIBBLE_BEARING and not inOppGoalbox(player) and player.brain.my.x > (NogginConstants.FIELD_WHITE_WIDTH / 3.0 + NogginConstants.GREEN_PAD_X))
def shouldDribble(player): """ Ball is in between us and the opp goal, let's dribble for a while """ if constants.USE_DRIBBLE: my = player.brain.my dribbleAimPoint = helpers.getShotCloseAimPoint(player) goalBearing = my.getRelativeBearing(dribbleAimPoint) return (not player.penaltyKicking and 0 < player.brain.ball.relX < constants.SHOULD_DRIBBLE_X and 0 < fabs(player.brain.ball.relY) < constants.SHOULD_DRIBBLE_Y and fabs(goalBearing) < constants.SHOULD_DRIBBLE_BEARING and not player.brain.my.inOppGoalbox() and player.brain.my.x > ( NogginConstants.FIELD_WHITE_WIDTH / 3.0 + NogginConstants.GREEN_PAD_X) )
def shootBallFar(player): """ From 3 point range! """ my = player.brain.my shotAimPoint = helpers.getShotFarAimPoint(player) bearingToGoal = my.getRelativeBearing(shotAimPoint) if constants.DEBUG_KICKS: print "bearing to goal is ", bearingToGoal if constants.SHOOT_BALL_FAR_SIDE_KICK_ANGLE > abs(bearingToGoal) > \ constants.SHOOT_BALL_FAR_LOC_ALIGN_ANGLE and \ not player.hasAlignedOnce: player.angleToAlign = bearingToGoal player.bigKick = True return player.goNow('alignOnBallStraightKick') elif bearingToGoal > constants.SHOOT_BALL_SIDE_KICK_ANGLE: return player.goNow('kickBallLeft') elif bearingToGoal < -constants.SHOOT_BALL_SIDE_KICK_ANGLE: return player.goNow('kickBallRight') else : player.bigKick = True return player.goNow('kickBallStraight')
def shootBallClose(player): """ Slam-dunk! """ my = player.brain.my shotAimPoint = helpers.getShotCloseAimPoint(player) leftPostBearing = my.getRelativeBearing(player.brain.oppGoalLeftPost) rightPostBearing = my.getRelativeBearing(player.brain.oppGoalRightPost) # Am I looking between the posts? if (rightPostBearing < -constants.KICK_STRAIGHT_POST_BEARING and leftPostBearing > constants.KICK_STRAIGHT_POST_BEARING): return player.goNow('kickBallStraight') leftShotPointBearing = my.getRelativeBearing(constants.SHOOT_AT_LEFT_AIM_POINT) rightShotPointBearing = my.getRelativeBearing(constants.SHOOT_AT_RIGHT_AIM_POINT) # Turn to the closer shot point if fabs(rightShotPointBearing) < fabs(leftShotPointBearing): angleToAlign = rightShotPointBearing else : angleToAlign = leftShotPointBearing if constants.SHOOT_BALL_SIDE_KICK_ANGLE > abs(angleToAlign) > \ constants.SHOOT_BALL_LOC_ALIGN_ANGLE and \ not player.hasAlignedOnce: player.angleToAlign = angleToAlign player.bigKick = False return player.goNow('alignOnBallStraightKick') elif angleToAlign > constants.SHOOT_BALL_SIDE_KICK_ANGLE: return player.goNow('kickBallLeft') elif angleToAlign < -constants.SHOOT_BALL_SIDE_KICK_ANGLE: return player.goNow('kickBallRight') else : player.bigKick = False return player.goLater('kickBallStraight')
def decideKick(player): if ChaseBallTransitions.shouldScanFindBall(player): player.inKickingState = False return player.goLater('scanFindBall') player.printf(player.kickDecider) if player.penaltyKicking: return player.goNow('penaltyKickBall') player.kickObjective = helpers.getKickObjective(player) if player.kickObjective == constants.OBJECTIVE_CLEAR: return player.goNow('clearBall') elif player.kickObjective == constants.OBJECTIVE_SHOOT_FAR or \ player.kickObjective == constants.OBJECTIVE_SHOOT_CLOSE: return player.goNow('shootBall') elif player.kickObjective == constants.OBJECTIVE_KICKOFF: player.hasKickedOffKick = True player.bigKick = False return player.goNow('kickBallStraight') else : return player.goNow('clearBall')
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')
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')