def rotateToOpenSpace(player): """ Rotate around ball, so as to find an open lane to dribble thru """ if player.firstFrame(): rotateToOpenSpace.counter = 0 if transitions.rotateLeft(player): player.setWalk(0, -.7, .25) else: player.setWalk(0, .7, -.25) if transitions.ballLost(player): return player.goNow('lookForBall') elif not transitions.shouldDribble(player): player.inKickingState = False player.stand() return player.goLater('chase') elif rotateToOpenSpace.counter == constants.ROTATE_FC: player.stand() return player.goLater('decideDribble') elif transitions.centerLaneOpen(player): rotateToOpenSpace.counter += 1 return player.stay() # so counter is not reset, see below rotateToOpenSpace.counter = 0 return player.stay()
def decideDribble(player): """ Decide to dribble straight ahead or rotate to avoid other robots. """ if player.firstFrame(): player.brain.tracker.trackBall() if not transitions.shouldDribble(player): player.inKickingState = False return player.goLater('chase') elif transitions.centerLaneOpen(player): return player.goNow('executeDribble') else: return player.goNow('rotateToOpenSpace')
def executeDribble(player): """ Move through the ball, so as to execute a dribble. """ if transitions.ballToOurLeft(player): player.kick = kicks.LEFT_DRIBBLE else: player.kick = kicks.RIGHT_DRIBBLE ball = player.brain.ball kick_pos = player.kick.getPosition() player.kickPose = RelRobotLocation(ball.rel_x - kick_pos[0], ball.rel_y - kick_pos[1], 0) if player.firstFrame(): player.aboutToRotate = False player.ballBeforeDribble = ball if player.corner_dribble: player.brain.nav.goTo(player.kickPose, Navigator.PRECISELY, Navigator.CAREFUL_SPEED, False, False) else: player.brain.nav.goTo(player.kickPose, Navigator.PRECISELY, Navigator.GRADUAL_SPEED, False, False) else: player.brain.nav.updateDest(player.kickPose) if player.corner_dribble: if transitions.ballLost(player) or transitions.ballGotFarAway(player): player.corner_dribble = False return player.goLater('approachBall') elif transitions.dribbleGoneBad(player): return player.goNow('positionForDribble') elif transitions.centerField(player): player.corner_dribble = False return player.goLater('approachBall') else: if transitions.ballLost(player): return player.goNow('lookForBall') elif not transitions.shouldDribble(player): player.inKickingState = False return player.goLater('approachBall') elif not transitions.centerLaneOpen(player): player.aboutToRotate = True # we will go from position to rotate return player.goNow('positionForDribble') elif transitions.dribbleGoneBad(player): return player.goNow('positionForDribble') return player.stay()
def executeDribble(player): """ Move through the ball, so as to execute a dribble. """ if transitions.ballToOurLeft(player): player.kick = kicks.LEFT_DRIBBLE else: player.kick = kicks.RIGHT_DRIBBLE ball = player.brain.ball kick_pos = player.kick.getPosition() player.kickPose = RelRobotLocation(ball.rel_x - kick_pos[0], ball.rel_y - kick_pos[1], 0) if player.firstFrame(): player.aboutToRotate = False player.ballBeforeDribble = ball if player.corner_dribble: player.brain.nav.goTo(player.kickPose, Navigator.PRECISELY, Navigator.CAREFUL_SPEED, False, False) else: player.brain.nav.goTo(player.kickPose, Navigator.PRECISELY, Navigator.GRADUAL_SPEED, False, False) else: player.brain.nav.updateDest(player.kickPose) if player.corner_dribble: if transitions.ballLost(player) or transitions.ballGotFarAway(player): player.corner_dribble = False return player.goLater('chase') elif transitions.dribbleGoneBad(player): return player.goNow('positionForDribble') elif transitions.centerField(player): player.corner_dribble = False return player.goLater('chase') else: if transitions.ballLost(player): return player.goNow('lookForBall') elif not transitions.shouldDribble(player): player.inKickingState = False return player.goLater('chase') elif not transitions.centerLaneOpen(player): player.aboutToRotate = True # we will go from position to rotate return player.goNow('positionForDribble') elif transitions.dribbleGoneBad(player): return player.goNow('positionForDribble') return player.stay()
def positionForDribble(player): """ We should position ourselves behind the ball for easy dribbling. """ if transitions.ballToOurLeft(player): player.kick = kicks.LEFT_DRIBBLE else: player.kick = kicks.RIGHT_DRIBBLE ball = player.brain.ball kick_pos = player.kick.getPosition() player.kickPose = RelRobotLocation(ball.rel_x + constants.SETUP_POSITION, ball.rel_y - kick_pos[1], 0) if player.firstFrame(): player.brain.nav.goTo(player.kickPose, Navigator.GENERAL_AREA, Navigator.MEDIUM_SPEED, False, False) else: player.brain.nav.updateDest(player.kickPose) if transitions.ballLost(player): return player.goLater('lookForBall') elif not transitions.shouldDribble(player): player.inKickingState = False player.stand() return player.goLater('chase') elif player.aboutToRotate and transitions.navDone(player): player.aboutToRotate = False return player.goLater('rotateToOpenSpace') elif transitions.navDone(player): return player.goLater('decideDribble') return player.stay()
def positionForKick(player): """ Get the ball in the sweet spot """ if (transitions.shouldApproachBallAgain(player) or transitions.shouldRedecideKick(player)): player.inKickingState = False return player.goLater('chase') if not player.shouldKickOff or DRIBBLE_ON_KICKOFF: if dr_trans.shouldDribble(player): return player.goNow('decideDribble') if player.corner_dribble: return player.goNow('executeDribble') ball = player.brain.ball kick_pos = player.kick.getPosition() positionForKick.kickPose = RelRobotLocation(ball.stat_rel_x - kick_pos[0], ball.stat_rel_y - kick_pos[1], 0) if player.firstFrame(): # Safer when coming from orbit in 1 frame. Still works otherwise, too. player.brain.tracker.lookStraightThenTrack() #only enque the new goTo destination once and update it afterwards player.brain.nav.goTo(positionForKick.kickPose, Navigator.PRECISELY, Navigator.SLOW_SPEED, False, Navigator.ADAPTIVE) else: player.brain.nav.updateDest(positionForKick.kickPose) if transitions.shouldFindBallKick(player): player.inKickingState = False return player.goLater('chase') if (transitions.ballInPosition(player, positionForKick.kickPose) or player.brain.nav.isAtPosition()): player.ballBeforeKick = player.brain.ball player.brain.nav.stand() return player.goNow('kickBallExecute') return player.stay()
def positionForKick(player): """ Get the ball in the sweet spot """ if (transitions.shouldApproachBallAgain(player) or transitions.shouldRedecideKick(player)): player.inKickingState = False return player.goLater('chase') if not player.shouldKickOff or DRIBBLE_ON_KICKOFF: if dr_trans.shouldDribble(player): return player.goNow('decideDribble') if player.corner_dribble: return player.goNow('executeDribble') ball = player.brain.ball kick_pos = player.kick.getPosition() positionForKick.kickPose = RelRobotLocation(ball.rel_x - kick_pos[0], ball.rel_y - kick_pos[1], 0) if player.firstFrame(): player.brain.tracker.lookStraightThenTrack() player.brain.nav.destinationWalkTo(positionForKick.kickPose, Navigator.SLOW_SPEED, True) elif player.brain.ball.vis.on: # don't update if we don't see the ball player.brain.nav.updateDestinationWalkDest(positionForKick.kickPose) if transitions.shouldFindBall(player): player.inKickingState = False return player.goLater('chase') player.ballBeforeKick = player.brain.ball if transitions.ballInPosition(player, positionForKick.kickPose): if player.motionKick: return player.goNow('motionKickExecute') else: player.brain.nav.stand() return player.goNow('kickBallExecute') return player.stay()
def positionForDribble(player): """ We should position ourselves behind the ball for easy dribbling. """ if transitions.ballToOurLeft(player): player.kick = kicks.LEFT_DRIBBLE else: player.kick = kicks.RIGHT_DRIBBLE ball = player.brain.ball kick_pos = player.kick.getPosition() player.kickPose = RelRobotLocation(ball.rel_x + constants.SETUP_POSITION, ball.rel_y - kick_pos[1], 0) if player.firstFrame(): player.brain.nav.goTo(player.kickPose, Navigator.GENERAL_AREA, Navigator.MEDIUM_SPEED, False, False) else: player.brain.nav.updateDest(player.kickPose) if player.corner_dribble: if transitions.ballLost(player) or transitions.ballGotFarAway(player): player.corner_dribble = False return player.goLater('chase') elif transitions.navDone(player): return player.goLater('executeDribble') else: if transitions.ballLost(player): return player.goLater('lookForBall') elif not transitions.shouldDribble(player): player.inKickingState = False player.stand() return player.goLater('chase') elif player.aboutToRotate and transitions.navDone(player): player.aboutToRotate = False return player.goLater('rotateToOpenSpace') elif transitions.navDone(player): return player.goLater('decideDribble') return player.stay()
def prepareForKick(player): if player.firstFrame(): prepareForKick.hackKick = hackKick.KickInformation(player.brain) player.brain.nav.stand() return player.stay() if player.brain.ball.distance > constants.APPROACH_BALL_AGAIN_DIST: # Ball has moved away. Go get it! player.inKickingState = False return player.goLater('chase') player.kick = prepareForKick.hackKick.shoot() if hackKick.DEBUG_KICK_DECISION: print str(player.kick) if not player.shouldKickOff or DRIBBLE_ON_KICKOFF: if dr_trans.shouldDribble(player): return player.goNow('decideDribble') return player.goNow('orbitBall')
def lookForBall(player): """ Backup and look for ball. If fails, leave the FSA. """ if player.firstFrame(): lookForBall.setDest = False player.brain.tracker.repeatWidePan() player.stand() if transitions.seesBall(player): player.brain.tracker.trackBall() return player.goNow('positionForDribble') elif player.brain.nav.isStopped(): if not lookForBall.setDest: backupLoc = RelRobotLocation(constants.BACKUP_WHEN_LOST,0,0) player.brain.nav.walkTo(backupLoc) lookForBall.setDest = True else: player.inKickingState = False return player.goLater('chase') return player.stay()
def lookForBall(player): """ Backup and look for ball. If fails, leave the FSA. """ if player.firstFrame(): lookForBall.setDest = False player.brain.tracker.repeatWidePan() player.stand() if transitions.seesBall(player): player.brain.tracker.trackBall() return player.goNow('positionForDribble') elif player.brain.nav.isStopped(): if not lookForBall.setDest: backupLoc = RelRobotLocation(constants.BACKUP_WHEN_LOST, 0, 0) player.brain.nav.walkTo(backupLoc) lookForBall.setDest = True else: player.inKickingState = False return player.goLater('chase') return player.stay()