def getstate(cells, pos, inc):
    """
    A helper function to call within a cellular automata's rule function to
    access the value of neighbor cells at position pos + inc. See: `states()`.

    The new position pos+inc will automatically wrap mod the size of the cells
    array so will never go out of bounds.

    Parameters
    ----------
    cells : list
        An array of cells holding the cellular automata's current states.

    pos : tuple
        The (*row*, *col*) index of the current cell in the cells array.
        Your rule function will receive this position in its pos argument.
        To access a neighbor cell, pass the pos value to getstate() along
        with a positional increment *inc*.
    
    inc : int | tuple
        A positive or negative offset to add to pos to calculate the position of the
        neighbor cell. This must be a tuple (*row*, *col*) for 2D automata. For 1D
        cases you can specify a positive or negative integer, or a tuple (0, *col*).

    Returns
    -------
    The value of the neighbor cell at pos+inc.
    """

    if not isinstance(inc, tuple):
        inc = (0, inc)
    row = (pos[0] + inc[0]) % len(cells)
    col = (pos[1] + inc[1]) % len(cells[0])
    return cells[row][col]