def forwardProgress(self, kick): goalCenter = Location(nogginC.FIELD_WHITE_RIGHT_SIDELINE_X, nogginC.MIDFIELD_Y) ball = Location(self.brain.ball.x, self.brain.ball.y) kickDestination = Location(kick.destinationX, kick.destinationY) return goalCenter.distTo(ball) > goalCenter.distTo(kickDestination)
def notTowardOurGoal(self, kick): # do not kick into our goalbox ball = self.brain.ball inBox = ( ball.x > nogginC.GREEN_PAD_X and ball.x < nogginC.BLUE_GOALBOX_RIGHT_X and ball.y < nogginC.BLUE_GOALBOX_TOP_Y and ball.y > nogginC.BLUE_GOALBOX_BOTTOM_Y ) intoBox = ( kick.destinationX > nogginC.GREEN_PAD_X and kick.destinationX < nogginC.BLUE_GOALBOX_RIGHT_X and kick.destinationY < nogginC.BLUE_GOALBOX_TOP_Y and kick.destinationY > nogginC.BLUE_GOALBOX_BOTTOM_Y ) print "inBox returned" if intoBox and not inBox: return False else: goalCenter = Location(nogginC.FIELD_WHITE_LEFT_SIDELINE_X, nogginC.MIDFIELD_Y) ball = Location(ball.x, ball.y) kickDestination = Location(kick.destinationX, kick.destinationY) return goalCenter.distTo(ball) < goalCenter.distTo(kickDestination)
def flipLocFilter(self): """ Check where the goalie sees the ball and where we do. Record if we're generally correct, or if our flipped location is generally correct, or if neither one agrees with the goalie. NOTE: ignore whenever the ball is in the middle 2x2 meter box. """ # Get goalie data for mate in self.teamMembers: if mate.isDefaultGoalie() and mate.active: if mate.ballOn and self.ball.vis.on: # calculate global ball coordinates # note: assume goalie is in center of goal. goalie_x = Constants.FIELD_WHITE_LEFT_SIDELINE_X goalie_y = Constants.MIDFIELD_Y ball_x = goalie_x + (mate.ballDist * math.cos(mate.ballBearing)) ball_y = goalie_y + (mate.ballDist * math.sin(mate.ballBearing)) goalie_ball_location = Location(ball_x, ball_y) # check against my data my_ball_location = Location(self.ball.x, self.ball.y) flipped_ball_location = Location(Constants.FIELD_GREEN_WIDTH - self.ball.x, Constants.FIELD_GREEN_HEIGHT - self.ball.y) if (mate.ballDist < 250 and self.loc.x > Constants.MIDFIELD_X and self.ball.x > Constants.MIDFIELD_X): # I'm probably flipped! self.updateFlipFilters(-1) print "Goalie saw the ball close, and I think I and it are far." print "Goalie sees ball at: " + str(goalie_ball_location) break if (goalie_ball_location.inCenterCenter() or my_ball_location.inCenterCenter()): # Ball is too close to the middle of the field. Risky. self.updateFlipFilters(0) break if my_ball_location.distTo(goalie_ball_location) < 70: # I'm probably in the right place! self.updateFlipFilters(1) elif flipped_ball_location.distTo(goalie_ball_location) < 70: # I'm probably flipped! self.updateFlipFilters(-1) else: # I don't agree with the goalie. Ignore. self.updateFlipFilters(0) # If I've decided I should flip enough times, actually do it. if (len(self.flipFilter) == 10 and sum(self.flipFilter) > 6): self.flipLoc() # Reset filters! Don't want to flip again next frame. self.noFlipFilter = [] self.flipFilter = []
def flipLocFilter(self): """ Check where the goalie sees the ball and where we do. Record if we're generally correct, or if our flipped location is generally correct, or if neither one agrees with the goalie. NOTE: ignore whenever the ball is in the middle 2x2 meter box. """ # Get goalie data for mate in self.teamMembers: if mate.isDefaultGoalie() and mate.active: if mate.ballOn and self.ball.vis.on: # calculate global ball coordinates # note: assume goalie is in center of goal. goalie_x = Constants.FIELD_WHITE_LEFT_SIDELINE_X goalie_y = Constants.MIDFIELD_Y ball_x = goalie_x + (mate.ballDist * math.cos(mate.ballBearing)) ball_y = goalie_y + (mate.ballDist * math.sin(mate.ballBearing)) goalie_ball_location = Location(ball_x, ball_y) # check against my data my_ball_location = Location(self.ball.x, self.ball.y) flipped_ball_location = Location(Constants.FIELD_GREEN_WIDTH - self.ball.x, Constants.FIELD_GREEN_HEIGHT - self.ball.y) if (mate.ballDist < 250 and self.loc.x > Constants.MIDFIELD_X and self.ball.x > Constants.MIDFIELD_X): # I'm probably flipped! self.updateFlipFilters(-1) print "Goalie saw the ball close, and I think I and it are far." print "Goalie sees ball at: " + str(goalie_ball_location) break if (goalie_ball_location.inCenterCenter() or my_ball_location.inCenterCenter()): # Ball is too close to the middle of the field. Risky. self.updateFlipFilters(0) break if my_ball_location.distTo(goalie_ball_location) < 70: # I'm probably in the right place! self.updateFlipFilters(1) elif flipped_ball_location.distTo(goalie_ball_location) < 70: # I'm probably flipped! self.updateFlipFilters(-1) else: # I don't agree with the goalie. Ignore. self.updateFlipFilters(0) # If I've decided I should flip enough times, actually do it. if (len(self.flipFilter) == 10 and sum(self.flipFilter) > 6): self.flipLoc() # Reset filters! Don't want to flip again next frame. self.noFlipFilter = [] self.flipFilter = []
def searchFieldForFlippedSharedBall(player): """ Flips the shared ball and searches for it. """ sharedball = Location(-1*(player.brain.sharedBall.x-NogginConstants.MIDFIELD_X) + NogginConstants.MIDFIELD_X, -1*(player.brain.sharedBall.y-NogginConstants.MIDFIELD_Y) + NogginConstants.MIDFIELD_Y) if player.firstFrame(): player.brain.tracker.trackBall() player.brain.tracker.repeatWideSnapPan() player.sharedBallCloseCount = 0 player.brain.nav.goTo(sharedball, precision = nav.GENERAL_AREA, speed = speeds.SPEED_EIGHT, avoidObstacles = True, fast = True, pb = False) if sharedball.distTo(player.brain.loc) < 100: player.sharedBallCloseCount += 1 else: player.sharedBallCloseCount = 0 if not transitions.shouldFindSharedBall(player): player.sharedBallOffCount += 1 else: player.sharedBallOffCount = 0 player.brain.nav.updateDest(sharedball)
def searchFieldForSharedBall(player): """ Searches the field for the shared ball. """ sharedball = Location(player.brain.sharedBall.x, player.brain.sharedBall.y) if player.firstFrame(): player.brain.tracker.trackBall() player.brain.tracker.repeatWideSnapPan() player.sharedBallCloseCount = 0 player.sharedBallOffCount = 0 player.brain.nav.goTo(sharedball, precision = nav.GENERAL_AREA, speed = speeds.SPEED_EIGHT, avoidObstacles = True, fast = True, pb = False) if sharedball.distTo(player.brain.loc) < 100: player.sharedBallCloseCount += 1 else: player.sharedBallCloseCount = 0 if not transitions.shouldFindSharedBall(player): player.sharedBallOffCount += 1 else: player.sharedBallOffCount = 0 player.brain.nav.updateDest(sharedball)
def obstacleAware(self, clearing=False): motionKicksOnGoal = self.motionKicksAsapOnGoal() if motionKicksOnGoal: return motionKicksOnGoal # if self.checkObstacle(1, 75): # inScrum = self.motionKicksInScrumAsap() # if inScrum: # return inScrum if (not self.checkObstacle(1, 215) and not self.checkObstacle(1, 215) and not self.checkObstacle(8, 215)): goalCenter = Location(nogginC.FIELD_WHITE_RIGHT_SIDELINE_X, nogginC.MIDFIELD_Y) ball = Location(self.brain.ball.x, self.brain.ball.y) if ball.distTo(goalCenter) <= 400: timeAndSpace = self.frontKicksOrbitIfSmall() if timeAndSpace: return timeAndSpace elif clearing: clear = self.frontKicksClear() if clear: return clear asap = self.motionKicksAsap() if asap: return asap return self.frontKickCrosses()
def obstacleAware(self, clearing=False): motionKicksOnGoal = self.motionKicksAsapOnGoal() if motionKicksOnGoal: return motionKicksOnGoal # if self.checkObstacle(1, 75): # inScrum = self.motionKicksInScrumAsap() # if inScrum: # return inScrum if not self.checkObstacle(1, 215) and not self.checkObstacle(1, 215) and not self.checkObstacle(8, 215): goalCenter = Location(nogginC.FIELD_WHITE_RIGHT_SIDELINE_X, nogginC.MIDFIELD_Y) ball = Location(self.brain.ball.x, self.brain.ball.y) if ball.distTo(goalCenter) <= 400: timeAndSpace = self.frontKicksOrbitIfSmall() if timeAndSpace: return timeAndSpace elif clearing: clear = self.frontKicksClear() if clear: return clear asap = self.motionKicksAsap() if asap: return asap return self.frontKickCrosses()
def notTowardOurGoal(self, kick): # do not kick into our goalbox ball = self.brain.ball inBox = (ball.x > nogginC.GREEN_PAD_X and ball.x < nogginC.BLUE_GOALBOX_RIGHT_X and ball.y < nogginC.BLUE_GOALBOX_TOP_Y and ball.y > nogginC.BLUE_GOALBOX_BOTTOM_Y) intoBox = (kick.destinationX > nogginC.GREEN_PAD_X and kick.destinationX < nogginC.BLUE_GOALBOX_RIGHT_X and kick.destinationY < nogginC.BLUE_GOALBOX_TOP_Y and kick.destinationY > nogginC.BLUE_GOALBOX_BOTTOM_Y) # print "inBox returned" if intoBox and not inBox: return False else: goalCenter = Location(nogginC.FIELD_WHITE_LEFT_SIDELINE_X, nogginC.MIDFIELD_Y) ball = Location(ball.x, ball.y) kickDestination = Location(kick.destinationX, kick.destinationY) return goalCenter.distTo(ball) < goalCenter.distTo(kickDestination)
def shouldKickOff(self): """ Tells the decider if we should kickOff. Also sets the player constant. """ if self.brain.player.shouldKickOff: centerField = Location(NogginConstants.CENTER_FIELD_X, NogginConstants.CENTER_FIELD_Y) self.brain.player.shouldKickOff = (centerField.distTo(self.brain.ball) < NogginConstants.CENTER_CIRCLE_RADIUS) return self.brain.player.shouldKickOff else: return False
def timeForSomeHeroics(self): asapOnGoal = self.allKicksIncludingBigKickAsapOnGoal() if asapOnGoal: return asapOnGoal # TODO hack for Brazil goalCenter = Location(nogginC.FIELD_WHITE_RIGHT_SIDELINE_X, nogginC.MIDFIELD_Y) ball = Location(self.brain.ball.x, self.brain.ball.y) if ball.distTo(goalCenter) <= 200: return self.frontKicksOrbit() return self.bigKicksOrbit()
def shouldKickOff(self): """ Tells the decider if we should kickOff. Also sets the player constant. """ if self.brain.player.shouldKickOff: centerField = Location(NogginConstants.CENTER_FIELD_X, NogginConstants.CENTER_FIELD_Y) self.brain.player.shouldKickOff = \ (centerField.distTo(self.brain.ball.loc) < NogginConstants.CENTER_CIRCLE_RADIUS) return self.brain.player.shouldKickOff else: return False
def timeForSomeHeroics(self): asapOnGoal = self.allKicksIncludingBigKickAsapOnGoal() if asapOnGoal: return asapOnGoal # TODO hack for Brazil goalCenter = Location(nogginC.FIELD_WHITE_RIGHT_SIDELINE_X, nogginC.MIDFIELD_Y) ball = Location(self.brain.ball.x, self.brain.ball.y) if ball.distTo(goalCenter) <= 200: return self.frontKicksOrbit() return self.bigKicksOrbit()
def findStrikerHome(ball, hh): if not hasattr(findStrikerHome, 'upperHalf'): findStrikerHome.upperHalf = (ball.y - NogginConstants.CENTER_FIELD_Y) >= 0 # the buffer zone is twice this because its this distance on each side of midfield # the buffer keeps us from oscillating sides of the field when the ball is near the center line oscBuff = 50 if findStrikerHome.upperHalf and ( ball.y - NogginConstants.CENTER_FIELD_Y) < -1 * oscBuff: findStrikerHome.upperHalf = False elif not findStrikerHome.upperHalf and ( ball.y - NogginConstants.CENTER_FIELD_Y) > oscBuff: findStrikerHome.upperHalf = True goalCenter = Location(NogginConstants.FIELD_WHITE_RIGHT_SIDELINE_X, NogginConstants.MIDFIELD_Y) ballToGoal = Location(goalCenter.x - ball.x, goalCenter.y - ball.y) # vector # avoid divide by zeros if ballToGoal == Location(0, 0): ballToGoal = Location(1, 0) # the point at which we draw our normal vector from percentageToPivot = 0.8 pivotPoint = Location(ball.x + ballToGoal.x * 0.7, ball.y + ballToGoal.y * 0.7) # two possible normal vectors. If ball.y is greater than midfield.y choose (dy, -dx) # else choose (-dy, dx) if findStrikerHome.upperHalf: normalVect = Location(ballToGoal.y, -1 * ballToGoal.x) else: normalVect = Location(-1 * ballToGoal.y, ballToGoal.x) # normalize the vector and make its magnitude to the desired value normalVectLength = 100 normalizeMag = normalVectLength / normalVect.distTo(Location(0, 0)) normalVect.x *= normalizeMag normalVect.y *= normalizeMag strikerHome = RobotLocation(pivotPoint.x + normalVect.x, pivotPoint.y + normalVect.y, hh) # if for some reason you get placed off the field project back onto the field if strikerHome.x > NogginConstants.FIELD_WHITE_RIGHT_SIDELINE_X - 20: strikerHome.x = NogginConstants.FIELD_WHITE_RIGHT_SIDELINE_X - 20 return strikerHome
def findStrikerHome(ball, hh): if not hasattr(findStrikerHome, 'upperHalf'): findStrikerHome.upperHalf = (ball.y - NogginConstants.CENTER_FIELD_Y) >= 0 # the buffer zone is twice this because its this distance on each side of midfield # the buffer keeps us from oscillating sides of the field when the ball is near the center line oscBuff = 50 if findStrikerHome.upperHalf and (ball.y - NogginConstants.CENTER_FIELD_Y) < -1*oscBuff: findStrikerHome.upperHalf = False elif not findStrikerHome.upperHalf and (ball.y - NogginConstants.CENTER_FIELD_Y) > oscBuff: findStrikerHome.upperHalf = True goalCenter = Location(NogginConstants.FIELD_WHITE_RIGHT_SIDELINE_X, NogginConstants.MIDFIELD_Y) ballToGoal = Location(goalCenter.x - ball.x, goalCenter.y - ball.y) # vector # avoid divide by zeros if ballToGoal == Location(0, 0): ballToGoal = Location (1, 0) # the point at which we draw our normal vector from percentageToPivot = 0.8 pivotPoint = Location(ball.x + ballToGoal.x*0.7, ball.y + ballToGoal.y*0.7) # two possible normal vectors. If ball.y is greater than midfield.y choose (dy, -dx) # else choose (-dy, dx) if findStrikerHome.upperHalf: normalVect = Location(ballToGoal.y, -1*ballToGoal.x) else: normalVect = Location(-1*ballToGoal.y, ballToGoal.x) # normalize the vector and make its magnitude to the desired value normalVectLength = 100 normalizeMag = normalVectLength/normalVect.distTo(Location(0,0)) normalVect.x *= normalizeMag normalVect.y *= normalizeMag strikerHome = RobotLocation(pivotPoint.x + normalVect.x , pivotPoint.y + normalVect.y, hh) # if for some reason you get placed off the field project back onto the field if strikerHome.x > NogginConstants.FIELD_WHITE_RIGHT_SIDELINE_X - 20: strikerHome.x = NogginConstants.FIELD_WHITE_RIGHT_SIDELINE_X - 20 return strikerHome
def forwardProgress(self, kick): goalCenter = Location(nogginC.FIELD_WHITE_RIGHT_SIDELINE_X, nogginC.MIDFIELD_Y) ball = Location(self.brain.ball.x, self.brain.ball.y) kickDestination = Location(kick.destinationX, kick.destinationY) return goalCenter.distTo(ball) > goalCenter.distTo(kickDestination)