def blockPass(): """Move to inbetween the two enemies""" me.goal = Goals.blockPass # work out where to move to e0 = enemies[0].currentPoint e1 = enemies[1].currentPoint x = (e0.x + e1.x)/2 y = (e0.y + e1.y)/2 point_to_be = Point(x, y) # work out the parameters for the move command angle_to_face = point_to_be.bearing(ball.currentPoint) angle_to_move = me.bearing(point_to_be) distance = me.distance(point_to_be) if not isEnemyBox(point_to_be): controller.move(angle_to_move,angle_to_move,distance) else: ghost_walk(angle_to_face)
def blockPass(): """Move to inbetween the two enemies""" me.goal = Goals.blockPass # work out where to move to e0 = enemies[0].currentPoint e1 = enemies[1].currentPoint x = (e0.x + e1.x) / 2 y = (e0.y + e1.y) / 2 point_to_be = Point(x, y) # work out the parameters for the move command angle_to_face = point_to_be.bearing(ball.currentPoint) angle_to_move = me.bearing(point_to_be) distance = me.distance(point_to_be) if not isEnemyBox(point_to_be): controller.move(angle_to_move, angle_to_move, distance) else: ghost_walk(angle_to_face)
def ghost_walk(angle_to_face): ghost_flag = False for i in range(0, 10): ghost_pt_x = random.random() * 30 * random.choice([1, -1]) ghost_pt_y = random.random() * 30 * random.choice([1, -1]) target = me.currentPoint.x + ghost_pt_y, me.currentPoint.y + ghost_pt_y if target[0] > 0 and target[0] < PITCH_LENGTH and target[ 1] > 0 and target[1] < PITCH_WIDTH and not isEnemyBox( Point(target[0], target[1])) and lineOfSight( me.currentPoint, Point(target[0], target[1])): ghost_flag = True break if ghost_flag: angle_to_move = me.bearing(Point(target[0], target[1])) print "Ghost" controller.move(angle_to_face, angle_to_move, 60, None, None) else: print "None" controller.stop_robot()
def playBall(): # if we are closest to ball heldByMe = ball.status == BallStatus.me heldByAlly = ball.status == BallStatus.ally heldByEnemyA = ball.status == BallStatus.enemyA heldByEnemyB = ball.status == BallStatus.enemyB ballFree = ball.status == BallStatus.free # If the enemy has the ball if heldByEnemyA or heldByEnemyB: # if I'm closer to our goal than the ally, go defend it if me.distance(ourGoal) < ally.distance(ourGoal): guardGoal() # otherwise, intercept the pass else: blockPass() # if we have the ball elif heldByMe: # shoot if possible if lineOfSight(me.currentPoint, opponentGoal): shoot() # else, try and pass to ally elif lineOfSight(me.currentPoint, ally.currentPoint): passBall() else: confuseEnemy() # if our ally has the ball, set up a pass elif ball.status == BallStatus.ally: receivePass() # if noone has the ball, go grab the ball or defend elif me.distance(ball) < ally.distance(ball) and not isEnemyBox( ball.currentPoint): collectBall() else: guardGoal()
def ghost_walk(angle_to_face): ghost_flag = False for i in range(0, 10): ghost_pt_x = random.random() * 30 * random.choice([1, -1]) ghost_pt_y = random.random() * 30 * random.choice([1, -1]) target = me.currentPoint.x + ghost_pt_y, me.currentPoint.y + ghost_pt_y if target[0] > 0 and target[0] < PITCH_LENGTH and target[1] > 0 and target[1] < PITCH_WIDTH and not isEnemyBox(Point(target[0],target[1])) and lineOfSight(me.currentPoint, Point(target[0],target[1])): ghost_flag = True break; if ghost_flag: angle_to_move = me.bearing(Point(target[0],target[1])) print "Ghost" controller.move(angle_to_face, angle_to_move, 60, None, None) else: print "None" controller.stop_robot()