<commit_before>import composite_behavior
import behavior
import constants
import robocup
import main
import enum
import math
import skills.move

# This tactic builds a wall a certain distance from point A, blocking point B.
class Wall(composite_behavior.CompositeBehavior):
    class State(enum.Enum):
        defense_wall = 1

    def __init__(self,
                 num_defenders = 3,                         # number of defenders we're making the wall with (default 3)
                 curvature = 0,                             # curvature (in radians) of the wall 0 - pi/2
                 mark_point = None,                         # what point we are defending against (default is ball)
                 defender_point = robocup.Point(0, 0),      # what point we are defending (default is goal)
                 defender_spacing = 3,                      # number of robot radii between the centers of the defenders in the wall
                 dist_from_mark = .5):                       # distance from the mark point we want to build the wall
        super().__init__(continuous=True)

        self.number_of_defenders = num_defenders
        self.curvature = curvature
        self._mark_point = main.ball().pos if mark_point == None else mark_point
        self._defense_point = defender_point
        self.dist_from_mark = dist_from_mark
        self.defender_spacing = defender_spacing

        self.add_state(Wall.State.defense_wall, 
                       behavior.Behavior.State.running)

        self.add_transition(behavior.Behavior.State.start,
                            Wall.State.defense_wall, lambda: True,
                            "immediately")

        self.add_transition(
            Wall.State.defense_wall,
            behavior.Behavior.State.completed, lambda: self.completed(), "robot kicked")

    def on_enter_defense_wall(self):
        self.remove_all_subbehaviors()
        midpoint = self.mark_point + (self.defense_point - self.mark_point).normalized() * self.dist_from_mark
        angle = (midpoint - self.defense_point).angle()
        for i in range(self.number_of_defenders):
            pt = None
            if self.number_of_defenders % 2 != 0:
                pt = self.point_on_arc(midpoint, angle, i - int(self.number_of_defenders / 2))
            else:
                pt = self.point_on_arc(midpoint, angle, i - int(self.number_of_defenders / 2) + .5)
            self.add_subbehavior(
                skills.move.Move(pt),
                name="robot" + str(i),
                required=False,
                priority=self.number_of_defenders - i)

    def completed(self):
        for bhvr in self.all_subbehaviors():
             if not bhvr.is_done_running():
                return False
        self.remove_all_subbehaviors()
        return True

    # Finds the point on the wall (arc) at which the defender robot should move to
    def point_on_arc(self, midpoint, angle, defender_number):
        x_perp = robocup.Point(1, 0)
        x_perp.rotate(self.defense_point, angle + defender_number * self.curvature + math.pi/2)
        return midpoint + x_perp * constants.Robot.Radius * self.defender_spacing * defender_number

    @property
    def defense_point(self):
        return self._defense_point

    @property
    def mark_point(self):
        return self._mark_point

    @defense_point.setter
    def defense_point(self, point):
        self.remove_all_subbehaviors()
        self._defense_point = point
        self.on_enter_defense_wall()

    @mark_point.setter
    def mark_point(self, point):
        self.remove_all_subbehaviors()
        self._mark_point = point
        self.on_enter_defense_wall()<commit_msg>fixed setters and getters, still have problem with non-goal defense point<commit_after>import composite_behavior
import behavior
import constants
import robocup
import main
import enum
import math
import skills.move

# This tactic builds a wall a certain distance from point A, blocking point B.
class Wall(composite_behavior.CompositeBehavior):
    class State(enum.Enum):
        defense_wall = 1

    def __init__(self,
                 num_defenders = 3,                         # number of defenders we're making the wall with (default 3)
                 curvature =  0,                             # curvature (in radians) of the wall 0 - pi/2
                 mark_point = None,                         # what point we are defending against (default is ball)
                 defender_point = robocup.Point(0, 0),      # what point we are defending (default is goal)
                 defender_spacing = 3.5,                      # number of robot radii between the centers of the defenders in the wall
                 dist_from_mark = 1,                        # distance from the mark point we want to build the wall
                 defender_priorities = [20, 19, 18, 17, 16]): # default defense priorities                       
        super().__init__(continuous=True)

        self.number_of_defenders = num_defenders
        self.curvature = -1 * curvature
        self._mark_point = main.ball().pos if mark_point == None else mark_point
        self._defense_point = defender_point
        self.dist_from_mark = dist_from_mark
        self.defender_spacing = defender_spacing
        self.defender_priorities = defender_priorities

        self.add_state(Wall.State.defense_wall, 
                       behavior.Behavior.State.running)

        self.add_transition(behavior.Behavior.State.start,
                            Wall.State.defense_wall, lambda: True,
                            "immideately")

    def on_enter_defense_wall(self):
        self.remove_all_subbehaviors()
        midpoint = self.mark_point + (self.defense_point - self.mark_point).normalized() * self.dist_from_mark
        angle = (midpoint - self.defense_point).angle()
        for i, priority in enumerate(self.defender_priorities[:self.number_of_defenders]):
            pt = self.calculate_destination(midpoint, angle, i)
            self.add_subbehavior(
                skills.move.Move(pt),
                name="robot" + str(i),
                required=False,
                priority=priority)

    # Finds the point on the arc the defender should move to
    def calculate_destination(self, midpoint, angle, robot_number):
        defender_number = robot_number - self.number_of_defenders / 2 + .5
        x_perp = robocup.Point(1, self.defense_point.y)
        x_perp.rotate(self.defense_point, angle + defender_number * self.curvature + math.pi/2)
        return midpoint + x_perp * constants.Robot.Radius * self.defender_spacing * defender_number        

    @property
    def defense_point(self):
        return self._defense_point

    @property
    def mark_point(self):
        return self._mark_point

    # Changes the point we are defending against attack, updates move behaviors
    @defense_point.setter
    def defense_point(self, point):
        self._defense_point = point
        midpoint = self.mark_point + (self.defense_point - self.mark_point).normalized() * self.dist_from_mark
        angle = (midpoint - self.defense_point).angle()
        for i in range(self.number_of_defenders):
            if self.has_subbehavior_with_name("robot" + str(i)):
                behavior = self.subbehavior_with_name("robot" + str(i))
                behavior.pos = self.calculate_destination(midpoint, angle, i)

    # Changes the point we are building a wall against, updates move behaviors
    @mark_point.setter
    def mark_point(self, point):
        self._mark_point = point
        midpoint = self.mark_point + (self.defense_point - self.mark_point).normalized() * self.dist_from_mark
        angle = (midpoint - self.defense_point).angle()
        for i in range(self.number_of_defenders):
            if self.has_subbehavior_with_name("robot" + str(i)):
                behavior = self.subbehavior_with_name("robot" + str(i))
                behavior.pos = self.calculate_destination(midpoint, angle, i)
{'fraction_non_alphanumeric': 0.0780159521435693, 'fraction_numerical': 0.005483549351944167, 'mean_word_length': 2.202314445331205, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2112996', 'n_tokens_mistral': 2319, 'n_tokens_neox': 2156, 'n_words': 564}