예제 #1
0
def guardGoal():
    """Go to the goal line and face the enemy with the ball"""
    me.goal = Goals.guardGoal
    angle_to_face = me.bearing(ball)

    # if not on our goal line, move into the middle of it
    if abs(me.currentPoint.x - ourGoal.x) > 15:
        angle_to_move = me.bearing(ourGoal)
        distance = me.distance(ourGoal)
        controller.move(angle_to_move,angle_to_move,distance)
    # if we're on our goal line, move to block the ball
    else:
        # work out which enemy has the ball
        if ball.status == BallStatus.enemyA:
            enemyNum=0
        elif ball.status == BallStatus.enemyB:
            enemyNum=1
        else:
            print("just guarding lol")
            controller.move(angle_to_face,0,0,False,rotate_in_place=True)
            return

        # calculate where on the y axis the ball would hit if kicked now
        x_dist = enemies[enemyNum].currentPoint.x  - ourGoal.x
        y_dist = x_dist * tan(enemies[enemyNum].currentRotation)
        y_intersection = enemies[enemyNum].currentPoint.y + y_dist

        # calculate where we should therefore go to (we don't want to leave the goal line)
        minY = PITCH_WIDTH/2 - 0.5*GOAL_WIDTH + ROBOT_WIDTH/2
        maxY = PITCH_WIDTH/2 + 0.5*GOAL_WIDTH - ROBOT_WIDTH/2
        point_to_be = Point(ourGoal.x, max(minY, min(maxY, y_intersection)))

        # if we're not where we should be, move there holonomically
        if not nearEnough(point_to_be, me.currentPoint, near_enough_point=10):
            # turn to face the opposite side of the pitch before the holo movement
            if OUR_GOAL=='left':
                angle_to_face=0
            else:
                angle_to_face=180
            # calculate the parameters to send to the robot
            distance = me.distance(point_to_be)
            # we want to move holonomically up and down
            if point_to_be.y<me.currentPoint.y:
                angle_to_move = 90
            else:
                angle_to_move = -90
            controller.move(angle_to_face,angle_to_move,distance)

        # if we're in position already but just facing wrongly, turn to face the robot with the ball
        elif not nearEnough(angle_to_face, me.currentRotation):
            controller.move(angle_to_face,0,0,False,rotate_in_place=True)
        # if we're all set, just wait for something to happen
        else:
            controller.stop_robot()
예제 #2
0
def guardGoal():
    """Go to the goal line and face the enemy with the ball"""
    me.goal = Goals.guardGoal
    angle_to_face = me.bearing(ball)

    # if not on our goal line, move into the middle of it
    if abs(me.currentPoint.x - ourGoal.x) > 15:
        angle_to_move = me.bearing(ourGoal)
        distance = me.distance(ourGoal)
        controller.move(angle_to_move, angle_to_move, distance)
    # if we're on our goal line, move to block the ball
    else:
        # work out which enemy has the ball
        if ball.status == BallStatus.enemyA:
            enemyNum = 0
        elif ball.status == BallStatus.enemyB:
            enemyNum = 1
        else:
            print("just guarding lol")
            controller.move(angle_to_face, 0, 0, False, rotate_in_place=True)
            return

        # calculate where on the y axis the ball would hit if kicked now
        x_dist = enemies[enemyNum].currentPoint.x - ourGoal.x
        y_dist = x_dist * tan(enemies[enemyNum].currentRotation)
        y_intersection = enemies[enemyNum].currentPoint.y + y_dist

        # calculate where we should therefore go to (we don't want to leave the goal line)
        minY = PITCH_WIDTH / 2 - 0.5 * GOAL_WIDTH + ROBOT_WIDTH / 2
        maxY = PITCH_WIDTH / 2 + 0.5 * GOAL_WIDTH - ROBOT_WIDTH / 2
        point_to_be = Point(ourGoal.x, max(minY, min(maxY, y_intersection)))

        # if we're not where we should be, move there holonomically
        if not nearEnough(point_to_be, me.currentPoint, near_enough_point=10):
            # turn to face the opposite side of the pitch before the holo movement
            if OUR_GOAL == 'left':
                angle_to_face = 0
            else:
                angle_to_face = 180
            # calculate the parameters to send to the robot
            distance = me.distance(point_to_be)
            # we want to move holonomically up and down
            if point_to_be.y < me.currentPoint.y:
                angle_to_move = 90
            else:
                angle_to_move = -90
            controller.move(angle_to_face, angle_to_move, distance)

        # if we're in position already but just facing wrongly, turn to face the robot with the ball
        elif not nearEnough(angle_to_face, me.currentRotation):
            controller.move(angle_to_face, 0, 0, False, rotate_in_place=True)
        # if we're all set, just wait for something to happen
        else:
            controller.stop_robot()
예제 #3
0
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()
예제 #4
0
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)
예제 #5
0
def collectBall():
    """Move towards then grab the ball"""
    me.goal=Goals.collectBall
    
    # if we've caught up to the ball, stop and grab
    if nearEnough(me.bearing(ball), me.currentRotation, near_enough_angle=30) and ball.distance(me)< BALL_OWNERSHIP_DISTANCE:
        controller.stop_robot()
        controller.grab(True)
    # otherwise, go to the ball
    else:
        me.goal = Goals.collectBall
        angle_to_face = me.bearing(ball)
        angle_to_move = angle_to_face
        distance_to_move = me.distance(ball)
        if lineOfSight(me.currentPoint,ball.currentPoint):
            print "Real"
            controller.move(angle_to_face,angle_to_move,distance_to_move,True)
        else:
            ghost_walk(angle_to_face)
예제 #6
0
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)
예제 #7
0
def collectBall():
    """Move towards then grab the ball"""
    me.goal = Goals.collectBall

    # if we've caught up to the ball, stop and grab
    if nearEnough(me.bearing(ball), me.currentRotation, near_enough_angle=30
                  ) and ball.distance(me) < BALL_OWNERSHIP_DISTANCE:
        controller.stop_robot()
        controller.grab(True)
    # otherwise, go to the ball
    else:
        me.goal = Goals.collectBall
        angle_to_face = me.bearing(ball)
        angle_to_move = angle_to_face
        distance_to_move = me.distance(ball)
        if lineOfSight(me.currentPoint, ball.currentPoint):
            print "Real"
            controller.move(angle_to_face, angle_to_move, distance_to_move,
                            True)
        else:
            ghost_walk(angle_to_face)