seagull/lifeforms/wiki.py
def parse_plaintext_layout(plaintext_str: Union[str, list]) -> np.ndarray:
    """Parse plaintext_str in Plaintext format into ndarray layout

    typical plaintext_str format:
    '''
    .O.O
    O.O
    O
    ......O
    '''

    Parameters
    ----------
    cells_str : Union[str, list]
        Plaintext format lifeform description
        May be a list of lines in which case no comment lines are allowed 

    Raises
    ------
    ValueError
        if invalid input provided

    """
    if isinstance(plaintext_str, list):
        # already line-split
        lines = plaintext_str
    else:
        # split lines, ignore comments
        lines = plaintext_str.strip().replace("\r\n", "\n").split("\n")
        lines = [line for line in lines if not line.startswith("!")]

    # check if only '.' and 'O' are present
    if set("".join(lines)) != {".", "O"}:
        raise ValueError("Invalid input cells_str : use only '.' and 'O'")

    layout = [[1 if c == "O" else 0 for c in line] for line in lines]

    max_width = max(len(line) for line in layout)
    # add zeroes so that all lines are of equal length
    [line.extend([0] * (max_width - len(line))) for line in layout]

    return np.array(layout)
Parse plaintext_str in Plaintext format into ndarray layout

    typical plaintext_str format:
    '''
    .O.O
    O.O
    O
    ......O
    '''

    Parameters
    ----------
    cells_str : Union[str, list]
        Plaintext format lifeform description
        May be a list of lines in which case no comment lines are allowed 

    Raises
    ------
    ValueError
        if invalid input provided

    


Parameters

cells_str : Union[str, list]
Plaintext format lifeform description
May be a list of lines in which case no comment lines are allowed

Raises

ValueError
if invalid input provided
Parameters cells_str : Union [ str list ] Plaintext format lifeform description May be a list of lines in which case no comment lines are allowed Raises ValueError if invalid input provided
def parse_plaintext_layout(plaintext_str: Union[str, list]) -> np.ndarray:
    if isinstance(plaintext_str, list):
        lines = plaintext_str
    else:
        lines = plaintext_str.strip().replace("\r\n", "\n").split("\n")
        lines = [line for line in lines if not line.startswith("!")]
    if set("".join(lines)) != {".", "O"}:
        raise ValueError("Invalid input cells_str : use only '.' and 'O'")
    layout = [[1 if c == "O" else 0 for c in line] for line in lines]
    max_width = max(len(line) for line in layout)
    [line.extend([0] * (max_width - len(line))) for line in layout]
    return np.array(layout)
def parse_plaintext_layout ( plaintext_str : Union [ str , list ] ) -> np . ndarray : if isinstance ( plaintext_str , list ) : lines = plaintext_str else : lines = plaintext_str . strip ( ) . replace ( "\r\n" , "\n" ) . split ( "\n" ) lines = [ line for line in lines if not line . startswith ( "!" ) ] if set ( "" . join ( lines ) ) != { "." , "O" } : raise ValueError ( "Invalid input cells_str : use only '.' and 'O'" ) layout = [ [ 1 if c == "O" else 0 for c in line ] for line in lines ] max_width = max ( len ( line ) for line in layout ) [ line . extend ( [ 0 ] * ( max_width - len ( line ) ) ) for line in layout ] return np . array ( layout )
Parse plaintext_str in Plaintext format into ndarray layout
typical plaintext_str format:
'''
.O.O
O.O
O
......O
'''
Parse plaintext_str in Plaintext format into ndarray layout typical plaintext_str format : ' ' ' . O . O O . O O ...... O ' ' '
"""Parse plaintext_str in Plaintext format into ndarray layout

    typical plaintext_str format:
    '''
    .O.O
    O.O
    O
    ......O
    '''

    Parameters
    ----------
    cells_str : Union[str, list]
        Plaintext format lifeform description
        May be a list of lines in which case no comment lines are allowed 

    Raises
    ------
    ValueError
        if invalid input provided

    """ # already line-split # split lines, ignore comments # check if only '.' and 'O' are present # add zeroes so that all lines are of equal length
plaintext_str
Union[str, list]