<commit_before>from fysom import Fysom

from yourgame.entity import GameEntity
from yourgame.hex_model import sprites_to_hex
from yourgame import resources


__all__ = ['Enemy',
           'Stalker',
           'Rambler',
           'Tosser']


class Enemy(GameEntity):
    def __init__(self, filename):
        super(Enemy, self).__init__(filename)
        self._home = (None, None)
        self.path = ()
        self.fsm = Fysom({'initial': 'home',
                          'events': [
                              {'name': 'go_home',
                               'src': 'seeking',
                               'dst': 'going_home'},
                              {'name': 'ramble',
                               'src': ['home', 'seeking'],
                               'dst': 'rambling'},
                              {'name': 'seek_player',
                               'src': ['home', 'going_home', 'rambling'],
                               'dst': 'seeking'}
                          ]})

    @property
    def home(self):
        return self._home

    @home.setter
    def home(self, coord):
        self._home = coord
        self.position.x, self.position.y = coord

    def handle_internal_events(self, scene):
        pass

    def update_ai(self, scene, event):
        fsm = self.fsm
        if fsm.isstate('home'):
            fsm.ramble()
        if fsm.isstate('going_home'):
            if self.position == self.home:
                fsm.ramble()
        if fsm.isstate('rambling'):
            blacklist = {sprites_to_hex(sprite.position)
                         for sprite in scene.internal_event_group}
            pos = sprites_to_hex(self.position)
            home = sprites_to_hex(self.home)
            if not self.path:
                self.path = scene.model.pathfind_ramble(
                    pos, home, self.radius, blacklist)[0]


class Stalker(GameEntity):
    """ follows the player
    """
    def __init__(self, filename):
        super(Stalker, self).__init__(filename)
        self.move_sound = resources.sounds['lose7.ogg']
        self._playing_move_sound = False
<commit_msg>hex !<commit_after>from fysom import Fysom

from yourgame.entity import GameEntity
from yourgame.hex_model import sprites_to_hex
from yourgame import resources


__all__ = ['Enemy',
           'Stalker',
           'Rambler',
           'Tosser']


class Enemy(GameEntity):
    def __init__(self, filename):
        super(Enemy, self).__init__(filename)
        self._home = (None, None)
        self.accel = 10
        self.moving = False
        self.radius = 2
        self.path = ()
        self.fsm = Fysom({'initial': 'home',
                          'events': [
                              {'name': 'go_home',
                               'src': 'seeking',
                               'dst': 'going_home'},
                              {'name': 'ramble',
                               'src': ['home', 'seeking'],
                               'dst': 'rambling'},
                              {'name': 'seek_player',
                               'src': ['home', 'going_home', 'rambling'],
                               'dst': 'seeking'}
                          ]})

    @property
    def home(self):
        return self._home

    @home.setter
    def home(self, coord):
        self._home = coord
        self.position.x, self.position.y = coord

    def handle_internal_events(self, scene):
        pass

    def update_ai(self, scene, event):
        fsm = self.fsm
        if fsm.isstate('home'):
            fsm.ramble()
        if fsm.isstate('going_home'):
            if self.position == self.home:
                fsm.ramble()
        if fsm.isstate('rambling'):
            blacklist = {sprites_to_hex(sprite.position)
                         for sprite in scene.internal_event_group}
            pos = sprites_to_hex(self.position)
            home = sprites_to_hex(self.home)
            if not self.path:
                self.path = list(scene.model.pathfind_ramble(
                    pos, home, self.radius, blacklist)[0])


class Stalker(GameEntity):
    """ follows the player
    """
    def __init__(self, filename):
        super(Stalker, self).__init__(filename)
        self.move_sound = resources.sounds['lose7.ogg']
        self._playing_move_sound = False

{'fraction_non_alphanumeric': 0.11595205163669894, 'fraction_numerical': 0.0016136468418626094, 'mean_word_length': 1.4681456200227532, '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': '1959209', 'n_tokens_mistral': 1248, 'n_tokens_neox': 1197, 'n_words': 257}