def setFieldConstantsFromField_Dimensions(value): Field.Length = value.Length() Field.Width = value.Width() Field.Border = value.Border() Field.LineWidth = value.LineWidth() Field.GoalWidth = value.GoalWidth() Field.GoalDepth = value.GoalDepth() Field.GoalHeight = value.GoalHeight() Field.PenaltyDist = value.PenaltyDist() Field.PenaltyDiam = value.PenaltyDiam() Field.ArcRadius = value.ArcRadius() Field.CenterRadius = value.CenterRadius() Field.CenterDiameter = value.CenterDiameter() Field.GoalFlat = value.GoalFlat() Field.FloorLength = value.FloorLength() Field.FloorWidth = value.FloorWidth() Field.OurGoalZoneShape = robocup.CompositeShape() Field.OurGoalZoneShape.add_shape(robocup.Circle(robocup.Point(-Field.GoalFlat / 2.0, 0), Field.ArcRadius)) Field.OurGoalZoneShape.add_shape(robocup.Circle(robocup.Point(Field.GoalFlat / 2.0, 0), Field.ArcRadius)) Field.OurGoalZoneShape.add_shape(robocup.Rect(robocup.Point(-Field.GoalFlat / 2.0, Field.ArcRadius), robocup.Point(Field.GoalFlat / 2.0, 0))) Field.TheirGoalShape = robocup.CompositeShape() Field.TheirGoalShape.add_shape(robocup.Circle(robocup.Point(-Field.GoalFlat / 2.0, Field.Length), Field.ArcRadius)) Field.TheirGoalShape.add_shape(robocup.Circle(robocup.Point(Field.GoalFlat / 2.0, Field.Length), Field.ArcRadius)) Field.TheirGoalShape.add_shape(robocup.Rect(robocup.Point(-Field.GoalFlat / 2.0, Field.Length), robocup.Point(Field.GoalFlat / 2.0, Field.Length - Field.ArcRadius))) Field.TheirGoalSegment = robocup.Segment(robocup.Point(Field.GoalWidth / 2.0, Field.Length), robocup.Point(-Field.GoalWidth / 2.0, Field.Length)) Field.OurGoalSegment = robocup.Segment(robocup.Point(Field.GoalWidth / 2.0, 0), robocup.Point(-Field.GoalWidth / 2.0, 0)) Field.TheirHalf = robocup.Rect(robocup.Point(-Field.Width/2, Field.Length), robocup.Point(Field.Width/2, Field.Length/2)) Field.OurHalf = robocup.Rect(robocup.Point(-Field.Width/2, 0), robocup.Point(Field.Width/2, Field.Length/2))
def generate_default_rectangle(kick_point): offset_from_edge = 0.25 offset_from_ball = 0.4 # offset_from_ball = 0.7 if kick_point.x > 0: # Ball is on right side of field toReturn = robocup.Rect( robocup.Point( 0, min(constants.Field.Length - offset_from_edge, main.ball().pos.y - offset_from_ball)), robocup.Point( -constants.Field.Width / 2 + offset_from_edge, min(constants.Field.Length * 3 / 4, main.ball().pos.y - 2))) else: # Ball is on left side of field toReturn = robocup.Rect( robocup.Point( 0, min(constants.Field.Length - offset_from_edge, main.ball().pos.y - offset_from_ball)), robocup.Point( constants.Field.Width / 2 - offset_from_edge, min(constants.Field.Length * 3 / 4, main.ball().pos.y - 2))) return toReturn
class Field: Length = 6.05 Width = 4.05 Border = 0.25 LineWidth = 0.01 GoalWidth = 0.700 GoalDepth = 0.180 GoalHeight = 0.160 # Distance of the penalty marker from the goal line PenaltyDist = 0.750 PenaltyDiam = 0.010 # Radius of the goal arcs ArcRadius = 0.8 # diameter of the center circle CenterRadius = 0.5 CenterDiameter = 1.0 # flat area for defense markings GoalFlat = 0.35 FloorLength = Length + 2.0 * Border FloorWidth = Width + 2.0 * Border CenterPoint = robocup.Point(0.0, Length / 2.0) OurGoalZoneShape = robocup.CompositeShape() OurGoalZoneShape.add_shape( robocup.Circle(robocup.Point(-GoalFlat / 2.0, 0), ArcRadius)) OurGoalZoneShape.add_shape( robocup.Circle(robocup.Point(GoalFlat / 2.0, 0), ArcRadius)) OurGoalZoneShape.add_shape( robocup.Rect(robocup.Point(-GoalFlat / 2.0, ArcRadius), robocup.Point(GoalFlat / 2.0, 0))) TheirGoalShape = robocup.CompositeShape() TheirGoalShape.add_shape( robocup.Circle(robocup.Point(-GoalFlat / 2.0, Length), ArcRadius)) TheirGoalShape.add_shape( robocup.Circle(robocup.Point(GoalFlat / 2.0, Length), ArcRadius)) TheirGoalShape.add_shape( robocup.Rect(robocup.Point(-GoalFlat / 2.0, Length), robocup.Point(GoalFlat / 2.0, Length - ArcRadius))) TheirGoalSegment = robocup.Segment(robocup.Point(GoalWidth / 2.0, Length), robocup.Point(-GoalWidth / 2.0, Length)) OurGoalSegment = robocup.Segment(robocup.Point(GoalWidth / 2.0, 0), robocup.Point(-GoalWidth / 2.0, 0)) TheirHalf = robocup.Rect(robocup.Point(-Width / 2, Length), robocup.Point(Width / 2, Length / 2)) OurHalf = robocup.Rect(robocup.Point(-Width / 2, 0), robocup.Point(Width / 2, Length / 2))
def __init__(self, side=Side.center): super().__init__(continuous=True) self._block_robot = None self._area = None self._side = side self._opponent_avoid_threshold = 2.0 self._defend_goal_radius = 0.9 self._win_eval = evaluation.window_evaluator.WindowEvaluator() self._area = robocup.Rect( robocup.Point(-constants.Field.Width / 2.0, constants.Field.Length), robocup.Point(constants.Field.Width / 2.0, 0)) if self._side is Defender.Side.right: self._area.get_pt(0).x = 0 if self._side is Defender.Side.left: self._area.get_pt(1).x = 0 self.add_state(Defender.State.marking, behavior.Behavior.State.running) self.add_state(Defender.State.area_marking, behavior.Behavior.State.running) self.add_transition(behavior.Behavior.State.start, Defender.State.marking, lambda: True, "immediately") self.add_transition( Defender.State.marking, Defender.State.area_marking, lambda: not self._area.contains_point(main.ball().pos) and self. block_robot is None, "if ball not in area and no robot to block") self.add_transition( Defender.State.area_marking, Defender.State.marking, lambda: self._area.contains_point(main.ball( ).pos) or self.find_robot_to_block() is not None, "if ball or opponent enters my area")
def side(self, value): self._side = value self._area = robocup.Rect(robocup.Point(-constants.Field.Width/2.0, constants.Field.Length), robocup.Point(constants.Field.Width/2.0, 0)) if self._side is Defender.Side.right: self._area.get_pt(0).x = 0 if self._side is Defender.Side.left: self._area.get_pt(1).x = 0
def __init__(self): super().__init__(continuous=False) for s in Distraction.State: self.add_state(s, behavior.Behavior.State.running) self.ball_is_far = main.ball().pos.y < (0.4 * constants.Field.Length) #the first Distraction point self.Distraction_point = robocup.Point(0.40 * constants.Field.Width, 0.95 * constants.Field.Length) #the second Distraction point self.Distraction_recieve_pass_point = robocup.Point( 0.40 * constants.Field.Width, 0.8 * constants.Field.Length) #striker's position self.striker_point = robocup.Point(-0.40 * constants.Field.Width, 0.9 * constants.Field.Length) #center of field position, used if ball is far self.center = robocup.Point(0.5 * constants.Field.Width, 0.5 * constants.Field.Length) self.distract_box = robocup.Rect( robocup.Point(0.33 * constants.Field.Width / 2, (7 / 9) * constants.Field.Length), robocup.Point(constants.Field.Width, constants.Field.Length)) self.striker_box = robocup.Rect( robocup.Point(-0.33 * constants.Field.Width / 2, (7 / 9) * constants.Field.Length), robocup.Point(-constants.Field.Width, constants.Field.Length)) self.distracter_get_close_ball = self.distract_box.contains_point( main.ball().pos) self.striker_get_close_ball = self.striker_box.contains_point( main.ball().pos) self.pass_striker_instead = False self.dont_shoot = False #If ball is not far self.add_transition( behavior.Behavior.State.start, Distraction.State.setup, lambda: not self.ball_is_far, 'capture ball') #If the ball is near the distracter position, then skip steps that get it to that position self.add_transition( Distraction.State.setup, Distraction.State.cross, lambda: self.distracter_get_close_ball and self.subbehavior_with_name('capture').is_done_running(), 'distracter get ball') #If the ball is near the strikers position, then skip the steps that get it to that position self.add_transition( Distraction.State.setup, Distraction.State.shoot, lambda: self.striker_get_close_ball and self.subbehavior_with_name('capture').is_done_running(), 'striker get ball') #If the ball is far away, then go from capturing the ball to getting robots set up to recieve a closer pass self.add_transition( behavior.Behavior.State.start, Distraction.State.optional_adjustment, lambda: self.ball_is_far, 'setup close pass') #Capture the ball and pass to a distracting robot if the ball is not far away self.add_transition( Distraction.State.setup, Distraction.State.passing, lambda: self. subbehavior_with_name('capture').is_done_running(), 'pass') #If the chance to pass and score with the striker is higher than passing to the Distraction recieve pass position self.add_transition( Distraction.State.setup, Distraction.State.cross, lambda: self.distracter_get_close_ball and self.subbehavior_with_name('capture').is_done_running(), 'cross') #Go from setting up a close pass to making the pass towards the center of the field self.add_transition( Distraction.State.optional_adjustment, Distraction.State.center_pass, lambda: self.subbehavior_with_name( 'move half').is_done_running() and self.subbehavior_with_name( 'capture 2').is_done_running(), 'closer pass') #After getting the ball to the center right of the field, pass to the distracting robot self.add_transition( Distraction.State.center_pass, Distraction.State.passing, lambda: self.subbehavior_with_name( 'center pass').is_done_running(), 'pass upfield') #Have the distracrting robot capture the ball and go to passing to the striker self.add_transition( Distraction.State.passing, Distraction.State.cross, lambda: (self.has_subbehavior_with_name('distract pass') and self. subbehavior_with_name('distract pass').is_done_running( )) or (self.has_subbehavior_with_name('get close ball') and self. subbehavior_with_name('get close ball').is_done_running()), 'have the distracrting robot capture the ball and go to passing to the striker' ) #The striker gets the ball, either through pass or capturing, and goes to shoot self.add_transition( Distraction.State.passing, Distraction.State.shoot, lambda: ( self.has_subbehavior_with_name('striker pass') and self. subbehavior_with_name('striker pass').is_done_running()) or (self.has_subbehavior_with_name('striker get close ball') and self. subbehavior_with_name('striker get close ball').is_done_running( )) or (self.has_subbehavior_with_name('get close ball') and self. subbehavior_with_name('get close ball').is_done_running()), 'stiker get ball') #go from the striker receiving the cross to shooting the ball self.add_transition( Distraction.State.cross, Distraction.State.shoot, lambda: self.subbehavior_with_name( 'pass to striker').is_done_running(), 'cross shoot') #Don't shoot if shoot chance is too low, and pass back to distracter self.add_transition(Distraction.State.shoot, Distraction.State.passing, lambda: self.dont_shoot, 'striker passes ') self.add_transition( Distraction.State.shoot, Distraction.State.setup, lambda: self. subbehavior_with_name('shooting').is_done_running(), 'repeat')