from typing import List


def get_alive_neighbors(y_pos: int, x_pos: int, state: List[List[int]]) -> int:
    """Counts alive neighbors of a cell with the passed coordinates.

    Args:
        y_pos: y position of the cell.
        x_pos: x position of the cell.
        state: A list of lists representing the board in a 2D space.

    Returns:
        The count of alive neighbors for a cell in state[y_pos][x_pos].
    """

    width = len(state[0])
    height = len(state)

    alive_neighbors = 0
    for neighbor_y_pos in range(y_pos - 1, y_pos + 2):
        # Make sure not to go off the grid vertically.
        if neighbor_y_pos < 0 or neighbor_y_pos >= height:
            continue

        for neighbor_x_pos in range(x_pos - 1, x_pos + 2):
            # Make sure not to compare to self.
            if neighbor_y_pos == y_pos and neighbor_x_pos == x_pos:
                continue

            # Make sure not go off the grid horizontally.
            if neighbor_x_pos < 0 or neighbor_x_pos >= width:
                continue

            alive_neighbors += state[neighbor_y_pos][neighbor_x_pos]

    return alive_neighbors