<commit_before>import play
import behavior
import skills.pivot_kick
import skills.move
import tactics.coordinated_pass
import tactics.behavior_sequence
import robocup
import constants
import main


## Continually runs a coordinated pass to opposite sides of the field
class OneTouchPass(play.Play):

    ReceiveXCoord = 1
    ReceiveYCoord = constants.Field.Length * 5.0 / 6.0

    def __init__(self):
        super().__init__(continuous=False)

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


        pass_bhvr = tactics.coordinated_pass.CoordinatedPass()
        self.add_subbehavior(pass_bhvr, 'pass')




    def reset_receive_point(self):
        pass_bhvr = self.subbehavior_with_name('pass')
        pass_bhvr.receive_point = robocup.Point(OneTouchPass.ReceiveXCoord, OneTouchPass.ReceiveYCoord)


    def execute_running(self):
        pass_bhvr = self.subbehavior_with_name('pass')


        if pass_bhvr.receive_point == None:
            self.reset_receive_point()

        if self.has_subbehavior_with_name('kick'):
            kick = self.subbehavior_with_name('kick')
            # TODO, if this isnt needed, merge with lower if

        elif pass_bhvr.is_done_running():
            kick = skills.pivot_kick.PivotKick()
            kick.target = constants.Field.TheirGoalSegment
            kick.aim_params['desperate_timeout'] = 3
            self.add_subbehavior(kick, 'kick', required=True)

    def on_exit_running(self):
        self.remove_all_subbehaviors()
        # TODO This restarts play if another robot is asigned the ball. Make it exit either way.

<commit_msg>Switched onetouchpass to use the state machine<commit_after>import play
import behavior
import skills.pivot_kick
import skills.move
import tactics.coordinated_pass
import tactics.behavior_sequence
import robocup
import constants
import main
from enum import Enum


## Continually runs a coordinated pass to opposite sides of the field
class OneTouchPass(play.Play):

    ReceiveXCoord = 1
    ReceiveYCoord = constants.Field.Length * 5.0 / 6.0

    class State(Enum):
        shooting = 1   # Shooting into the goal

    def __init__(self):
        super().__init__(continuous=False)

        for state in OneTouchPass.State:
            self.add_state(state, behavior.Behavior.State.running)

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

        self.add_transition(behavior.Behavior.State.running,
                OneTouchPass.State.shooting,
                lambda: self.subbehavior_with_name('pass').state == behavior.Behavior.State.completed,
                'preparing to shoot')

        self.add_transition(OneTouchPass.State.shooting,
                behavior.Behavior.State.completed,
                lambda: self.subbehavior_with_name('kick').state == behavior.Behavior.State.completed,
                'Shooter shot')

    def reset_receive_point(self):
        pass_bhvr = self.subbehavior_with_name('pass')
        pass_bhvr.receive_point = robocup.Point(OneTouchPass.ReceiveXCoord, OneTouchPass.ReceiveYCoord)

    def on_enter_running(self):
        pass_bhvr = tactics.coordinated_pass.CoordinatedPass()
        self.add_subbehavior(pass_bhvr, 'pass')
        if pass_bhvr.receive_point == None:
            self.reset_receive_point()


    def on_enter_shooting(self):
        kick = skills.pivot_kick.PivotKick()
        self.add_subbehavior(kick, 'kick', required=True)
        kick = self.subbehavior_with_name('kick')
        kick.target = constants.Field.TheirGoalSegment
        kick.aim_params['desperate_timeout'] = 3

    def on_exit_running(self):
        self.remove_subbehavior('pass')

    def on_exit_shooting(self):
        self.remove_subbehavior('kick')

{'fraction_non_alphanumeric': 0.08556832694763729, 'fraction_numerical': 0.0033205619412515963, 'mean_word_length': 2.9475806451612905, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7652005', 'n_tokens_mistral': 1208, 'n_tokens_neox': 1091, 'n_words': 227}