Пример #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 receivePass():
    """Face our ally and get ready to grab the ball if they kick it to us"""
    me.goal = Goals.receivePass
    angle_to_face = me.bearing(ally)
    # if we're facing the ally, ungrab and get ready to receive the ball
    if nearEnough(angle_to_face, me.currentRotation):
        controller.stop_robot()
        controller.ungrab(True)
    # otherwise, turn to face our ally
    else:
        controller.move(angle_to_face,0,0,False,rotate_in_place=True)
Пример #4
0
 def get_grabbed(self, robot):
     willBounce = random.sample([0, 0, 1, 1, 0, 0, 0], 1)[0]
     if nearEnough(robot.currentPoint, self.currentPoint):
         if willBounce:
             print("oh no, the ball bounced off the robot!")
             self.direction = robot.direction - 15
             self.currentSpeed = 0
             self.acceleration = -0.15
         else:
             self.acceleration = 0
             self.state = BallStatus.me
Пример #5
0
 def get_grabbed(self, robot):
     willBounce = random.sample([0,0,1,1,0,0,0], 1)[0]
     if nearEnough(robot.currentPoint, self.currentPoint):
         if willBounce:
             print("oh no, the ball bounced off the robot!")
             self.direction = robot.direction - 15
             self.currentSpeed = 0
             self.acceleration = -0.15
         else:
             self.acceleration = 0
             self.state = BallStatus.me
Пример #6
0
def receivePass():
    """Face our ally and get ready to grab the ball if they kick it to us"""
    me.goal = Goals.receivePass
    angle_to_face = me.bearing(ally)
    # if we're facing the ally, ungrab and get ready to receive the ball
    if nearEnough(angle_to_face, me.currentRotation):
        controller.stop_robot()
        controller.ungrab(True)
    # otherwise, turn to face our ally
    else:
        controller.move(angle_to_face, 0, 0, False, rotate_in_place=True)
Пример #7
0
def passBall():
    """Kick the ball full power towards our ally"""
    me.goal = Goals.passBall
    angle_to_face = me.bearing(ally)
    # if we're facing the ally, pass them the ball
    if nearEnough(angle_to_face, me.currentRotation):
        controller.stop_robot()
        if not controller.haveIkicked:
            controller.kick(255)
    # otherwise, turn to face our ally
    else:
        controller.move(angle_to_face,0,0,False,rotate_in_place=True)
Пример #8
0
def passBall():
    """Kick the ball full power towards our ally"""
    me.goal = Goals.passBall
    angle_to_face = me.bearing(ally)
    # if we're facing the ally, pass them the ball
    if nearEnough(angle_to_face, me.currentRotation):
        controller.stop_robot()
        if not controller.haveIkicked:
            controller.kick(255)
    # otherwise, turn to face our ally
    else:
        controller.move(angle_to_face, 0, 0, False, rotate_in_place=True)
Пример #9
0
def shoot():
    """Kick the ball full power towards the goal"""
    me.goal = Goals.shoot
    angle_to_face = me.bearing(opponentGoal)
    # if we're facing the goal, shoot!
    if nearEnough(angle_to_face, me.currentRotation):
        controller.stop_robot()
        print controller.haveIkicked
        if not controller.haveIkicked:
            controller.kick(255)
    # otherwise, turn to face the goal
    else:
        controller.move(angle_to_face,0,0,False,rotate_in_place=True)
Пример #10
0
def confuseEnemy():
    """Shoogle around a bit to confuse the enemy and hopefully make them move"""
    global confusionTarget
    # if just started this new goal, choose an amount to shoogle
    if me.goal!=Goals.confuse:
        confusionTarget = me.currentRotation + random.uniform(-90,90)
        me.goal = Goals.confuse
    # if we've reached our confusion target, we're done for now
    if nearEnough(confusionTarget, me.currentRotation):
        clearPlan()
    # otherwise, shoogle!
    else:
        controller.move(confusionTarget,0,0,False,rotate_in_place=True)
Пример #11
0
def shoot():
    """Kick the ball full power towards the goal"""
    me.goal = Goals.shoot
    angle_to_face = me.bearing(opponentGoal)
    # if we're facing the goal, shoot!
    if nearEnough(angle_to_face, me.currentRotation):
        controller.stop_robot()
        print controller.haveIkicked
        if not controller.haveIkicked:
            controller.kick(255)
    # otherwise, turn to face the goal
    else:
        controller.move(angle_to_face, 0, 0, False, rotate_in_place=True)
Пример #12
0
def confuseEnemy():
    """Shoogle around a bit to confuse the enemy and hopefully make them move"""
    global confusionTarget
    # if just started this new goal, choose an amount to shoogle
    if me.goal != Goals.confuse:
        confusionTarget = me.currentRotation + random.uniform(-90, 90)
        me.goal = Goals.confuse
    # if we've reached our confusion target, we're done for now
    if nearEnough(confusionTarget, me.currentRotation):
        clearPlan()
    # otherwise, shoogle!
    else:
        controller.move(confusionTarget, 0, 0, False, rotate_in_place=True)
Пример #13
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)
Пример #14
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)
Пример #15
0
def updatePositions():
    """Updates the system's belief of the state of the game based on the vision system"""
    # get the info on the robots from the vision system
    if api.getMyPosition() is not None:
        mePosition = api.getMyPosition()
        me.update(Point(mePosition[0]*X_RATIO,mePosition[1]*Y_RATIO))
    else:
        print "Can't find my position this tick :("
    if api.getMyOrientation() is not None:
        meOrientation = api.getMyOrientation()[1]
        me.updateRotation(meOrientation)
    else:
        print "Can't find my orientation this tick :("

    if api.getAllyPosition() is not None:
        allyPosition = api.getAllyPosition()
        ally.update(Point(allyPosition[0]*X_RATIO,allyPosition[1]*Y_RATIO))
    else:
        print "Can't find my friend's position this tick :("
    if api.getAllyOrientation() is not None:
        allyOrientation = api.getAllyOrientation()[1]
        ally.updateRotation(allyOrientation)
    else:
        print "Can't find my friend's orientation this tick :("

    if api.getEnemyPositions()[0] is not None:
        enemy0Position = api.getEnemyPositions()[0]
        enemies[0].update(Point(enemy0Position[0]*X_RATIO,enemy0Position[1]*Y_RATIO))
    else:
        print "Can't find enemy 0 this tick :("
    if api.getEnemyOrientation()[0] is not None:
        enemy0Orientation =  api.getEnemyOrientation()[0][1]
        enemies[0].updateRotation(enemy0Orientation)
    else:
        print "Can't find enemy 0's orientation this tick :("

    if api.getEnemyPositions()[1] is not None:
        enemy1Position = api.getEnemyPositions()[1]
        enemies[1].update(Point(enemy1Position[0]*X_RATIO,enemy1Position[1]*Y_RATIO))
    else:
        print "Can't find enemy 1 this tick :("
    if api.getEnemyOrientation()[1] is not None:
        enemy1Orientation = api.getEnemyOrientation()[1][1]
        enemies[1].updateRotation(enemy1Orientation)
    else:
        print "Can't find enemy 1's orientation this tick :("

    if api.getBallCenter() is not None:
        ballPosition =  api.getBallCenter()
        ball.update(Point(ballPosition[0]*X_RATIO,ballPosition[1]*Y_RATIO))
    else:
        print "Shit! Where's the ball gone"

    try:#see who has ball posesion - needs work
        if nearEnough(enemies[0].bearing(ball),enemies[0].currentRotation, near_enough_angle=45) and ball.distance(enemies[0]) < BALL_OWNERSHIP_DISTANCE:
            ball.status = BallStatus.enemyA
        elif nearEnough(enemies[1].bearing(ball),enemies[1].currentRotation, near_enough_angle=45) and  ball.distance(enemies[1]) < BALL_OWNERSHIP_DISTANCE:
            ball.status = BallStatus.enemyB
        elif nearEnough(ally.bearing(ball),ally.currentRotation, near_enough_angle=45) and  ball.distance(ally)< BALL_OWNERSHIP_DISTANCE:
            ball.status = BallStatus.ally
        elif nearEnough(me.bearing(ball), me.currentRotation, near_enough_angle=45) and ball.distance(me)< BALL_OWNERSHIP_DISTANCE and me.grabbed:
            ball.status = BallStatus.me
        # if we can't see it, assume it's the same
        elif api.world['ball_center']==None:
            pass
        # if it's far enough from everything, it's free
        else:
            ball.status = BallStatus.free
    except (TypeError, AttributeError):
        print("Location of some objects unknown")