def passToCorner(player): if player.firstFrame(): player.passBack = True if roleConstants.isFirstChaser(player.role): corner = Location(nogginC.FIELD_WHITE_WIDTH, 0.) decider = KickDecider.KickDecider(player.brain) player.kick = decider.sweetMovesForKickOff(0, corner) player.inKickingState = True return player.goNow('approachBall') elif roleConstants.isSecondChaser(player.role) or roleConstants.isCherryPicker(player.role): player.brain.tracker.repeatFastTwoIntervalPan() passDestination = Location(nogginC.OPP_GOALBOX_LEFT_X, 60.) player.brain.nav.goTo(passDestination, Navigator.GENERAL_AREA, speeds.SPEED_EIGHT, True, False, True, False) else: return player.goNow('playOffBall') return player.stay() elif constants.shouldPassToFieldCross(player): return player.goNow('passToFieldCross') elif constants.ballNotPassedToCorner(player): player.passBack = False player.inKickOffPlay = False return player.goNow('findBall') else: passDestination = Location(nogginC.OPP_GOALBOX_LEFT_X, 60.) player.brain.nav.updateDest(passDestination) return player.stay()
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 pLeftDeepBack(team, workingPlay): """position deep right back""" workingPlay.setSubRole(PBConstants.LEFT_DEEP_BACK) dest = Location(PBConstants.DEEP_BACK_X, PBConstants.LEFT_DEEP_BACK_Y) h = dest.headingTo(team.brain.ball.loc) pos = (PBConstants.DEEP_BACK_X, PBConstants.LEFT_DEEP_BACK_Y, h) workingPlay.setPosition(pos)
def passToFieldCross(player): if player.firstFrame(): player.passBack = False if roleConstants.isFirstChaser(player.role): player.brain.tracker.repeatFastTwoIntervalPan() fieldCross = Location(nogginC.LANDMARK_OPP_FIELD_CROSS[0], nogginC.LANDMARK_OPP_FIELD_CROSS[1]) player.brain.nav.goTo(fieldCross, Navigator.GENERAL_AREA, speeds.SPEED_EIGHT, True, False, True, False) elif roleConstants.isSecondChaser(player.role) or roleConstants.isCherryPicker(player.role): if not constants.ballIsLost(player): decider = KickDecider.KickDecider(player.brain) # player.kick = decider.bigKicksOnGoal() # player.kick = decider.sweetMovesOnGoal() # player.kick = decider.sweetMoveCrossToCenter() player.kick = decider.decidingStrategy() player.finishedPlay = True player.inKickingState = True return player.goNow('approachBall') else: player.inKickOffPlay = False return player.goNow('findBall') else: return player.goNow('playOffBall') return player.stay() if roleConstants.isFirstChaser(player.role): fieldCross = Location(nogginC.LANDMARK_OPP_FIELD_CROSS[0], nogginC.LANDMARK_OPP_FIELD_CROSS[1]) player.brain.nav.updateDest(fieldCross) if constants.shouldStopWalkingToCross(player): player.inKickOffPlay = False return player.goNow('approachBall') return player.stay()
def determineChaseTime(self): """ Attempt to define a time in seconds to get to the ball. Can give penalties in certain situations. @ return: returns a time in seconds with penalties. Note: Don't give bonuses. It can result in negative chase times which can screw up the math later on. --Wils (06/25/11) """ ballLocation = Location(self.brain.ball.x, self.brain.ball.y) headingBallToGoal = ballLocation.headingTo(OPP_GOAL) relLocToBall = RelRobotLocation(self.brain.ball.rel_x, self.brain.ball.rel_y, headingBallToGoal) time = self.determineTimeToDest(relLocToBall) # Give a penalty for not seeing the ball if we aren't in a kickingState if (self.brain.ball.vis.frames_off > 45 and # TODO: unify this constant with shouldFindBall not self.brain.player.inKickingState): time += BALL_OFF_PENALTY if DEBUG_DETERMINE_DEST_TIME: print "\tChase time after ball on bonus " + str(time) return time
def findDefenderHomeNoBall(player, left): # print "Find defender home WITHOUT ball" if player.brain.staggeredPositioning: if left: print "even defender back no ball stagger" return role.evenDefenderBack else: print "odd defender forward no ball stagger" return role.oddDefenderForward else: if left: if player.brain.loc.distTo(Location(role.evenDefenderBack.x, role.evenDefenderBack.y)) < \ player.brain.loc.distTo(Location(role.evenDefenderForward.x, role.evenDefenderForward.y)): print "even defender forward no ball" return role.evenDefenderForward else: print "even defender back no ball" return role.evenDefenderBack else: if player.brain.loc.distTo(Location(role.oddDefenderBack.x, role.oddDefenderBack.y)) < \ player.brain.loc.distTo(Location(role.oddDefenderForward.x, role.oddDefenderForward.y)): print "odd defender forward no ball" return role.oddDefenderForward else: print "odd defender back no ball" return role.oddDefenderBack
def __init__(self, visionBall): Location.__init__(self, 0.0, 0.0) self.vis = visionBall (self.uncertX, self.uncertY, self.sd, self.velX, self.velY, self.bearing, self.dist, self.uncertVelX, self.uncertVelY, self.heading, self.locDist, self.locBearing, # loc based self.relX, # vision based self.relY, self.relVelX, self.relVelY, self.lastRelX, self.lastRelY, self.dx, self.dy, self.endY, self.accX, self.accY, self.uncertAccX, self.uncertAccY, self.relAccX, self.relAccY) = [0]*Constants.NUM_TOTAL_BALL_VALUES
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 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 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 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 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 pLeftDeepBack(team, workingPlay): """position deep right back""" workingPlay.setSubRole(PBConstants.LEFT_DEEP_BACK) dest = Location(PBConstants.DEEP_BACK_X, PBConstants.LEFT_DEEP_BACK_Y) h = dest.headingTo(team.brain.ball.loc) pos = (PBConstants.DEEP_BACK_X, PBConstants.LEFT_DEEP_BACK_Y,h) workingPlay.setPosition(pos)
def pOffensiveMiddie(team, workingPlay): workingPlay.setSubRole(PBConstants.OFFENSIVE_MIDDIE) y = MyMath.clip(team.brain.ball.loc.y, PBConstants.MIN_MIDDIE_Y, PBConstants.MAX_MIDDIE_Y) dest = Location(PBConstants.OFFENSIVE_MIDDIE_X, y) h = dest.headingTo(team.brain.ball.loc) pos = (PBConstants.OFFENSIVE_MIDDIE_X, y, h) workingPlay.setPosition(pos)
def pRightDeepBack(team, workingPlay): """position deep left back""" workingPlay.setSubRole(PBConstants.RIGHT_DEEP_BACK) dest = Location(PBConstants.DEEP_BACK_X, PBConstants.RIGHT_DEEP_BACK_Y) h = dest.headingTo(Location(team.brain.ball.x, team.brain.ball.y)) pos = (PBConstants.DEEP_BACK_X, PBConstants.RIGHT_DEEP_BACK_Y,h) workingPlay.setPosition(pos)
def print_location_readings(session, location_id: int): loc = Location(location_id) start = datetime.datetime(2020, 1, 1) end = datetime.datetime(2020, 1, 1) interval = datetime.timedelta(minutes=60) for reading in loc.readings(session, start, end, interval): print(reading)
def pDubDMiddie(team, workingPlay): """middie for when in dubD""" workingPlay.setSubRole(PBConstants.DUB_D_MIDDIE) y = MyMath.clip(team.brain.ball.loc.y, PBConstants.MIN_MIDDIE_Y, PBConstants.MAX_MIDDIE_Y) x = PBConstants.OFFENSIVE_MIDDIE_X dest = Location(x, y) h = dest.headingTo(team.brain.ball.loc) pos = (x, y, h) workingPlay.setPosition(pos)
def pPicker(team, workingPlay): """position picker""" workingPlay.setSubRole(PBConstants.PICKER) x = PBConstants.PICKER_X y = PBConstants.PICKER_Y dest = Location(x, y) h = dest.headingTo(team.brain.ball.loc) pos = (x,y,h) workingPlay.setPosition(pos)
def pStopper(team, workingPlay): """position stopper""" workingPlay.setSubRole(PBConstants.STOPPER) x = PBConstants.STOPPER_X y = MyMath.clip(team.brain.ball.loc.y, PBConstants.MIN_STOPPER_Y, PBConstants.MAX_STOPPER_Y) dest = Location(x, y) h = dest.headingTo(team.brain.ball.loc) pos = (x, y, h) workingPlay.setPosition(pos)
def pCenterBack(team, workingPlay): """position center back""" workingPlay.setSubRole(PBConstants.CENTER_BACK) x, y = team.getPointBetweenBallAndGoal(team.brain.ball, PBConstants.DEFENDER_BALL_DIST) x = MyMath.clip(x, PBConstants.SWEEPER_X, PBConstants.STOPPER_X) y = MyMath.clip(y, PBConstants.MIN_CENTER_BACK_Y, PBConstants.MAX_CENTER_BACK_Y) dest = Location(x, y) h = dest.headingTo(team.brain.ball.loc) pos = (x, y, h) workingPlay.setPosition(pos)
def strategize(self, play): """ creates a play, picks the strategy to run, returns the play after it is modified by Strategies """ currentGCState = self.brain.player.gameState # We don't control anything in initial or finished if (currentGCState == 'gameInitial' or currentGCState == 'gameFinished'): play.setRole(PBConstants.INIT_ROLE) self.lastBallX = -1 self.lastBallY = -1 return # Have a separate strategy to easily deal with being penalized elif not self.me.active: play.setRole(PBConstants.PENALTY_ROLE) self.lastBallX = -1 self.lastBallY = -1 return # Special case for the goalie if (self.me.isDefaultGoalie()): # Make sure the goalie's role is set play.setRole(PBConstants.GOALIE) dest = Location(PBConstants.GOALIE_HOME_X, PBConstants.GOALIE_HOME_Y) h = dest.headingTo(Location(self.brain.ball.x, self.brain.ball.y)) pos = (PBConstants.GOALIE_HOME_X, PBConstants.GOALIE_HOME_Y, h) play.setPosition(pos) return # Have a separate ready section to make things simpler if (currentGCState == 'gameReady' or currentGCState =='gameSet'): if (currentGCState == 'gameReady'): self.lastBallX = -1 self.lastBallY = -1 self.readyPosition(play) return # Update the current grid square that the ball is. self.ballUpdate() test = False # Check test cases if (PBConstants.TEST_DEFENDER or PBConstants.TEST_OFFENDER or PBConstants.TEST_MIDDIE or PBConstants.TEST_CHASER): test = True # Use the playbook table to determine position. self.priorityPositions( self.tableLookup(self.lastBallX, self.lastBallY, test) , play)
def pSweeper(team, workingPlay): """position sweeper""" workingPlay.setSubRole(PBConstants.SWEEPER) x = PBConstants.SWEEPER_X y = PBConstants.SWEEPER_Y y += PBConstants.SWEEPER_Y_OFFSET * MyMath.sign(team.brain.ball.loc.y - NogginConstants.CENTER_FIELD_Y) dest = Location(x, y) h = dest.headingTo(team.brain.ball.loc) pos = (x, y, h) workingPlay.setPosition(pos)
def pGoalieSave(team, workingPlay): """ goalie saving """ workingPlay.setSubRole(PBConstants.GOALIE_SAVE) dest = Location(PBConstants.GOALIE_HOME_X, PBConstants.GOALIE_HOME_Y) h = dest.headingTo(team.brain.ball.loc) pos = (PBConstants.GOALIE_HOME_X, PBConstants.GOALIE_HOME_Y, h) if PBConstants.USE_FANCY_GOALIE: pos = team.fancyGoaliePosition() workingPlay.setPosition(pos)
def pGoalieCenter(team, workingPlay): """normal goalie position in the center of the goal""" workingPlay.setSubRole(PBConstants.GOALIE_CENTER) dest = Location(PBConstants.GOALIE_HOME_X, PBConstants.GOALIE_HOME_Y) h = dest.headingTo(team.brain.ball.loc) pos = (PBConstants.GOALIE_HOME_X, PBConstants.GOALIE_HOME_Y, h) if PBConstants.USE_FANCY_GOALIE: pos = team.fancyGoaliePosition() workingPlay.setPosition(pos)
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 pGoalieChaser(team, workingPlay): """goalie is being a chaser, presumably in/near goalbox not intended for pulling the goalie situations""" workingPlay.setSubRole(PBConstants.GOALIE_CHASER) dest = Location(PBConstants.GOALIE_HOME_X, PBConstants.GOALIE_HOME_Y) h = dest.headingTo(team.brain.ball.loc) pos = (PBConstants.GOALIE_HOME_X, PBConstants.GOALIE_HOME_Y, h) if PBConstants.USE_FANCY_GOALIE: pos = team.fancyGoaliePosition() workingPlay.setPosition(pos)
def pRightWing(team, workingPlay): """position right winger""" workingPlay.setSubRole(PBConstants.RIGHT_WING) midpoint = (PBConstants.WING_MAX_X - PBConstants.WING_MIN_X) * 0.5 scale = (PBConstants.WING_MAX_X - midpoint) / (PBConstants.PICKER_X_THRESH - midpoint) x = -1 * scale * (team.brain.ball.loc.x - midpoint) y = PBConstants.RIGHT_WING_Y dest = Location(x, y) h = dest.headingTo(team.brain.ball.loc) pos = (x, y, h) workingPlay.setPosition(pos)
def move_forward(self, location, orientation): if orientation == Orientation.east: return Location.Location(location.x + 1, location.y) elif orientation == Orientation.west: return Location.Location(location.x - 1, location.y) elif orientation == Orientation.south: return Location.Location(location.x, location.y - 1) elif orientation == Orientation.north: return Location.Location(location.x, location.y + 1)
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 pSweeper(team, workingPlay): """position sweeper""" workingPlay.setSubRole(PBConstants.SWEEPER) x = PBConstants.SWEEPER_X y = PBConstants.SWEEPER_Y y += PBConstants.SWEEPER_Y_OFFSET * \ MyMath.sign(team.brain.ball.loc.y-NogginConstants.CENTER_FIELD_Y) dest = Location(x, y) h = dest.headingTo(team.brain.ball.loc) pos = (x, y, h) workingPlay.setPosition(pos)
def pForward(team, workingPlay): """position forward""" workingPlay.setSubRole(PBConstants.FORWARD) x = PBConstants.FORWARD_X if team.brain.ball.loc.y < NogginConstants.CENTER_FIELD_Y: y = PBConstants.LEFT_FORWARD_Y else: y = PBConstants.RIGHT_FORWARD_Y dest = Location(x, y) h = dest.headingTo(team.brain.ball.loc) pos = (x, y, h) workingPlay.setPosition(pos)
def pStriker(team, workingPlay): """position striker""" workingPlay.setSubRole(PBConstants.STRIKER) x = PBConstants.STRIKER_X if team.brain.ball.loc.y < NogginConstants.CENTER_FIELD_Y: y = PBConstants.LEFT_STRIKER_Y else: y = PBConstants.RIGHT_STRIKER_Y dest = Location(x, y) h = dest.headingTo(team.brain.ball.loc) pos = (x, y, h) workingPlay.setPosition(pos)
def pRightWing(team, workingPlay): """position right winger""" workingPlay.setSubRole(PBConstants.RIGHT_WING) midpoint = (PBConstants.WING_MAX_X - PBConstants.WING_MIN_X)*.5 scale = (PBConstants.WING_MAX_X - midpoint)/(PBConstants.PICKER_X_THRESH - midpoint) x = -1*scale*(team.brain.ball.loc.x - midpoint) y = PBConstants.RIGHT_WING_Y dest = Location(x, y) h = dest.headingTo(team.brain.ball.loc) pos = (x, y, h) workingPlay.setPosition(pos)
def pLeftWing(team, workingPlay): """position left winger""" workingPlay.setSubRole(PBConstants.LEFT_WING) midpoint = (PBConstants.WING_MAX_X - PBConstants.WING_MIN_X)*.5 scale = (PBConstants.WING_MAX_X - midpoint)/(PBConstants.PICKER_X_THRESH - midpoint) x = -1*scale*(team.brain.ball.x - midpoint) y = PBConstants.LEFT_WING_Y dest = Location(x, y) h = dest.headingTo(Location(team.brain.ball.x, team.brain.ball.y)) pos = (x,y,h) workingPlay.setPosition(pos)
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 sidePass(player): if player.firstFrame(): player.passBack = True if roleConstants.isFirstChaser(player.role): decider = KickDecider.KickDecider(player.brain) passDest = Location(nogginC.MIDFIELD_X + constants.SIDE_PASS_OFFSET, 0.) player.kick = decider.sweetMovesForKickOff(-1, passDest) player.inKickingState = True return player.goNow('approachBall') elif roleConstants.isSecondChaser(player.role) or roleConstants.isCherryPicker(player.role): pass else: return player.goNow('playOffBall') return player.stay() if constants.sidePassFinished(player): if constants.isSeeingBall(player): return player.goNow('passToFieldCross') elif constants.didNotRecieveSidePass(player): player.passBack = False player.inKickOffPlay = False return player.goNow('findBall') return player.stay()
def generate_maze(self, startX, startY): self.visited[startX][startY] = True self.cells[startX][startY].location = Location.Location(startX,startY) while (not self.visited[startX][startY + 1]) or (not self.visited[startX + 1][startY]) or ( not self.visited[startX][startY - 1]) or (not self.visited[startX - 1][startY]): while (True): # Choose a direction to move to 1 = North, 2 = East , 3 = South , 4 = West chosen_direction = random.randint(1, 4) if chosen_direction == 1 and not self.visited[startX][startY + 1]: self.cells[startX][startY].north = False self.cells[startX][startY + 1].south = False self.generate_maze(startX, startY + 1) break if chosen_direction == 2 and not self.visited[startX + 1][startY]: self.cells[startX][startY].east = False self.cells[startX + 1][startY].west = False self.generate_maze(startX + 1, startY) break if chosen_direction == 3 and not self.visited[startX][startY - 1]: self.cells[startX][startY].south = False self.cells[startX][startY - 1].north = False self.generate_maze(startX, startY - 1) break if chosen_direction == 4 and not self.visited[startX - 1][startY]: self.cells[startX][startY].west = False self.cells[startX - 1][startY].east = False self.generate_maze(startX - 1, startY) break
def addPassesToFieldCross(self): betweenFieldCrossAndGoalBoxLeft = (nogginC.LANDMARK_OPP_FIELD_CROSS[0] + nogginC.OPP_GOALBOX_LEFT_X) / 2. location = Location(betweenFieldCrossAndGoalBoxLeft, nogginC.CENTER_FIELD_Y) self.addPassesTo(location)
def pKickoffStriker(team, workingPlay): """position kickoff striker""" workingPlay.setSubRole(PBConstants.KICKOFF_STRIKER) x = PBConstants.KICKOFF_OFFENDER_X if team.kickoffFormation == 0: y = PBConstants.KICKOFF_OFFENDER_0_Y else: y = PBConstants.KICKOFF_OFFENDER_1_Y # We want to face the center (where the ball is, from our location) dest = Location(x,y) h = dest.headingTo(PBConstants.CENTER_FIELD) pos = (x,y,h) workingPlay.setPosition(pos)
def pCenterBack(team, workingPlay): """position center back""" workingPlay.setSubRole(PBConstants.CENTER_BACK) x,y = team.getPointBetweenBallAndGoal(team.brain.ball, PBConstants.DEFENDER_BALL_DIST) x = MyMath.clip(x, PBConstants.SWEEPER_X, PBConstants.STOPPER_X) y = MyMath.clip(y, PBConstants.MIN_CENTER_BACK_Y, PBConstants.MAX_CENTER_BACK_Y) dest = Location(x, y) h = dest.headingTo(team.brain.ball.loc) pos = (x, y, h) workingPlay.setPosition(pos)
def pReadyChaser(team, workingPlay): workingPlay.setSubRole(PBConstants.READY_CHASER) kickOff = team.brain.gameController.ownKickOff if kickOff: x = PBConstants.READY_KICKOFF_CHASER_X y = PBConstants.READY_KICKOFF_CHASER_Y else: x = PBConstants.READY_NON_KICKOFF_CHASER_X if team.kickoffFormation == 0: y = PBConstants.READY_NON_KICKOFF_CHASER_0_Y else: y = PBConstants.READY_NON_KICKOFF_CHASER_1_Y dest = Location(x, y) h = dest.headingTo(PBConstants.CENTER_FIELD) pos = (x,y,h) workingPlay.setPosition(pos)
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 orbitBall(player): """ State to orbit the ball """ if player.firstFrame(): if hackKick.DEBUG_KICK_DECISION: print "Orbiting at angle: ", player.kick.h if player.kick.h == 0: return player.goNow("positionForKick") elif player.kick.h < 0: # set y vel at 50% speed print "Turn to left, move right" player.brain.nav.walk(0, -0.7, 0.25) elif player.kick.h > 0: # set y vel at 50% speed in opposite direction print "Turn to right, move left" player.brain.nav.walk(0, 0.7, -0.25) elif player.brain.nav.isStopped(): player.shouldOrbit = False player.kick.h = 0 player.kick = kicks.chooseAlignedKickFromKick(player, player.kick) return player.goNow("positionForKick") # all of this is basically the same as in shoot() in hackKickInformation goalCenter = Location(nogginConstants.FIELD_WHITE_RIGHT_SIDELINE_X, nogginConstants.CENTER_FIELD_Y) ballLocation = Location(player.brain.ball.x, player.brain.ball.y) headingBallToGoalCenter = ballLocation.headingTo(goalCenter) bearingForKick = headingBallToGoalCenter - player.brain.loc.h # the kick was chosen before we came into orbitBall() if player.kick.isStraightKick(): orbitBall.desiredHeading = 0 - bearingForKick elif player.kick == kicks.RIGHT_SIDE_KICK: orbitBall.desiredHeading = 70 - bearingForKick elif player.kick == kicks.LEFT_SIDE_KICK: orbitBall.desiredHeading = -70 - bearingForKick elif player.kick.isBackKick(): if bearingForKick < -125: orbitBall.desiredHeading = -180 - bearingForKick else: orbitBall.desiredHeading = 180 - bearingForKick # #debugging # if player.counter%20 == 0: # print "desiredHeading is: | ", orbitBall.desiredHeading # print "ball to goal center:| ", headingBallToGoalCenter # print "player heading: | ", player.brain.loc.h # print "bearing for kick: | ", bearingForKick # print "walk is: | (",player.brain.nav.getXSpeed(),",",player.brain.nav.getYSpeed(),",",player.brain.nav.getHSpeed(),")" # print "=====================++++++++++" # our in-house heading checker is of the opinion that we're pointed in the right direction if orbitBall.desiredHeading > -10 and orbitBall.desiredHeading < 10: player.stopWalking() print "Done orbiting, going to positionForKick" player.shouldOrbit = False player.kick.h = 0 player.kick = kicks.chooseAlignedKickFromKick(player, player.kick) return player.goNow("positionForKick") if player.stateTime > 8: print "In state orbitBall for too long, switching to chase" player.shouldOrbit = False player.stopWalking() player.inKickingState = False return player.goLater("chase") # These next three if statements might need some fine tuning # ATM that doesn't appear to be the case if constants.ORBIT_BALL_DISTANCE < player.brain.ball.distance - 7: # We're too far away player.brain.nav.setXSpeed(0.15) if constants.ORBIT_BALL_DISTANCE > player.brain.ball.distance + 1: # We're too close player.brain.nav.setXSpeed(-0.15) if ( constants.ORBIT_BALL_DISTANCE > player.brain.ball.distance - 1 and constants.ORBIT_BALL_DISTANCE < player.brain.ball.distance + 1 ): # print "We're at a good distance" player.brain.nav.setXSpeed(0) if transitions.shouldFindBallKick(player) or transitions.shouldCancelOrbit(player): player.inKickingState = False return player.goLater("chase") if player.kick.h > 0: # Orbiting clockwise if player.brain.ball.rel_y > 2: player.brain.nav.setHSpeed(0) # print "turn clockwise SLOWER" elif player.brain.ball.rel_y < 2: player.brain.nav.setHSpeed(-0.35) # print "turn clockwise FASTER" else: player.brain.nav.setHSpeed(-0.25) # print "turn clockwise NORMAL" else: # Orbiting counter-clockwise if player.brain.ball.rel_y > 2: player.brain.nav.setHSpeed(0.35) # print "turn counterclockwise FASTER" elif player.brain.ball.rel_y < 2: player.brain.nav.setHSpeed(0) # print "turn counterclockwise SLOWER" else: player.brain.nav.setHSpeed(0.25) # print "turn clockwise NORMAL" return player.stay()
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)