<commit_before>import sys

from fmtstr.fmtfuncs import red, bold, green, on_blue, yellow, on_red

from fmtstr.terminal import Terminal
from fmtstr.terminalcontrol import TerminalController
from fmtstr.fsarray import FSArray

class Entity(object):
    def __init__(self, display, x, y, speed=1):
        self.display = display
        self.x, self.y = x, y
        self.speed = speed

    def towards(self, entity):
        dx = entity.x - self.x
        dy = entity.y - self.y
        desired_x = dx/abs(dx) * self.speed if dx else 0
        desired_y = dy/abs(dy) * self.speed if dy else 0
        return desired_x, desired_y

class World(object):
    def __init__(self, width, height):
        self.width = width
        self.height = height
        self.player = Entity(on_blue(green(bold('5'))), width // 2, height // 2 - 2, speed=5)
        self.npcs = [Entity(on_blue(red('X')), i * width // 10, j * height // 10) for i in range(10) for j in range(10)]
        self.turn = 0

    entities = property(lambda self: self.npcs + [self.player])

    def move_entity(self, entity, dx, dy):
        entity.x = max(0, min(self.width-1, entity.x + dx))
        entity.y = max(0, min(self.height-1, entity.y + dy))

    def process_event(self, c):
        if c == "":
            sys.exit()
        elif c in ('KEY_UP', 'KEY_LEFT', 'KEY_DOWN', 'KEY_RIGHT'):
            self.move_entity(self.player, *{'KEY_UP':(0,self.player.speed),
                                            'KEY_LEFT':(-self.player.speed, 0),
                                            'KEY_DOWN':(0,-self.player.speed),
                                            'KEY_RIGHT':(self.player.speed, 0)}[c])
        else:
            self.msg = Terminal.array_from_text_rc("try w, a, s, d, or ctrl-D", self.height, self.width)
        return self.tick()<commit_msg>fairer start on smaller screens in gameexample<commit_after>import sys

from fmtstr.fmtfuncs import red, bold, green, on_blue, yellow, on_red

from fmtstr.terminal import Terminal
from fmtstr.terminalcontrol import TerminalController
from fmtstr.fsarray import FSArray

class Entity(object):
    def __init__(self, display, x, y, speed=1):
        self.display = display
        self.x, self.y = x, y
        self.speed = speed

    def towards(self, entity):
        dx = entity.x - self.x
        dy = entity.y - self.y
        desired_x = dx/abs(dx) * self.speed if dx else 0
        desired_y = dy/abs(dy) * self.speed if dy else 0
        return desired_x, desired_y

class World(object):
    def __init__(self, width, height):
        self.width = width
        self.height = height
        n = 10
        self.player = Entity(on_blue(green(bold('5'))), width // 2, height // 2 - 2, speed=5)
        self.npcs = [Entity(on_blue(red('X')), i * width // (n * 2), j * height // (n * 2)) for i in range(1, 2*n, 2) for j in range(1, 2*n, 2)]
        self.turn = 0

    entities = property(lambda self: self.npcs + [self.player])

    def move_entity(self, entity, dx, dy):
        entity.x = max(0, min(self.width-1, entity.x + dx))
        entity.y = max(0, min(self.height-1, entity.y + dy))

    def process_event(self, c):
        if c == "":
            sys.exit()
        elif c in ('KEY_UP', 'KEY_LEFT', 'KEY_DOWN', 'KEY_RIGHT'):
            self.move_entity(self.player, *{'KEY_UP':(0,self.player.speed),
                                            'KEY_LEFT':(-self.player.speed, 0),
                                            'KEY_DOWN':(0,-self.player.speed),
                                            'KEY_RIGHT':(self.player.speed, 0)}[c])
        else:
            self.msg = Terminal.array_from_text_rc("try w, a, s, d, or ctrl-D", self.height, self.width)
        return self.tick()
{'fraction_non_alphanumeric': 0.1368505623995715, 'fraction_numerical': 0.013926084627745045, 'mean_word_length': 2.0564648117839606, 'pattern_counts': {'":': 2, '<': 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': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4375232', 'n_tokens_mistral': 1225, 'n_tokens_neox': 1184, 'n_words': 321}