def receiveKickOffEchelon(): global playCounter if playCounter > 85: return False # Centre always charges if pReady.isCentre(Global.kickOffPos): hFWHead.DecideNextAction() sFindBall.walkToBall(Global.ballD, Global.ballH) return True # Wide players charge iff obstacle # Count obstacles forward on our side of the field if Global.selfLoc.getX() > Constant.FIELD_WIDTH / 2: tlx = Constant.FIELD_WIDTH / 2 + 40 brx = Constant.FIELD_WIDTH - 40 else: tlx = 40 brx = Constant.FIELD_WIDTH / 2 - 40 tly = Constant.FIELD_LENGTH / 2 + 50 bry = Constant.FIELD_LENGTH / 2 - 100 nobs = VisionLink.getNoObstacleInBox(tlx, tly, brx, bry, 20, Constant.OBS_USE_SHARED) hFWHead.DecideNextAction() #print "nobs:", nobs if nobs < 40: # no opp == defend rDefender.DecideNextAction() else: # opp = charge sFindBall.walkToBall(Global.ballD, Global.ballH) return True
def perform(params=None): global gBirdToBall id(params) # ignore resetEachFrame() # Back off if stuck if hStuck.amIStuckForward(): hFWHead.DecideNextAction() return targetX, targetY, _rangeX = hWhere.getSupporterPos() selfX, selfY = Global.selfLoc.getPos() hFWHead.DecideNextAction() # If the attacker has grabbed, get out of the way if hTeam.hasTeammateGrabbedBall(): if getOutOfEveryonesWay(): return # Continue BOP if one is executing if sBirdOfPrey.isBirdOfPreyTriggering(): if sBirdOfPrey.birdTo == sBirdOfPrey.BIRD_TO_BALL: birdPos = (Global.ballX, Global.ballY) else: birdPos = (targetX, targetY) if sBirdOfPrey.perform(*birdPos) == Constant.STATE_EXECUTING: hFWHead.minPosVariance = 1 # look around more often hFWHead.DecideNextAction() return # Stay out of the shot line and away from robots. This is after the bird # since the bird is more important than most of these, and DodgyDog in # the bird should keep us clear if getOutOfEveryonesWay(): return # If I have lost the ball for a while, then find the ball. # Don't trust gps for a long time, because after a few frames, gps ball # will direct you to no where. It is better for the robot to go into find # ball mode. if Global.ballSource == Constant.GPS_BALL and \ Global.lostBall >= 2 * Constant.LOST_BALL_SCAN: Indicator.showFacePattern([5, 0, 0, 0, 5]) sFindBall.findBySpin() return # Move to supporter position supportBall() # Bird back to position if I am way in front if targetY < selfY - BIRD_TO_POS_THRESH: sBirdOfPrey.birdTo = sBirdOfPrey.BIRD_TO_POS if sBirdOfPrey.perform(targetX, targetY) == Constant.STATE_EXECUTING: return
def DecideNextAction(): global doKickOff resetEachFrame() rSetPlay.resetPerform() Global.firstPlayFrame = Global.frame + 1 #import Constant #print rSetPlay.getGapTo(Constant.MAX_GOALBOX_EDGE_X, Constant.TOP_GOALBOX_EDGE_Y) #print rSetPlay.getObstaclesToGoal() # Receiving team look at the ball # FIXME: look to front for obstacles too if VisionLink.getKickOffTeam() != VisionLink.getTeamColor(): if pReady.isCentre(Global.kickOffPos): hTrack.stationaryLocalise() else: hFWHead.DecideNextAction() # Kicker looks at ball (no localise). Others scan to see obstacles elif pReady.isCentre(Global.kickOffPos): sFindBall.perform(True) elif pReady.isForward(Global.kickOffPos): hTrack.stationaryLocalise(4, 30, -30) else: hTrack.stationaryLocalise() Indicator.showBatteryStatus() doKickOff = True
def receiveKickOffPincer(): global playCounter if playCounter > 85: return False if pReady.isCentre(Global.kickOffPos): if playCounter < 65: Global.myRole = Global.myLastRole = Constant.DEFENDER if sBlock.checkThenBlock(True, 3.0, bothSides=True): return sFindBall.perform(True) hTrack.saGoToTargetFacingHeading(Constant.FIELD_WIDTH / 2, Constant.FIELD_LENGTH * 0.29, 90, maxSpeed=20) #rDefender.DecideNextAction() #Action.walk(0.01, 0, 0) # don't go anywhere return True return False # Wide players hFWHead.DecideNextAction() sFindBall.walkToBall(Global.ballD, Global.ballH) return True
def DecideNextAction(): Global.myLastRole = Constant.DEFENDER Global.myRole = Constant.DEFENDER Indicator.setDefault() hFWHead.resetEachFrame() perform() #findBallDefender() hFWHead.DecideNextAction()
def DecideNextAction(): import sFindBall import hFWHead Indicator.setDefault() hFWHead.resetEachFrame() if Global.lostBall < 30: hFWHead.DecideNextAction() if perform(): Indicator.showFacePattern([5,3,3,3,5]) else: sFindBall.perform()
def receiveKickOffCharge(): global playCounter if playCounter > 85: return False # The close player stays if pReady.isClose(Global.kickOffPos): if playCounter > 65: return False rDefender.perform() return True # Others charge hFWHead.DecideNextAction() sFindBall.walkToBall(Global.ballD, Global.ballH) return True
def DecideNextAction(): import hFWHead import hWhere import Indicator targetX, targetY = hWhere.getSupporterPos() targetH = Global.selfLoc.getHeading() + Global.ballH r = perform(Global.ballX,Global.ballY,\ Constant.TARGET_GOAL_X,Constant.TARGET_GOAL_Y,\ targetH) if r == Constant.STATE_EXECUTING: Indicator.showHeadColor([True, True, True]) else: Indicator.showHeadColor([False, False, False]) hTrack.saGoToTargetFacingHeading(targetX, targetY, targetH) hFWHead.DecideNextAction()
def kickOffUPenn(): global playCounter, whenGrabbed if pReady.chosenFormation == 0: kickLeft = False else: kickLeft = True if pReady.isCentre(Global.kickOffPos): if playCounter > 150: return False if whenGrabbed == 0: print "grabbing" if sGrab.perform() == Constant.STATE_FAILED: return False if sGrab.isGrabbed: whenGrabbed = playCounter return True print "Grabbed!" if sUpennKick.perform(kickLeft) == Constant.STATE_SUCCESS: sGrab.resetPerform() return False sFindBall.perform(True) return True elif pReady.isForward(Global.kickOffPos): if playCounter > 40: return False hTrack.saGoToTarget(Constant.TARGET_GOAL_X, Constant.TARGET_GOAL_Y) hFWHead.DecideNextAction() else: return False return True
def kickOffShootGoal(): global playCounter, whenGrabbed if pReady.isCentre(Global.kickOffPos): if playCounter > 150: sGrab.resetPerform() return False if whenGrabbed == 0: #print "grabbing" sGrab.perform() if sGrab.isGrabbed: #print "grabbed" whenGrabbed = playCounter return True if playCounter < whenGrabbed + 40: #print "walking" sGrabDribble(0, Action.MAX_LEFT, 0) return True # not aiming to visual goal if sGrabTurnKick.perform(False) == Constant.STATE_SUCCESS: #print "aiming" sGrab.resetPerform() return False elif pReady.isForward(Global.kickOffPos): if playCounter > 40: return False hTrack.saGoToTarget(Constant.TARGET_GOAL_X, Constant.TARGET_GOAL_Y) else: return False hFWHead.DecideNextAction() return True
def useBallDistanceSetKickOffPosition(): global inStartPos, isFacingTargetGoal #print "Global.ballD", Global.ballD if Global.lostBall <= 15 and Global.kickOffState != None and \ Global.kickOffState == Constant.DECIDEPOSITION_B and inStartPos and \ isFacingTargetGoal and \ -Constant.CIRCLE_DIAMETER/2 < Global.ballX - Constant.FIELD_WIDTH/2.0 < Constant.CIRCLE_DIAMETER/2 and \ -Constant.CIRCLE_DIAMETER/2 < Global.ballY - Constant.FIELD_LENGTH/2.0 < Constant.CIRCLE_DIAMETER/2 \ : if Global.haveBall < 3: pass if Global.ballD <= Constant.CIRCLE_DIAMETER / 2 + 5: Action.walk(-7, 0, 0, minorWalkType=Action.SkeFastForwardMWT) elif Global.ballD >= Constant.CIRCLE_DIAMETER / 2 + 20: Action.walk(9, 0, 0, minorWalkType=Action.SkeFastForwardMWT) elif Global.ballH > 8: Action.walk(0, 0, Global.ballH, minorWalkType=Action.SkeFastForwardMWT) elif Global.ballH < -8: Action.walk(0, 0, Global.ballH, minorWalkType=Action.SkeFastForwardMWT) else: #don't move if the ball within the range pass #hTrack.trackVisualBall() #hFWHead.minPosVariance = hFWHead.minHeadVariance = 0 hFWHead.compulsoryAction = None hFWHead.DecideNextAction() #sFindBall.perform(True) return True else: return False
def perform(params=None): global gGetOutOfTheBallCounter global gGetOutOfTheAttackerCounter global gGetOutOfTheCircleCounter global gMateLoc global gTargetPointReqAccuracy id(params) # ignore resetEachFrame() # Back of if stuck if hStuck.amIStuckForward(): hFWHead.DecideNextAction() return hFWHead.DecideNextAction() # If the attacker has grabbed, get out of the way # if hTeam.hasTeammateGrabbedBall(): # if getOutOfEveryonesWay(): # return # --------------------------------------------------------------- # Check if I need to get out of the way for the attacker first. targetH = hMath.normalizeAngle_0_360(Global.selfLoc.getHeading() + Global.ballH) if gGetOutOfTheBallCounter > 0: r = sGetOutOfTheWay.perform(Global.ballX,Global.ballY,\ Constant.TARGET_GOAL_X,Constant.TARGET_GOAL_Y,\ targetH,True) if r == Constant.STATE_EXECUTING: gGetOutOfTheBallCounter -= 1 Indicator.showFacePattern([0, 0, 2, 0, 0]) return gGetOutOfTheBallCounter = 0 if gGetOutOfTheAttackerCounter > 0: r = sGetOutOfTheWay.perform(Global.ballX,Global.ballY,\ gMateLoc.getX(),gMateLoc.getY(),\ targetH,True) if r == Constant.STATE_EXECUTING: gGetOutOfTheAttackerCounter -= 1 Indicator.showFacePattern([0, 0, 2, 0, 0]) return gGetOutOfTheAttackerCounter = 0 if gGetOutOfTheCircleCounter > 0: r = sGetOutOfTheWay.getOutOfTheCircle(Global.ballX, Global.ballY, targetH, True) if r == Constant.STATE_EXECUTING: gGetOutOfTheCircleCounter -= 1 Indicator.showFacePattern([0, 2, 0, 2, 0]) return gGetOutOfTheCircleCounter = 0 for i in Global.otherValidForwards: mate = Global.teamPlayers[i] if mate.isAttacker()\ and mate.getTimeToReachBall() < 3000: r = sGetOutOfTheWay.perform(Global.ballX,Global.ballY,\ Constant.TARGET_GOAL_X,Constant.TARGET_GOAL_Y,\ targetH) if r == Constant.STATE_EXECUTING: gGetOutOfTheBallCounter = GET_OUT_DURATION Indicator.showFacePattern([0, 0, 2, 0, 0]) return mateLoc = Global.teammatesLoc[i] gMateLoc = mateLoc.getCopy() r = sGetOutOfTheWay.perform(Global.ballX,Global.ballY,\ mateLoc.getX(),mateLoc.getY(),\ targetH) if r == Constant.STATE_EXECUTING: gGetOutOfTheAttackerCounter = GET_OUT_DURATION Indicator.showFacePattern([0, 0, 2, 0, 0]) return r = sGetOutOfTheWay.getOutOfTheCircle(Global.ballX, Global.ballY, targetH) if r == Constant.STATE_EXECUTING: gGetOutOfTheCircleCounter = GET_OUT_DURATION Indicator.showFacePattern([0, 2, 0, 2, 0]) return # --------------------------------------------------------------- # trigger BOP if i was doing it. if sBirdOfPrey.isBirdOfPreyTriggering(): # FIXME: Winger currently not in use so birding not updated if sBirdOfPrey.perform(Global.ballX, Global.ballY) == Constant.STATE_EXECUTING: return # trigger BOP when I am certain distance behind from the ball DEFENCE_OFFSET = 10.0 DEFENCE_ANGLE = 150.0 if sBirdOfPrey.areWeAboveTheLine(DEFENCE_OFFSET,DEFENCE_ANGLE,True, \ Global.ballX, Global.ballY): sBirdOfPrey.perform(Global.ballX, Global.ballY) return # If I have lost the ball for a while, then find the ball. if (Global.ballSource == Constant.GPS_BALL and Global.lostBall > 210)\ or (Global.ballSource == Constant.WIRELESS_BALL and Global.lostBall > 240): Indicator.showFacePattern([5, 0, 0, 0, 5]) sFindBall.perform() return doGetToTargetPoint()
def DecideNextAction(): import hFWHead if sGrab.perform() == Constant.STATE_SUCCESS: hFWHead.DecideNextAction() perform(90)
def perform(params=None): VisionLink.startProfile("rAttacker.py") global gLastFrameCalled global gLastDecisionFunction global isGoal id(params) # ignore shouldIBeDodgy = gUseDodgyDog if gLastFrameCalled != Global.frame - 1: resetPerform() gLastFrameCalled = Global.frame ### Variable lighting challenge ### if Global.lightingChallenge and playMode: if Global.vBall.isVisible(): isGoal = False for pressSensor in range(1, 4, 1): # Used to react to back sensors if VisionLink.getPressSensorCount(pressSensor) > 8: print "It's a goal!!" isGoal = True if isGoal: VisionLink.resetBall(Constant.FIELD_WIDTH / 2.0, Constant.FIELD_LENGTH / 2.0, 0.0, 0.0) pos = Global.selfLoc.getPos() if (hMath.getDistanceBetween(pos[0], pos[1], Constant.FIELD_WIDTH / 2.0, Constant.FIELD_LENGTH / 2.0) < 50): sFindBall.perform() else: hTrack.stationaryLocalise() hTrack.saGoToTarget(Constant.FIELD_WIDTH / 2.0, Constant.FIELD_LENGTH / 2.0) return else: pass # perform normal attacker elif Global.lightingChallenge: ObsMapping() return ### End variable lighting challenge ### ### Penalty Shooter #### if Global.penaltyShot: if Global.frame - Global.firstPlayFrame < 90: hTrack.stationaryLocalise() return elif Global.frame - Global.firstPlayFrame < 115: sFindBall.perform(True) return #print "rAttacker frame", # Last man attacker can block # if not hTeam.amIFurthestBack(ignoreRoles = []): # print "not furthest back" # elif sGrab.grabbingCount > 0: # print "grabbing count", sGrab.grabbingCount # elif sGrab.isGrabbed: # print "grabbed" # elif Global.frame - sGrabDribble.gLastActionFrame < 60: # print "grabdribbleaction", sGrabDribble.gLastActionFrame ## if hTeam.amIFurthestBack(ignoreRoles = []) \ ## and not sGrab.grabbingCount > 0 \ ## and not sGrab.isGrabbed \ ## and hMath.getTimeElapsed(sGrab.gLastGrabTime, VisionLink.getCurrentTime()) > 7000 \ ## and not Global.penaltyShot \ ## and Global.frame - sGrabDribble.gLastActionFrame > 60 \ ## and Global.selfLoc.getHeading() < 180 \ ## and Global.selfLoc.getY() < Constant.FIELD_LENGTH * 0.7: ## #print __name__, "candidate block" ## #_, _, speed, dirDegrees, _, _ = VisionLink.getGPSBallVInfo(Constant.CTLocal) ## #print "speed", speed ## # This speed really needs to be 4.5 to remove all noise but then it ## # nearly never blocks. I'm under pressure to keep it possible in the ## # face of all the other checks above, hence 4 ## if sBlock.checkThenBlock(onlyVisualBall = True, minBallSpeed = 3, ## minDist = 40, maxDist = 80, ## bothSides = False, dontBlockCentre = True): ## print __name__, hMath.getTimeElapsed(sGrab.gLastGrabTime, ## VisionLink.getCurrentTime()) ## print __name__, Global.frame, "blocking, gLastActionFrame =", sGrabDribble.gLastActionFrame ## print ## return # Back off if stuck if hStuck.amIStuckForward()\ and Global.ballD > 200\ and Global.gpsLocalBall.getDistance() > 200\ and not sGrab.isGrabbed\ and sGrab.grabbingCount == 0\ and Global.frame - sGrab.gLastApproachFrame >= 5\ and (not Global.penaltyShot)\ and (not Global.lightingChallenge): sFindBall.perform(True) return # Don't go into own goal box if hWhere.ballInOwnGoalBox(0)\ and (not sGrab.isGrabbed)\ and sGrab.grabbingCount == 0\ and (not Global.penaltyShot)\ and (not Global.lightingChallenge): #print "Ball in goal box" #print "avoiding" doAvoidGoalBox() hFWHead.DecideNextAction() return # no dodgy if not shouldIEndActivelyLocalise()\ or shouldIActivelyLocalise(): #print "localising" doActivelyLocalise() elif shouldIKick(): #shouldIBeDodgy = False #Really? #print "kicking" doKick() elif Global.lightingChallenge and shouldIGoToCenter(): doGotoCenter() else: #print "tracking" doTrackBall() # Use dodgy dog if required fwdCmd = Action.finalValues[Action.Forward] shouldIBeDodgy = shouldIBeDodgy \ and (not sGrab.isGrabbed) \ and sGrab.grabbingCount == 0 \ and Global.frame - sGrab.gLastApproachFrame >= 5 \ and Global.ballD >= sGrab.CLOSE_DIST \ and Global.frame - sFindBall.gLastSpinFrame >= 15 \ and Global.frame - sGetBehindBall.gLastCalledFrame >= 5 \ and fwdCmd > Action.MAX_SKE_FWD_SPD/2 \ and fwdCmd > abs(Action.finalValues[Action.Left]) \ and sDodgyDog.shouldIBeDodgyToBall() if shouldIBeDodgy: #print "and dodging" sDodgyDog.dodgyDogToBall() VisionLink.stopProfile("rAttacker.py")
def DecideNextAction(): pForward.DecideNextAction() if Global.myRole == Constant.ATTACKER: if Global.ballD < 45 or (Global.lostBall > 0 and Global.ballD < 70): Action.stopLegs() hFWHead.DecideNextAction()
def kickOffPushToSupporter(): global playCounter, whenGrabbed global bestHeading, gBestHeading (myX, myY) = Global.selfLoc.getPos() myH = Global.selfLoc.getHeading() if pReady.chosenFormation == 0: (suppX, suppY) = (PUSH_TO_X + 40, PUSH_TO_Y - 40) else: (suppX, suppY) = (PUSH_TO_X - 40, PUSH_TO_Y - 40) if pReady.isCentre(Global.kickOffPos): if playCounter > 180: # 6 sec, just in case return False if whenGrabbed == 0: #print "grabbing" if sGrab.grabbingCount == 0: # Find the obstacle gap just before we drop the head to grab #(gapLeft, gapRight, bestHeading, angle) = \ # VisionLink.getBestGap(lKickX, lKickY, # GAP_MAX_DIST,GAP_MIN_DIST, # GAP_MIN,GAP_MIN_INTENSITY, # Constant.OBS_USE_SHARED) gap = getGapTo(PUSH_TO_X, PUSH_TO_Y) if gap != None: (gapLeft, gapRight, bestHeading, angle) = gap else: bestHeading = hMath.getHeadingToAbsolute( Global.selfLoc, PUSH_TO_X, PUSH_TO_Y) gBestHeading = hMath.local2GlobalHeading( Global.selfLoc, bestHeading) print "gap ", bestHeading, gBestHeading if sGrab.perform() == Constant.STATE_FAILED: return False if sGrab.isGrabbed: #print "grabbed, best gap at local", bestHeading, \ # "global", gBestHeading whenGrabbed = playCounter return True # Don't prevent other forward from being attacker Global.myRole = Global.myLastRole = Constant.SUPPORTER relH = gBestHeading - Global.selfLoc.getHeading() if playCounter - whenGrabbed < 40: if sGrabDribble.perform(Action.MAX_FORWARD, 0, relH) \ == Constant.STATE_FAILED: return False return True Action.kick(Action.GTChestPushWT) if Action.shouldIContinueKick(): Action.continueKick() return True sGrab.resetPerform() return False elif pReady.isForward(Global.kickOffPos): if playCounter < 80: sDodgyDog.dodgyDogTo(suppX, suppY) hTrack.stationaryLocalise(6, 30, -30) return True elif playCounter < 120: if hTrack.canSeeBall and Global.ballD < 30: Global.myRole = Global.myLastRole = Constant.ATTACKER return False h = hMath.normalizeAngle_0_360(myH + Global.ballH) hTrack.saGoToTargetFacingHeading(suppX, suppY, h) hFWHead.DecideNextAction() return True else: Global.myRole = Global.myLastRole = Constant.ATTACKER return False else: return False return False
def DecideNextAction(): perform() Action.stopLegs() import hFWHead hFWHead.DecideNextAction()
def kickOffKickToCorner(): global playCounter, whenGrabbed global bestHeading, gBestHeading # Warning: this set play freezes the attacker when it fails. # Don't use it yet (myX, myY) = Global.selfLoc.getPos() myH = Global.selfLoc.getHeading() if pReady.chosenFormation == 0: (kickX, kickY) = (Constant.FIELD_WIDTH, Constant.FIELD_LENGTH - 80) (suppX, suppY) = (kickX + 40, kickY - 40) else: (kickX, kickY) = (0, Constant.FIELD_LENGTH - 80) (suppX, suppY) = (kickX - 40, kickY - 40) if pReady.isCentre(Global.kickOffPos): print "kickToCorner: whenGrabbed", whenGrabbed, if playCounter > 120: # 6 sec, just in case return False if whenGrabbed == 0: if sGrab.grabbingCount == 0: # Find the obstacle gap just before we drop the head to grab #(gapLeft, gapRight, bestHeading, angle) = \ # VisionLink.getBestGap(lKickX, lKickY, # GAP_MAX_DIST,GAP_MIN_DIST, # GAP_MIN,GAP_MIN_INTENSITY, # Constant.OBS_USE_SHARED) gap = getGapTo(kickX, kickY) if gap != None: (gapLeft, gapRight, bestHeading, angle) = gap bestHeading += hMath.getSign(5, bestHeading) else: bestHeading = hMath.getHeadingToAbsolute( Global.selfLoc, kickX, kickY) gBestHeading = hMath.local2GlobalHeading( Global.selfLoc, bestHeading) print "gap", bestHeading, gBestHeading, print "grabbing" if sGrab.perform() == Constant.STATE_FAILED: print "Grab failed in set play. Done." sGrab.resetPerform() Global.myRole = Global.myLastRole = Constant.ATTACKER return False if sGrab.isGrabbed: print "grabbed, best gap at local", bestHeading, \ "global", gBestHeading whenGrabbed = playCounter return True # Don't prevent other forward from being attacker Global.myRole = Global.myLastRole = Constant.SUPPORTER # Keep updating gap, but not with shared obs gap = getGapTo(kickX, kickY) if gap != None: (gapLeft, gapRight, bestHeading, angle) = gap bestHeading += hMath.getSign(5, bestHeading) gBestHeading = hMath.local2GlobalHeading(Global.selfLoc, bestHeading) print "New gap global", gBestHeading, else: print "No gap left - using last global", gBestHeading, #bestHeading = 0 # Kick now relH = gBestHeading - Global.selfLoc.getHeading() print "relH", relH, if abs(relH) >= 4 and (playCounter - whenGrabbed) < 55: print "dribbling" if sGrabDribble.perform(0, 0, relH) == Constant.STATE_FAILED: print "dribble failed. Done." Global.myRole = Global.myLastRole = Constant.ATTACKER return False return True print "Kicking", Action.kick(Action.SoftTapWT) if Action.shouldIContinueKick(): Action.continueKick() return True sGrab.resetPerform() print "success. Done." return False elif pReady.isForward(Global.kickOffPos): Global.myRole = Global.myLastRole = Constant.ATTACKER if playCounter < 60: hTrack.saGoToTarget(suppX, suppY, 25) hFWHead.DecideNextAction() return True elif playCounter < 100: if hTrack.canSeeBall and Global.ballD < 30: return False h = hMath.normalizeAngle_0_360(myH + Global.ballH) hTrack.saGoToTargetFacingHeading(suppX, suppY, h) hFWHead.DecideNextAction() return True else: rAttacker.perform() return False else: return False return False
def kickOffKickToGap(): global playCounter, whenGrabbed global bestHeading, gBestHeading (myX, myY) = Global.selfLoc.getPos() myH = Global.selfLoc.getHeading() if pReady.chosenFormation == 0: print "chosenFormation =", pReady.chosenFormation, "- going right" (kickX, kickY) = (Constant.MAX_GOALBOX_EDGE_X, Constant.TOP_GOALBOX_EDGE_Y) (suppX, suppY) = (kickX + 40, kickY - 40) (lKickX, lKickY) = hMath.getLocalCoordinate(myX, myY, myH, kickX, kickY) else: print "chosenFormation =", pReady.chosenFormation, "- going left" (kickX, kickY) = (Constant.MIN_GOALBOX_EDGE_X, Constant.TOP_GOALBOX_EDGE_Y) (suppX, suppY) = (kickX - 40, kickY - 40) (lKickX, lKickY) = hMath.getLocalCoordinate(myX, myY, myH, kickX, kickY) if pReady.isCentre(Global.kickOffPos): if playCounter > 120: # 6 sec, just in case return False if whenGrabbed == 0: #print "grabbing" if sGrab.grabbingCount == 0: # Find the obstacle gap just before we drop the head to grab (gapLeft, gapRight, bestHeading, angle) = \ VisionLink.getBestGap(lKickX, lKickY, GAP_MAX_DIST,GAP_MIN_DIST, GAP_MIN,GAP_MIN_INTENSITY, Constant.OBS_USE_SHARED) gBestHeading = hMath.local2GlobalHeading( Global.selfLoc, bestHeading) #gBestHeading = hMath.getHeadingBetween(Constant.FIELD_WIDTH/2, Constant.FIELD_LENGTH/2, kickX, kickY) print "local target", lKickX, lKickY print "gap", bestHeading, gBestHeading if sGrab.perform() == Constant.STATE_FAILED: return False if sGrab.isGrabbed: print "grabbed, best gap at local", bestHeading, \ "global", gBestHeading whenGrabbed = playCounter return True # Don't prevent other forward from being attacker Global.myRole = Global.myLastRole = Constant.SUPPORTER relH = gBestHeading - Global.selfLoc.getHeading() if abs(relH) >= 3: if sGrabDribble.perform(0, 0, relH) == Constant.STATE_FAILED: return False return True Action.kick(Action.SoftTapWT) if Action.shouldIContinueKick(): Action.continueKick() return True sGrab.resetPerform() return False elif pReady.isForward(Global.kickOffPos): if playCounter < 80: sDodgyDog.dodgyDogTo(suppX, suppY) hTrack.stationaryLocalise(6, 30, -30) return True elif playCounter < 120: if hTrack.canSeeBall and Global.ballD < 30: Global.myRole = Global.myLastRole = Constant.ATTACKER return False h = hMath.normalizeAngle_0_360(myH + Global.ballH) hTrack.saGoToTargetFacingHeading(suppX, suppY, h) hFWHead.DecideNextAction() return True else: Global.myRole = Global.myLastRole = Constant.ATTACKER return False else: return False return False
def perform(params = None): global gTargetPointReqAccuracy global gBirdToBall#, gBirdPos id(params) # ignore resetEachFrame() # Back off if stuck if hStuck.amIStuckForward() and not hWhere.selfInOwnGoalBox(15): hFWHead.DecideNextAction() return targetX, targetY = hWhere.getDefenderPos() selfX, selfY = Global.selfLoc.getPos() hFWHead.DecideNextAction() # If the attacker has grabbed, get out of the way if hTeam.hasTeammateGrabbedBall(): if getOutOfEveryonesWay(): return # Continue BOP if already doing one if sBirdOfPrey.isBirdOfPreyTriggering(): if sBirdOfPrey.birdTo == sBirdOfPrey.BIRD_TO_BALL: birdPos = (Global.ballX, Global.ballY) else: # BIRD_TO_POS birdPos = (targetX, targetY) # If there are no robots between (x) us and the ball defender can use # a tighter curve birdAngle = 40 for i in Global.otherValidForwards: if Global.teammatesLoc[i].getY() > Global.ballY \ and Global.ballX < Global.teammatesLoc[i].getX() \ < Global.selfLoc.getX(): birdAngle = 45 elif Global.teammatesLoc[i].getY() > Global.ballY \ and Global.selfLoc.getX() < Global.teammatesLoc[i].getX() \ < Global.ballX: birdAngle = 45 if sBirdOfPrey.perform(birdPos[0], birdPos[1], birdAngle)\ == Constant.STATE_EXECUTING: # Can we do better than this (supporter too)? Need to see obstacles hFWHead.minPosVar = 1 # localise more often hFWHead.DecideNextAction() return # Make sure we're not obstructing teammates. This is less important than # the bird, but hopefully DodgyDog in the bird will keep us clear. if getOutOfEveryonesWay(): return # Bird back to position if I am way in front and not close to ball if targetY < selfY - BIRD_TO_POS_THRESH and Global.ballD > 70: sBirdOfPrey.birdTo = sBirdOfPrey.BIRD_TO_POS if sBirdOfPrey.perform(targetX, targetY) == Constant.STATE_EXECUTING: return # trigger BOP when I am certain distance in front of the ball, but not if # defender position is in front of the ball anyway #DEFENCE_OFFSET = 10.0 #DEFENCE_ANGLE = 150.0 #if targetY < Global.ballY < selfY and \ # sBirdOfPrey.areWeAboveTheLine(DEFENCE_OFFSET, DEFENCE_ANGLE, \ # True, Global.ballX, Global.ballY): # sBirdOfPrey.birdTo = sBirdOfPrey.BIRD_TO_BALL # if sBirdOfPrey.perform(Global.ballX, Global.ballY) == Constant.STATE_EXECUTING: # return sBirdOfPrey.birdTo = None # If I have lost the ball for a while, then find the ball. if Global.ballSource == Constant.GPS_BALL and Global.lostBall > 150: Indicator.showFacePattern([5,0,0,0,5]) findBallDefender() return doGetToTargetPoint(targetX, targetY) # Check if I need to back off, because of obstacle in front of me. """