def positionAtHome(player): """ Go to the player's home position. Defenders look in the direction of the shared ball if it is on with reliability >= 2. Cherry pickers look in the direction of the shared ball if it is on with reliability >= 1. """ if player.firstFrame(): player.brain.tracker.trackBall() home = RobotLocation(player.homePosition.x, player.homePosition.y, player.homePosition.h) if (player.brain.sharedBall.ball_on and player.brain.sharedBall.reliability >= 2 and role.isDefender(player.role)): sharedball = Location(player.brain.sharedBall.x, player.brain.sharedBall.y) home.h = player.brain.loc.getRelativeBearing(sharedball) elif (player.brain.sharedBall.ball_on and player.brain.sharedBall.reliability >= 1 and role.isCherryPicker(player.role)): sharedball = Location(player.brain.sharedBall.x, player.brain.sharedBall.y) home.h = player.brain.loc.getRelativeBearing(sharedball) fastWalk = role.isCherryPicker(player.role) player.brain.nav.goTo(home, precision = nav.HOME, speed = nav.QUICK_SPEED, avoidObstacles = True, fast = fastWalk, pb = False) home = RobotLocation(player.homePosition.x, player.homePosition.y, player.homePosition.h) if (player.brain.sharedBall.ball_on and player.brain.sharedBall.reliability >= 2 and role.isDefender(player.role)): sharedball = Location(player.brain.sharedBall.x, player.brain.sharedBall.y) home.h = player.brain.loc.getRelativeBearing(sharedball) elif (player.brain.sharedBall.ball_on and player.brain.sharedBall.reliability >= 1 and role.isCherryPicker(player.role)): sharedball = Location(player.brain.sharedBall.x, player.brain.sharedBall.y) home.h = player.brain.loc.getRelativeBearing(sharedball) player.brain.nav.updateDest(home)
def calculateHomePosition(player): """ Calculate home position. """ # We've seen the ball recently enough if player.brain.ball.vis.frames_off < 20: ball = player.brain.ball bearing = ball.bearing_deg elif player.brain.sharedBall.ball_on: ball = player.brain.sharedBall bearing = degrees(atan2(ball.y - player.brain.loc.y, ball.x - player.brain.loc.x)) - player.brain.loc.h else: ball = None if ball != None and not (role.isDefender(player.role) and NogginConstants.FIXED_D_HOME): if role.isLeftDefender(player.role): home = findDefenderHomeWithBall(player, True, ball, bearing + player.brain.loc.h) elif role.isRightDefender(player.role): home = findDefenderHomeWithBall(player, False, ball, bearing + player.brain.loc.h) elif role.isStriker(player.role): home = findStrikerHome(ball, bearing + player.brain.loc.h) else: home = player.homePosition else: if role.isLeftDefender(player.role): home = findDefenderHomeNoBall(player, True) elif role.isRightDefender(player.role): home = findDefenderHomeNoBall(player, False) else: home = player.homePosition return home
def calculateHomePosition(player): """ Calculate home position. """ if player.brain.ball.vis.frames_off < 10: ball = player.brain.ball bearing = ball.bearing_deg elif player.brain.sharedBall.ball_on: ball = player.brain.sharedBall bearing = degrees( atan2(ball.y - player.brain.loc.y, ball.x - player.brain.loc.x)) - player.brain.loc.h else: ball = None if ball != None and not (role.isDefender(player.role) and NogginConstants.FIXED_D_HOME): if role.isLeftDefender(player.role): home = findDefenderHome(True, ball, bearing + player.brain.loc.h) elif role.isRightDefender(player.role): home = findDefenderHome(False, ball, bearing + player.brain.loc.h) elif role.isStriker(player.role): home = findStrikerHome(ball, bearing + player.brain.loc.h) else: home = player.homePosition else: home = player.homePosition return home
def chaser(player): """ Chasers position off to one side of the ball about a meter away if a chaser or cherry picker is calling them off. Chasers position further away up field if a defender is calling them off. """ if RoleConstants.isDefender(player.roleOfClaimer): if player.brain.ball.y >= player.brain.loc.y: return RobotLocation(player.brain.ball.x + 200, player.brain.ball.y - CHASER_DISTANCE, player.brain.ball.bearing_deg + player.brain.loc.h) return RobotLocation(player.brain.ball.x + 200, player.brain.ball.y + CHASER_DISTANCE, player.brain.ball.bearing_deg + player.brain.loc.h) else: southEast = RobotLocation(player.brain.ball.x - CHASER_DISTANCE, player.brain.ball.y - CHASER_DISTANCE, player.brain.ball.bearing_deg + player.brain.loc.h) southWest = RobotLocation(player.brain.ball.x - CHASER_DISTANCE, player.brain.ball.y + CHASER_DISTANCE, player.brain.ball.bearing_deg + player.brain.loc.h) northEast = RobotLocation(player.brain.ball.x + CHASER_DISTANCE, player.brain.ball.y - CHASER_DISTANCE, player.brain.ball.bearing_deg + player.brain.loc.h) northWest = RobotLocation(player.brain.ball.x + CHASER_DISTANCE, player.brain.ball.y + CHASER_DISTANCE, player.brain.ball.bearing_deg + player.brain.loc.h) supportPostitions = [southEast,southWest,northEast,northWest] positionsFilteredByInBounds = [position for position in supportPostitions if inBounds(position)] if len(positionsFilteredByInBounds) > 0: return min(positionsFilteredByInBounds, key=distanceToPosition(player)) # print "no in bounds position" return southEast
def tooFarFromHome(player, distThreshold, angleThreshold): """ Returns true if LOC thinks we're more than *distance* away from our home position """ if role.isDefender(player.role): home = calculateHomePosition(player) else: home = player.homePosition distanceTo = ((player.brain.loc.x - home.x)**2 + (player.brain.loc.y - home.y)**2)**.5 angleTo = fabs(player.brain.loc.h - home.h) return distanceTo > distThreshold or angleTo > angleThreshold
def chaser(player): """ Chasers position off to one side of the ball about a meter away if a chaser or cherry picker is calling them off. Chasers position further away up field if a defender is calling them off. """ if role.isStriker(player.roleOfClaimer): return striker(player) if role.isDefender(player.roleOfClaimer): if player.brain.ball.y >= player.brain.loc.y: return RobotLocation( player.brain.ball.x + 250, player.brain.ball.y - CHASER_DISTANCE, player.brain.ball.bearing_deg + player.brain.loc.h) return RobotLocation( player.brain.ball.x + 250, player.brain.ball.y + CHASER_DISTANCE, player.brain.ball.bearing_deg + player.brain.loc.h) else: southEast = RobotLocation( player.brain.ball.x - CHASER_DISTANCE, player.brain.ball.y - CHASER_DISTANCE, player.brain.ball.bearing_deg + player.brain.loc.h) southWest = RobotLocation( player.brain.ball.x - CHASER_DISTANCE, player.brain.ball.y + CHASER_DISTANCE, player.brain.ball.bearing_deg + player.brain.loc.h) northEast = RobotLocation( player.brain.ball.x + CHASER_DISTANCE, player.brain.ball.y - CHASER_DISTANCE, player.brain.ball.bearing_deg + player.brain.loc.h) northWest = RobotLocation( player.brain.ball.x + CHASER_DISTANCE, player.brain.ball.y + CHASER_DISTANCE, player.brain.ball.bearing_deg + player.brain.loc.h) supportPostitions = [southEast, southWest, northEast, northWest] positionsFilteredByInBounds = [ position for position in supportPostitions if (inBounds(position) and notBlockingGoal(position)) ] if len(positionsFilteredByInBounds) > 0: return min(positionsFilteredByInBounds, key=distanceToPosition(player)) # print "no in bounds position" return southEast
def positionAtHome(player): """ Go to the player's home position. """ if role.isDefender(player.role): home = calculateHomePosition(player) else: home = player.homePosition if player.firstFrame(): player.brain.tracker.trackBall() fastWalk = role.isChaser(player.role) player.brain.nav.goTo(home, precision = nav.HOME, speed = nav.QUICK_SPEED, avoidObstacles = True, fast = fastWalk, pb = False) player.brain.nav.updateDest(home)
def adjustHeading(player): if player.firstFrame(): # Spin to home heading player.stand() player.brain.tracker.repeatFixedPitchLookAhead() dest = RelRobotLocation(0, 0, adjustHeading.desiredHeading - player.brain.loc.h) player.brain.nav.goTo(dest, precision = nav.HOME, speed = speeds.SPEED_SIX, avoidObstacles = False, fast = True, pb = False) # player.setWalk(0, 0, player.brain.loc.h - adjustHeading.desiredHeading) # or math.fabs() if fabs(player.brain.loc.h - adjustHeading.desiredHeading) < 15: player.stand() if role.isDefender(player.role): return player.goNow('watchForBall') else: return player.goNow("panAtWayPoint")
def positionAtHome(player): """ Go to the player's home position. """ if role.isDefender(player.role): home = calculateHomePosition(player) else: home = player.homePosition if player.firstFrame(): player.brain.tracker.trackBall() fastWalk = role.isChaser(player.role) player.brain.nav.goTo(home, precision=nav.HOME, speed=nav.QUICK_SPEED, avoidObstacles=True, fast=fastWalk, pb=False) player.brain.nav.updateDest(home)
def prepareForKick(player): if player.firstFrame(): player.decider = KickDecider.KickDecider(player.brain) player.brain.nav.stand() if not player.inKickOffPlay: if player.shouldKickOff or player.brain.gameController.timeSincePlaying < 10: print "Overriding kick decider for kickoff!" player.shouldKickOff = False player.kick = player.decider.kicksBeforeBallIsFree() else: if roleConstants.isDefender(player.role): player.kick = player.decider.defender() else: player.kick = player.decider.attacker() player.inKickingState = True elif player.finishedPlay: player.inKickOffPlay = False return player.goNow('orbitBall')
def prepareForKick(player): if player.firstFrame(): player.decider = KickDecider.KickDecider(player.brain) player.brain.nav.stand() if not player.inKickOffPlay: if player.shouldKickOff or player.brain.gameController.timeSincePlaying < 10: print "Overriding kick decider for kickoff!" player.shouldKickOff = False player.kick = player.decider.motionKicksAsap() else: # if transitions.shouldChangeKickingStrategy(player): # print "Time for some heroics!" # player.kick = player.decider.timeForSomeHeroics() # else: player.kick = player.decider.obstacleAware(roleConstants.isDefender(player.role)) player.inKickingState = True elif player.finishedPlay: player.inKickOffPlay = False return player.goNow("orbitBall")
def prepareForKick(player): if player.firstFrame(): player.decider = KickDecider.KickDecider(player.brain) player.brain.nav.stand() if not player.inKickOffPlay: if player.shouldKickOff or player.brain.gameController.timeSincePlaying < 10: print "Overriding kick decider for kickoff!" player.shouldKickOff = False player.kick = player.decider.kicksBeforeBallIsFree() else: if roleConstants.isDefender(player.role): player.kick = player.decider.defender() else: player.kick = player.decider.attacker() player.inKickingState = True elif player.finishedPlay: player.inKickOffPlay = False player.motionKick = True return player.goNow('followPotentialField')
def ballInTheirHalf(player): if role.isDefender(player.role): return player.brain.sharedBall.ball_on and (player.brain.sharedBall.x > (nogginC.MIDFIELD_X + nogginC.CENTER_CIRCLE_RADIUS)) return False
def shouldSpinSearchFromWatching(player): shouldExtendTimer = player.commMode == 2 and role.isDefender(player.role) spinTimer = 25 if shouldExtendTimer else 12 return (player.stateTime > spinTimer and player.brain.ball.vis.frames_off > 30)
def ballInTheirHalf(player): if role.isDefender(player.role): return player.brain.sharedBall.ball_on and ( player.brain.sharedBall.x > (nogginC.MIDFIELD_X + nogginC.CENTER_CIRCLE_RADIUS)) return False