def get_goal(self, world, robot): ''' Selects a goal for robot ''' if robot.penalty: return None elif self.current_task == 'game' and world.game_state is not None: utils.defender_rotation_to_defend_point(robot, world.ball, world.our_goal.vector, defender.GOAL_RADIUS, world.our_side) if robot.has_ball(world.ball): info("Defender goal choice: Pass the ball") return defender.Pass(world, robot) elif utils.dist(world.our_goal, world.ball) < defender.GOAL_RADIUS: return None elif not utils.ball_heading_to_our_goal(world) and utils.defender_should_grab_ball(world): info("Defender goal choice: Retrieve the ball") return defender.GetBall(world, robot) else: info("Defender goal choice: Do the wiggle dance!") return defender.Defend(world, robot) elif self.current_task == 'oldgame' and world.game_state is not None: if robot.has_ball(world.ball): info("Defender goal choice: kick the ball") return defender.Pass(world, robot) elif utils.ball_heading_to_our_goal(world) and world.in_our_half(world.ball): info("Defender goal choice: Intercept") return defender.ReactiveGrabGoal(world, robot) elif utils.ball_is_static(world) and world.in_our_half(world.ball): ourdist = math.hypot(world.ball.x - robot.x, world.ball.y - robot.y) oppdists = [math.hypot(world.ball.x - r.x, world.ball.y - r.y) for r in world.their_robots if not r.is_missing()] if (len(oppdists) == 0 or ourdist < min(oppdists)) and world.game_state == 'normal-play': info("Defender goal choice: Retrieve ball") return defender.GetBall(world, robot) else: info("Defender goal choice: Block") return defender.Block(world, robot) else: info("Defender goal choice: Return to defence area") return defender.ReturnToDefenceArea(world, robot) elif self.current_task == 'move-grab': return defender.GetBall(world, robot) elif self.current_task == 'defend': return defender.Defend(world, robot) elif self.current_task == 'reactive-grab': return defender.ReactiveGrabGoal(world, robot) elif self.current_task == 'm1': return defender.ReceivingPass(world, robot) elif self.current_task == 'm2': return defender.ReceiveAndPass(world, robot) elif self.current_task == 'm31': return defender.InterceptPass(world, robot) elif self.current_task == 'm32': return defender.InterceptGoal(world, robot)
class GoToDefendPoint(Action): preconditions = [ (lambda w, r: abs( utils.defender_rotation_to_defend_point( r.vector, w.ball.vector, w.our_goal.vector, GOAL_RADIUS, w. our_side)[0]) < ROTATION_DEFEND_POINT_THRESHOLD, "Defender is facing defending point"), (lambda w, r: abs( utils.defender_distance_to_defend_point( r.vector, w.ball.vector, w.our_goal.vector, GOAL_RADIUS, w. our_side)) > DEFEND_POINT_DISTANCE_THRESHOLD, "Defender far away from defending point"), (lambda w, r: r.catcher == 'OPEN', "Grabbers are open.") ] 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 distance_to_move = math.hypot(dx, dy) 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, 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) logging.info("Facing defend point: Rotating %f degrees to %f %f" % (math.degrees(angle), defend_point.x, defend_point.y)) comms.turn(angle) return utils.defender_turn_delay(angle)
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, 100) dx = defend_point.x - self.robot.x dy = defend_point.y - self.robot.y distance_to_move = math.hypot(dx, dy) if side == "left": distance_to_move = -distance_to_move logging.info("Wants to move by: " + str(distance_to_move)) comms.move(distance_to_move)
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): 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)
class GoToDefendPoint(Action): preconditions = [(lambda w, r: abs(utils.defender_rotation_to_defend_point(r.vector, w.ball.vector, w.our_goal.vector, 100)[0]) < ROTATION_DEFEND_POINT_THRESHOLD, "Defender is facing defending point"), ] 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, 100) dx = defend_point.x - self.robot.x dy = defend_point.y - self.robot.y distance_to_move = math.hypot(dx, dy) if side == "left": distance_to_move = -distance_to_move logging.info("Wants to move by: " + str(distance_to_move)) comms.move(distance_to_move)
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) logging.info("Facing defend point: Rotating %f degrees to %f %f" % (math.degrees(angle), defend_point.x, defend_point.y)) comms.turn(angle) return utils.defender_turn_delay(angle)