<commit_before>"""
This file contains the prototypes needed for the implementations
of the algorithms.
"""

import math
from sneakymaze.exceptions import InvalidSizeException, EvenException

class Maze2DPrototype(object):
    """
    Prototype for 2D mazes with standard functions.
    """

    def __init__(self, size, seed = None, start=(1, 1)):

        #Convert Size to Tuple if needed
        if not type(size) in (type(()), type([])):
            if type(size) == type(0):
                size = (size, size)
            else:
                raise InvalidSizeException

        #Make sure that the Size is an integer
        size = (int(math.floor(size[0])), int(math.floor(size[1])))

        #Size Checks
        if size[0] % 2 != 1 or size[1] % 2 != 1:
            raise EvenException
        if size[0] < 3 or size[1] < 3:
            raise InvalidSizeException
        self.size = size

        #Start Checks
        if start[0] % 2 != 1 or start[1] % 2 != 1:
            raise EvenException
        self.start = start

        #Clear Content
        self.content = None

        #Start Generator
        self.regenerate(seed)

    def __repr__(self):
        return self.getstring()

    def _isinside(self, pos):
        """Checks if a position is inside the array."""
        xinside = pos[0] > 0 and pos[0] < self.size[0]
        yinside = pos[1] > 0 and pos[1] < self.size[1]
        return xinside and yinside

    def _getneighbours(self, pos):
        """Returns all neighbours of a position."""
        neighbours = []
        cell = (pos[0], pos[1] + 2)
        if self._isinside(cell):
            neighbours.append(cell)
        cell = (pos[0], pos[1] - 2)
        if self._isinside(cell):
            neighbours.append(cell)
        cell = (pos[0] + 2, pos[1])
        if self._isinside(cell):
            neighbours.append(cell)
        cell = (pos[0] - 2, pos[1])
        if self._isinside(cell):
            neighbours.append(cell)
        return neighbours

    def _getwallneighbours(self, pos):
        """Returns only the neighbours which are a wall (have value 'False')."""
        mylist = []
        neighbours = self._getneighbours(pos)
        for neighbour in neighbours:
            if not self.content[neighbour[0]][neighbour[1]]:
                mylist.append(neighbour)
        return mylist

    def clear(self):
        """Sets all cells of the array to false."""
        self.content = [[False for _ in range(self.size[1])]
                        for _ in range(self.size[0])]<commit_msg>Replaced manual appending with yielding<commit_after>"""
This file contains the prototypes needed for the implementations
of the algorithms.
"""

import math
from sneakymaze.exceptions import InvalidSizeException, EvenException

class Maze2DPrototype(object):
    """
    Prototype for 2D mazes with standard functions.
    """

    def __init__(self, size, seed = None, start=(1, 1)):

        #Convert Size to Tuple if needed
        if not type(size) in (type(()), type([])):
            if type(size) == type(0):
                size = (size, size)
            else:
                raise InvalidSizeException

        #Make sure that the Size is an integer
        size = (int(math.floor(size[0])), int(math.floor(size[1])))

        #Size Checks
        if size[0] % 2 != 1 or size[1] % 2 != 1:
            raise EvenException
        if size[0] < 3 or size[1] < 3:
            raise InvalidSizeException
        self.size = size

        #Start Checks
        if start[0] % 2 != 1 or start[1] % 2 != 1:
            raise EvenException
        self.start = start

        #Clear Content
        self.content = None

        #Start Generator
        self.regenerate(seed)

    def __repr__(self):
        return self.getstring()

    def _isinside(self, pos):
        """Checks if a position is inside the array."""
        xinside = pos[0] > 0 and pos[0] < self.size[0]
        yinside = pos[1] > 0 and pos[1] < self.size[1]
        return xinside and yinside

    def _getneighbours(self, pos):
        """Returns all neighbours of a position."""
        cell = (pos[0], pos[1] + 2)
        if self._isinside(cell):
            yield cell
        cell = (pos[0], pos[1] - 2)
        if self._isinside(cell):
            yield cell
        cell = (pos[0] + 2, pos[1])
        if self._isinside(cell):
            yield cell
        cell = (pos[0] - 2, pos[1])
        if self._isinside(cell):
            yield cell

    def _getwallneighbours(self, pos):
        """Returns only the neighbours which are a wall (have value 'False')."""
        mylist = []
        neighbours = self._getneighbours(pos)
        for neighbour in neighbours:
            if not self.content[neighbour[0]][neighbour[1]]:
                mylist.append(neighbour)
        return mylist

    def clear(self):
        """Sets all cells of the array to false."""
        self.content = [[False for _ in range(self.size[1])]
                        for _ in range(self.size[0])]
{'fraction_non_alphanumeric': 0.11638621794871795, 'fraction_numerical': 0.018830128205128204, 'mean_word_length': 1.9791169451073987, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, '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': '1040741', 'n_tokens_mistral': 1561, 'n_tokens_neox': 1466, 'n_words': 458}