本文整理汇总了Python中RoleConstants类的典型用法代码示例。如果您正苦于以下问题:Python RoleConstants类的具体用法?Python RoleConstants怎么用?Python RoleConstants使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RoleConstants类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: switchRoles
def switchRoles(player):
"""
State to decide who on the team should become the new chaser and switch accordingly.
"""
roleConstants.setRoleConstants(player, player.openChaser)
return player.goLater(player.gameState)
示例2: checkForConsistency
def checkForConsistency(player):
"""
Checks to see if anyone else has the same role as us. If they also have
a lower playerNumber then we change. Otherwise we assume that they will
fix the issue. Very similar in structure to determineRole in penalty states.
"""
if not player.roleSwitching:
return
openSpaces = [True, True, True, True]
conflict = False
position = 0
for mate in player.brain.teamMembers:
if mate.playerNumber == player.brain.playerNumber:
continue
openSpaces[mate.role - 2] = False
if mate.role == player.role and mate.playerNumber > player.brain.playerNumber and mate.frameSinceActive < 30:
conflict = True
if not conflict:
return # The expected outcome
for i in range(3):
if openSpaces[i] and constants.canRoleSwitchTo(i + 2):
constants.setRoleConstants(player, i + 2)
return
elif openSpaces[i]:
position = i + 2
if position == 0:
print "We have conflicting role AND there are no more open roles..."
constants.setRoleConstants(player, position)
return
示例3: switchRoles
def switchRoles(player):
"""
State to decide who on the team should become the new chaser and switch accordingly.
"""
# US Open Hack
if player.brain.game:
oppTeam = player.brain.game.team(1).team_number
else:
oppTeam = -1
roleConstants.setRoleConstants(player, player.openChaser, oppTeam)
return player.goLater(player.gameState)
示例4: commMonitor
def commMonitor(player):
if player.commMode == -1:
pass
elif player.commMode != 2 and transitions.awfulComm(player):
print "Switched to awful comm mode!"
player.role = player.brain.playerNumber
player.prevRoleConfig = RoleConstants.roleConfiguration
RoleConstants.roleConfiguration = RoleConstants.spread
RoleConstants.oddDefenderBox = RoleConstants.defenderBox
RoleConstants.evenDefenderBox = RoleConstants.defenderBox
RoleConstants.setRoleConstants(player, player.role)
player.roleSwitching = False
player.commMode = 2
示例5: getSupporterPosition
def getSupporterPosition(player, role):
"""
Returns a position to stand at to support teammate who is chasing the ball.
Used in positionAsSupporter in PlayOffBallStates.
"""
if RoleConstants.isLeftDefender(role):
return leftDefender(player)
elif RoleConstants.isRightDefender(role):
return rightDefender(player)
elif RoleConstants.isChaser(role):
return chaser(player)
else: # cherry picker
return cherryPicker(player)
示例6: chaser
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
示例7: positionAtHome
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)
示例8: watchForBall
def watchForBall(player):
"""
The player is at home, waiting for the ball to be within box.
"""
if player.firstFrame():
# print "-----------Player at home - Watching for ball-----------"
player.brain.tracker.trackBall()
player.brain.nav.stand()
# I commented this out because we were getting strange oscillations
# between this and positonAtHome, and honestly we never go here unless
# we are already at home... dumb...
# if transitions.tooFarFromHome(player, 50, 20):
# return player.goLater('positionAtHome')
if role.isFirstChaser(player.role):
if player.stateTime >= tracking.INITIALIZE_HEADING_TIME + tracking.FULL_WIDE_PAN_TIME:
return player.goNow('spinAtHome')
elif role.isStriker(player.role):
if player.stateTime >= tracking.INITIALIZE_HEADING_TIME + tracking.FULL_WIDE_PAN_TIME * 2:
return player.goNow('spinAtHome')
else:
if player.stateTime >= tracking.INITIALIZE_HEADING_TIME + tracking.FULL_WIDE_PAN_TIME * 2:
return player.goNow('spinAtHome')
示例9: tooFarFromHome
def tooFarFromHome(threshold, player):
"""
Returns true if LOC thinks we're more than *distance* away from our home
position
"""
if player.brain.ball.vis.frames_off < 10:
ball = player.brain.ball
elif player.brain.sharedBall.ball_on:
ball = player.brain.sharedBall
else:
ball = None
home = player.homePosition
if ball != None:
if role.isLeftDefender(player.role):
home = findDefenderHome(True, ball, player.homePosition.h)
elif role.isRightDefender(player.role):
home = findDefenderHome(False, ball, player.homePosition.h)
elif role.isStriker(player.role):
home = findStrikerHome(ball, player.homePosition.h)
else:
home = player.homePosition
distance = ((player.brain.loc.x - home.x) ** 2 + (player.brain.loc.y - home.y) ** 2) ** 0.5
return distance > threshold
示例10: calculateHomePosition
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
示例11: branchOnRole
def branchOnRole(player):
"""
Chasers are going to have a different behavior again.
We will branch on behavior based on role here
"""
# print "----------In branch on role----------"
# print "Entered Branch on Role"
# print "----- evenDefenderIsForward, lastEvenDefenderForwardVal ----"
# print player.brain.evenDefenderIsForward, lastEvenDefenderForwardVal
# global lastEvenDefenderForwardVal
# player.brain.evenDefenderIsForward = not lastEvenDefenderForwardVal
# newEvenDefenderForwardVal = True
# print("TIME SINCE PLAYING:", player.brain.gameController.timeSincePlaying)
if role.isFirstChaser(player.role):
if transitions.shouldFindSharedBall(player) and player.brain.gameController.timeSincePlaying > 75:
return player.goNow('searchFieldForSharedBall')
return player.goNow('playerFourSearchBehavior')
elif role.isStriker(player.role):
return player.goNow('playerFiveSearchBehavior')
elif role.isLeftDefender(player.role):
# print "Player Brain Left Forward 1: " + str(leftDefenderIsForward)
# if (player.brain.sharedBall.ball_on) and (player.brain.sharedBall.x < NogginConstants.MIDFIELD_X):
# print "WE ARE IN HERE"
# return player.goNow('leftDefenderBack')
if leftDefenderIsForward:
# print "Changing to False"
global leftDefenderIsForward
leftDefenderIsForward = False
# print "Player Brain Left Forward 2: " + str(leftDefenderIsForward)
return player.goNow('leftDefenderForward')
else:
# print "Changing to True"
global leftDefenderIsForward
leftDefenderIsForward = True
# print "Player Brain Left Forward 3: " + str(leftDefenderIsForward)
return player.goNow('leftDefenderBack')
else:
return player.goNow('positionAtHome')
示例12: positionAsSupporter
def positionAsSupporter(player):
if (role.isChaser(player.role) and role.isChaser(player.roleOfClaimer) and
player.brain.ball.distance > hypot(CHASER_DISTANCE, CHASER_DISTANCE)):
fast = True
else:
fast = False
positionAsSupporter.position = getSupporterPosition(player, player.role)
# TODO don't call goTo every frame
player.brain.nav.goTo(positionAsSupporter.position, precision = nav.GENERAL_AREA,
speed = nav.QUICK_SPEED, avoidObstacles = True,
fast = False, pb = False)
示例13: positionAsSupporter
def positionAsSupporter(player):
if (role.isChaser(player.role) and role.isChaser(player.roleOfClaimer) and
player.brain.ball.distance > hypot(CHASER_DISTANCE, CHASER_DISTANCE)):
fast = True
else:
fast = False
positionAsSupporter.position = getSupporterPosition(player, player.role)
if player.firstFrame():
player.brain.nav.goTo(positionAsSupporter.position, precision = nav.GENERAL_AREA,
speed = nav.QUICK_SPEED, avoidObstacles = True,
fast = False, pb = False)
player.brain.nav.updateDest(positionAsSupporter.position, fast=fast)
示例14: positionAtHome
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)
示例15: doPan
def doPan(player):
"""
Wide pan for 5 seconds.
"""
if player.firstFrame():
# print "------------Doing Pan-------------"
player.stand()
player.brain.tracker.trackBall()
if player.stateTime >= tracking.INITIALIZE_HEADING_TIME + tracking.FULL_WIDE_PAN_TIME:
if role.isFirstChaser(player.role):
return player.goNow('playerFourSearchBehavior')
elif role.isStriker(player.role):
return player.goNow('playerFiveSearchBehavior')
else:
return player.goNow('doSecondHalfSpin')