def chaseAroundBox(player): if player.firstFrame(): player.shouldNotChaseAroundBox = 0 player.brain.CoA.setRobotGait(player.brain.motion) if transitions.shouldKick(player): return player.goNow('waitBeforeKick') elif transitions.shouldScanFindBall(player): return player.goLater('scanFindBall') elif transitions.shouldAvoidObstacle( player): # Has potential to go into box! return player.goLater('avoidObstacle') if not transitions.shouldChaseAroundBox(player): player.shouldChaseAroundBox += 1 else: player.shouldChaseAroundBox = 0 if player.shouldChaseAroundBox > constants.STOP_CHASING_AROUND_BOX: return player.goLater('chase') ball = player.brain.ball my = player.brain.my if my.x > NogginConstants.MY_GOALBOX_RIGHT_X: # go to corner nearest ball if ball.y > NogginConstants.MY_GOALBOX_TOP_Y: player.brain.nav.goTo( RobotLocation( NogginConstants.MY_GOALBOX_RIGHT_X + constants.GOALBOX_OFFSET, NogginConstants.MY_GOALBOX_TOP_Y + constants.GOALBOX_OFFSET, NogginConstants.MY_GOAL_HEADING)) if ball.y < NogginConstants.MY_GOALBOX_BOTTOM_Y: player.brain.nav.goTo( RobotLocation( NogginConstants.MY_GOALBOX_RIGHT_X + constants.GOALBOX_OFFSET, NogginConstants.MY_GOALBOX_BOTTOM_Y - constants.GOALBOX_OFFSET, NogginConstants.MY_GOAL_HEADING)) if my.x < NogginConstants.MY_GOALBOX_RIGHT_X: # go to corner nearest ball if my.y > NogginConstants.MY_GOALBOX_TOP_Y: player.brain.nav.goTo( RobotLocation( NogginConstants.MY_GOALBOX_RIGHT_X + constants.GOALBOX_OFFSET, NogginConstants.MY_GOALBOX_TOP_Y + constants.GOALBOX_OFFSET, NogginConstants.MY_GOAL_HEADING)) if my.y < NogginConstants.MY_GOALBOX_BOTTOM_Y: player.brain.nav.goTo( RobotLocation( NogginConstants.MY_GOALBOX_RIGHT_X + constants.GOALBOX_OFFSET, NogginConstants.MY_GOALBOX_BOTTOM_Y - constants.GOALBOX_OFFSET, NogginConstants.MY_GOAL_HEADING)) return player.stay()
def chaseAroundBox(player): if player.firstFrame(): player.shouldNotChaseAroundBox = 0 player.brain.CoA.setRobotGait(player.brain.motion) if transitions.shouldKick(player): return player.goNow('waitBeforeKick') elif transitions.shouldScanFindBall(player): return player.goLater('scanFindBall') elif transitions.shouldAvoidObstacle(player): # Has potential to go into box! return player.goLater('avoidObstacle') if not transitions.shouldChaseAroundBox(player): player.shouldChaseAroundBox += 1 else : player.shouldChaseAroundBox = 0 if player.shouldChaseAroundBox > constants.STOP_CHASING_AROUND_BOX: return player.goLater('chase') ball = player.brain.ball my = player.brain.my if my.x > NogginConstants.MY_GOALBOX_RIGHT_X: # go to corner nearest ball if ball.y > NogginConstants.MY_GOALBOX_TOP_Y: player.brain.nav.goTo( RobotLocation(NogginConstants.MY_GOALBOX_RIGHT_X + constants.GOALBOX_OFFSET, NogginConstants.MY_GOALBOX_TOP_Y + constants.GOALBOX_OFFSET, NogginConstants.MY_GOAL_HEADING )) if ball.y < NogginConstants.MY_GOALBOX_BOTTOM_Y: player.brain.nav.goTo( RobotLocation(NogginConstants.MY_GOALBOX_RIGHT_X + constants.GOALBOX_OFFSET, NogginConstants.MY_GOALBOX_BOTTOM_Y - constants.GOALBOX_OFFSET, NogginConstants.MY_GOAL_HEADING )) if my.x < NogginConstants.MY_GOALBOX_RIGHT_X: # go to corner nearest ball if my.y > NogginConstants.MY_GOALBOX_TOP_Y: player.brain.nav.goTo( RobotLocation( NogginConstants.MY_GOALBOX_RIGHT_X + constants.GOALBOX_OFFSET, NogginConstants.MY_GOALBOX_TOP_Y + constants.GOALBOX_OFFSET, NogginConstants.MY_GOAL_HEADING )) if my.y < NogginConstants.MY_GOALBOX_BOTTOM_Y: player.brain.nav.goTo( RobotLocation( NogginConstants.MY_GOALBOX_RIGHT_X + constants.GOALBOX_OFFSET, NogginConstants.MY_GOALBOX_BOTTOM_Y - constants.GOALBOX_OFFSET, NogginConstants.MY_GOAL_HEADING )) 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 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 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()
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()