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 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 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 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 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 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 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