def perform(self, comms): goal = self.world.our_goal robots = filter(lambda r: not r.is_missing(), self.world.their_robots) robots.sort(key=lambda r: math.hypot(r.x - goal.x, r.y - goal.y)) if len(robots) == 0: logging.error("There is no enemy here. Gimme someone to destroy!") return 1 robot = robots[0] cone_upper = math.atan2(goal.x - robot.x, goal.higher_post - robot.y) % (2 * pi) cone_lower = math.atan2(goal.x - robot.x, goal.lower_post - robot.y) % (2 * pi) if robot.angle < min(cone_upper, cone_lower) or robot.angle > max(cone_upper, cone_lower): critical_angle = (cone_upper + cone_lower) / 2 else: critical_angle = robot.angle target_rotation = (critical_angle - self.robot.angle + pi / 2) % pi - pi / 2 if (critical_angle - self.robot.angle + pi / 2) % pi - pi / 2 <= 0.6: target_rotation = 0 dist = utils.defender_get_alignment_offset(self.robot, robot, critical_angle, target_rotation) logging.info("Aligning with enemy. (Rotate %f degrees, move %f right)", math.degrees(target_rotation), dist) if abs(dist) > MOVEMENT_THRESHOLD and abs(target_rotation) > ROTATION_THRESHOLD: comms.turn_then_move(target_rotation, dist) return utils.defender_turn_delay(target_rotation) + utils.defender_move_delay(dist) elif abs(dist) > MOVEMENT_THRESHOLD: comms.move(dist) return utils.defender_move_delay(dist) elif abs(target_rotation) > ROTATION_THRESHOLD: comms.turn(target_rotation) return utils.defender_turn_delay(target_rotation)
def perform(self, comms): # get robot 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] # Find our goal goal = Vector(0, 225, 0, 0) if self.robot.x > 300: goal = Vector(600, 225, 0, 0) # get the point robots = self.world.their_robots y_diff = goal.y - robot.y x_diff = goal.x - robot.x ratio = (self.world.our_defender.x - robot.x) / x_diff y_mean = robot.y + (y_diff * ratio) distance = utils.defender_distance_on_y(self.world.our_defender.vector, y_mean) print("DISTANCE: " + str(distance)) logging.info("Wants to move by: " + str(distance)) comms.move(distance) return utils.defender_move_delay(distance)
def perform(self, comms): distance_to_move = utils.defender_follow_ball_distance( self.robot.vector, self.world.ball.vector) logging.info("Wants to follow ball by: " + str(distance_to_move)) comms.move(distance_to_move) return utils.defender_move_delay(distance_to_move)
def perform(self, comms): target_rotation = (self.world.ball.angle - self.robot.angle + pi / 2) % pi - pi / 2 dist = utils.defender_get_alignment_offset(self.robot, self.world.ball, self.world.ball.angle, target_rotation) logging.info("Aligning with ball. (Rotate %f degrees, move %f right)", math.degrees(target_rotation), dist) if abs(dist) > MOVEMENT_THRESHOLD: comms.turn_then_move(target_rotation, dist) return utils.defender_turn_delay(target_rotation) + utils.defender_move_delay(dist) else: comms.turn(target_rotation) return utils.defender_turn_delay(target_rotation)
def perform(self, comms): angle, side, defend_point = utils.defender_rotation_to_defend_point(self.robot.vector, self.world.ball.vector, self.world.our_goal.vector, GOAL_RADIUS, self.world.our_side) dx = defend_point.x - self.robot.x dy = defend_point.y - self.robot.y wiggeled_distance_to_move = math.hypot(dx, dy) + WIGGLE_EFFECT if side == "left": wiggeled_distance_to_move = -wiggeled_distance_to_move logging.info("Wants to wiggle by: " + str(wiggeled_distance_to_move)) comms.move(wiggeled_distance_to_move) return utils.defender_move_delay(wiggeled_distance_to_move)
def perform(self, comms): robots = self.world.their_robots y_diff = robots[1].y - robots[0].y x_diff = robots[1].x - robots[0].x ratio = (self.world.our_defender.x - robots[0].x) / x_diff y_mean = robots[0].y + (y_diff * ratio) distance = utils.defender_distance_on_y(self.world.our_defender.vector, y_mean) print("DISTANCE: " + str(distance)) logging.info("Wants to move by: " + str(distance)) comms.move(distance) return utils.defender_move_delay(distance)
def perform(self, comms): angle, side, defend_point = utils.defender_rotation_to_defend_point( self.robot.vector, self.world.ball.vector, self.world.our_goal.vector, GOAL_RADIUS, self.world.our_side) dx = defend_point.x - self.robot.x dy = defend_point.y - self.robot.y wiggeled_distance_to_move = math.hypot(dx, dy) + WIGGLE_EFFECT if side == "left": wiggeled_distance_to_move = -wiggeled_distance_to_move logging.info("Wants to wiggle by: " + str(wiggeled_distance_to_move)) comms.move(wiggeled_distance_to_move) return utils.defender_move_delay(wiggeled_distance_to_move)
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): # 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): distance_to_move = utils.defender_follow_ball_distance(self.robot.vector, self.world.ball.vector) logging.info("Wants to follow ball by: " + str(distance_to_move)) comms.move(distance_to_move) return utils.defender_move_delay(distance_to_move)
def perform(self, comms): dist = utils.defender_get_alignment_offset(self.robot, self.world.ball, self.world.ball.angle) logging.info("Aligning with ball. (Move %f right)", dist) if abs(dist) > MOVEMENT_THRESHOLD: comms.move(dist) return utils.defender_move_delay(dist)
def perform(self, comms): dist = utils.dist(self.robot, utils.get_defence_point(self.world)) dist *= utils.get_movement_direction_from_vector(self.robot, utils.get_defence_point(self.world)) logging.info("Moving to defence area. Moving %f right.", dist) comms.move(dist) return utils.defender_move_delay(abs(dist))