def perform(self, comms):
        x = self.world.ball.x
        y = self.world.ball.y
        angle = utils.get_rotation_to_point(self.robot.vector, Vector(x, y, 0, 0))
        logging.info("Wants to rotate by: " + str(angle))
        comms.turn(angle)

        return utils.defender_turn_delay(angle)
Example #2
0
    def perform(self, comms):
        x = self.world.ball.x
        y = self.world.ball.y
        angle = utils.get_rotation_to_point(self.robot.vector, Vector(x, y, 0, 0))
        logging.info("Wants to rotate by: " + str(angle))
        comms.turn(angle)

        return utils.defender_turn_delay(angle)
Example #3
0
 def perform(self, comms):
     # takes take opponent's robot that is closer to ours
     robots = filter(lambda r: not r.is_missing(), self.world.their_robots)
     robots.sort(key=lambda r: math.hypot(r.x - self.robot.x, r.y - self.robot.y))
     if len(robots) == 0:
         logging.error("There is no enemy here. Gimme someone to destroy!")
         return 1
     robot = robots[0]
     angle = utils.get_rotation_to_point(self.robot.vector, robot.vector)
     logging.info("Facing opponent: Rotating %f" % angle)
     comms.turn(angle)
Example #4
0
 def perform(self, comms):
     turn_angle = (self.world.ball.angle - self.robot.angle) % (2 * pi) - pi
     dist = math.hypot(self.robot.x - self.world.ball.x, self.robot.y - self.world.ball.y)
     tri_angle = utils.get_rotation_to_point(self.world.ball.vector, self.robot)
     dist *= math.cos(tri_angle)
     if abs(turn_angle) < ROTATION_BALL_THRESHOLD:
         logging.info("Adjusting to ball position by distance: " + str(dist))
         comms.move(dist)
     else:
         logging.info("Adjusting angle by %f, distance by %f." % (turn_angle, dist))
         comms.turn_then_move(turn_angle, dist)
     return 2
Example #5
0
class FaceBall(Action):
    preconditions = [
        (lambda w, r: abs(utils.get_rotation_to_point(r.vector, w.ball.vector))
         > ROTATION_DEFEND_BALL_THRESHOLD, "Defender is not facing ball"),
        (lambda w, r: r.catcher == 'OPEN', "Grabbers are open.")
    ]

    def perform(self, comms):
        angle = utils.get_rotation_to_point(self.robot.vector,
                                            self.world.ball.vector)
        logging.info("Facing ball: Rotating %f" % angle)
        comms.turn(angle)
        return utils.defender_turn_delay(angle)
Example #6
0
class WaitForBallToCome(Action):
    '''
    Defender just waits for the ball to approach it
    '''

    # FIXME: ball_can_reach_robot doesn't do anything.
    # FIXME: robot_can_reach_ball doesn't do anything.
    preconditions = [(lambda w, r: abs(utils.get_rotation_to_point(r.vector, w.ball.vector)) < ROTATION_BALL_THRESHOLD, "Defender is facing ball"),
                     (lambda w, r: utils.ball_can_reach_robot(w.ball, r), "The ball can reach the robot"),
                     (lambda w, r: utils.robot_can_reach_ball(w.ball, r), "Defender can reach the ball"),
                     (lambda w, r: r.catcher == 'OPEN', "Grabbers are open."),
                     (lambda w, r: not utils.ball_is_static(w), "The ball is moving.")]

    def perform(self, comms):
        pass
Example #7
0
    def perform(self, comms):
        # reset dynamic threshold
        # TODO: has to be restarted everywhere!
        global ROTATION_THRESHOLD
        ROTATION_THRESHOLD = 0.1

        dx = self.world.ball.x - self.robot.x
        dy = self.world.ball.y - self.robot.y
        displacement = math.hypot(dx, dy)

        if displacement == 0:
            alpha = 0
        else:
            # TODO: has to handle this edge case better
            try:
                alpha = math.degrees(
                    math.asin(self.robot.catch_distance / float(displacement)))
            except ValueError as er:
                print(er)
                x = self.world.ball.x
                y = self.world.ball.y
                angle = utils.get_rotation_to_point(self.robot.vector,
                                                    Vector(x, y, 0, 0))
                logging.info("Wants to close-rotate by: " + str(angle))
                comms.turn(angle)
                return 1  # TODO: NO FIXED DELAY
        beta = 90 - alpha

        if math.sin(math.radians(alpha)) == 0:
            distance_to_move = 15  # something is obviously wrong so we have to move a bit
        else:
            distance_to_move = math.sin(
                math.radians(beta)) * self.robot.catch_distance / math.sin(
                    math.radians(alpha))

        # Find the movement side
        angle, side = utils.defender_get_rotation_to_catch_point(
            Vector(self.robot.x, self.robot.y, self.robot.angle, 0),
            Vector(self.world.ball.x, self.world.ball.y, 0, 0),
            self.robot.catch_distance)
        if side == "left":
            distance_to_move = -distance_to_move

        logging.info("Wants to move by: " + str(distance_to_move))
        comms.move(distance_to_move)

        return utils.defender_move_delay(distance_to_move)
Example #8
0
    def __init__(self, world, robot):
        if robot.catched_ball:
            print("222222222")
            self.actions = [Kick(world, robot, [
                                (lambda w, r: abs(utils.get_rotation_to_point(r.vector, w.our_attacker)) < ROTATION_BALL_THRESHOLD, "Defender is facing attacker.")]),
                            FaceFriendly(world, robot, [])]

        else:
            print("111111111")
            self.actions = [FaceFriendly(world, robot, [
                            (lambda w, r: r.has_ball(w.ball), "Our robot has the ball")]),
                            GrabBall(world, robot),
                            GoToStaticBall(world, robot, [
                                (opponent_doesnt_have_ball, "The house robot has the ball")]),
                            TurnToCatchPoint(world, robot, [
                                (opponent_doesnt_have_ball, "The house robot has the ball")]),
                            OpenGrabbers(world, robot),
                            FaceOpponent(world, robot)]
    def perform(self, comms):
        # reset dynamic threshold
        # TODO: has to be restarted everywhere!
        global ROTATION_THRESHOLD
        ROTATION_THRESHOLD = 0.1

        dx = self.world.ball.x - self.robot.x
        dy = self.world.ball.y - self.robot.y
        displacement = math.hypot(dx, dy)

        if displacement == 0:
            alpha = 0
        else:
            # TODO: has to handle this edge case better
            try:
                alpha = math.degrees(math.asin(self.robot.catch_distance / float(displacement)))
            except ValueError as er:
                print(er)
                x = self.world.ball.x
                y = self.world.ball.y
                angle = utils.get_rotation_to_point(self.robot.vector, Vector(x, y, 0, 0))
                logging.info("Wants to close-rotate by: " + str(angle))
                comms.turn(angle)
                return 1  # TODO: NO FIXED DELAY
        beta = 90 - alpha

        if math.sin(math.radians(alpha)) == 0:
            distance_to_move = 15  # something is obviously wrong so we have to move a bit
        else:
            distance_to_move = math.sin(math.radians(beta)) * self.robot.catch_distance / math.sin(math.radians(alpha))

        # Find the movement side
        angle, side = utils.defender_get_rotation_to_catch_point(Vector(self.robot.x, self.robot.y, self.robot.angle, 0), Vector(self.world.ball.x, self.world.ball.y, 0, 0), self.robot.catch_distance)
        if side == "left":
            distance_to_move = -distance_to_move

        logging.info("Wants to move by: " + str(distance_to_move))
        comms.move(distance_to_move)

        return utils.defender_move_delay(distance_to_move)
 def perform(self, comms):
     angle = utils.get_rotation_to_point(self.robot.vector, self.world.ball.vector)
     logging.info("Facing ball: Rotating %f" % angle)
     comms.turn(angle)
     return utils.defender_turn_delay(angle)
Example #11
0
 def perform(self, comms):
     self.robot._catched_ball = True
     angle = utils.get_rotation_to_point(self.robot.vector, self.world.our_attacker.vector)
     logging.info("Facing friendly: Rotating %f" % angle)
     comms.turn(angle)
Example #12
0
 def perform(self, comms):
     angle = utils.get_rotation_to_point(self.robot.vector, self.world.ball.vector)
     logging.info("Facing ball: Rotating %f" % angle)
     comms.turn(angle)