<commit_before>import play
import behavior
import skills
import tactics
import main
import robocup
import evaluation
import constants

class Basic122(play.Play):

    # how far the 2 support robots should stay away from the striker
    SupportAvoidTeammateRadius = 0.5

    OffenseSupportRatio = 0.7
    DefenseSupportRatio = 0.9

    # if an opponent is this close to the striker, we don't instruct the support bots to mark him
    SupportBackoffThresh = 1.5

    # multiplier used to decide when it's worth it to reassign the bot a support is marking
    MarkHysteresisCoeff = 0.9



    def __init__(self):
        super().__init__(continuous=False)  # FIXME: continuous?

        striker = skills.pivot_kick.PivotKick()

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

        striker.add_transition(behavior.Behavior.State.completed,
            behavior.Behavior.State.start,
            lambda: True,
            "immediately")
        self.add_subbehavior(striker, 'striker', required=False, priority=5)

        left = tactics.positions.defender.Defender(tactics.positions.defender.Defender.Side.left)
        self.add_subbehavior(left, 'left', required=False, priority=1)

        right = tactics.positions.defender.Defender(tactics.positions.defender.Defender.Side.right)
        self.add_subbehavior(right, 'right', required=False, priority=3)

        support1 = skills.mark.Mark()
        support1.mark_line_thresh = 1.0
        self.add_subbehavior(support1, 'support1', required=False, priority=2)

        support2 = skills.mark.Mark()
        support2.mark_line_thresh = 1.0
        self.add_subbehavior(support2, 'support2', required=False, priority=4)



    @classmethod
    def score(cls):
        return 0 if main.game_state().is_playing() else float("inf")


    def execute_running(self):
        striker = self.subbehavior_with_name('striker')
        support1 = self.subbehavior_with_name('support1')
        support2 = self.subbehavior_with_name('support2')
        supports = [support1, support2]


        # project ball location a bit into the future
        ball_proj = evaluation.ball.predict(main.ball().pos, main.ball().vel, t=0.75)


        # find closest opponent to striker
        closest_dist_to_striker, closest_opp_to_striker = float("inf"), None
        if striker.robot != None:
            for opp in main.their_robots():
                d = opp.pos.dist_to(striker.robot.pos)
                if d < closest_dist_to_striker:
                    closest_dist_to_striker, closest_opp_to_striker = d, opp

        striker_engaged = striker.robot != None and closest_dist_to_striker < Basic122.SupportBackoffThresh


        # pick out which opponents our defenders should 'mark'
        # TODO: explain
        nrOppClose = 0
        bestOpp1, bestOpp2 = None, None
        bestDistSq1, bestDistSq2 = float("inf"), float("inf")
        for opp in main.their_robots():<commit_msg>Imports defense behavior into basic122.<commit_after>import play
import behavior
import skills
import tactics
import main
import robocup
import evaluation
import constants

class Basic122(play.Play):

    # how far the 2 support robots should stay away from the striker
    SupportAvoidTeammateRadius = 0.5

    OffenseSupportRatio = 0.7
    DefenseSupportRatio = 0.9

    # if an opponent is this close to the striker, we don't instruct the support bots to mark him
    SupportBackoffThresh = 1.5

    # multiplier used to decide when it's worth it to reassign the bot a support is marking
    MarkHysteresisCoeff = 0.9



    def __init__(self):
        super().__init__(continuous=False)  # FIXME: continuous?

        striker = skills.pivot_kick.PivotKick()

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

        striker.add_transition(behavior.Behavior.State.completed,
            behavior.Behavior.State.start,
            lambda: True,
            "immediately")
        self.add_subbehavior(striker, 'striker', required=False, priority=1)

        support1 = skills.mark.Mark()
        support1.mark_line_thresh = 1.0
        self.add_subbehavior(support1, 'support1', required=False, priority=2)

        support2 = skills.mark.Mark()
        support2.mark_line_thresh = 1.0
        self.add_subbehavior(support2, 'support2', required=False, priority=3)

        self.add_subbehavior(tactics.defense.Defense(), 'defense', required=False,)

    @classmethod
    def score(cls):
        return 0 if main.game_state().is_playing() else float("inf")

    @classmethod
    def handles_goalie(cls):
        return True

    def execute_running(self):
        striker = self.subbehavior_with_name('striker')
        support1 = self.subbehavior_with_name('support1')
        support2 = self.subbehavior_with_name('support2')
        supports = [support1, support2]


        # project ball location a bit into the future
        ball_proj = evaluation.ball.predict(main.ball().pos, main.ball().vel, t=0.75)


        # find closest opponent to striker
        closest_dist_to_striker, closest_opp_to_striker = float("inf"), None
        if striker.robot != None:
            for opp in main.their_robots():
                d = opp.pos.dist_to(striker.robot.pos)
                if d < closest_dist_to_striker:
                    closest_dist_to_striker, closest_opp_to_striker = d, opp

        striker_engaged = striker.robot != None and closest_dist_to_striker < Basic122.SupportBackoffThresh


        # pick out which opponents our defenders should 'mark'
        # TODO: explain
        nrOppClose = 0
        bestOpp1, bestOpp2 = None, None
        bestDistSq1, bestDistSq2 = float("inf"), float("inf")
        for opp in main.their_robots():
{'fraction_non_alphanumeric': 0.08854961832061069, 'fraction_numerical': 0.016793893129770993, 'mean_word_length': 2.813712807244502, 'pattern_counts': {'":': 0, '<': 7, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7238070', 'n_tokens_mistral': 1842, 'n_tokens_neox': 1690, 'n_words': 419}