def generate_grid(obj, size):
    """Returns an array of x,y pairs representing all the coordinates in a
    square (size * size) grid centered around a RoomPosition object"""

    pos = obj.pos or obj

    # set boundaries to respect room position limits
    left, right = max(0, pos.x - size), min(49, pos.x + size) + 1
    top, bottom = max(0, pos.y - size), min(49, pos.y + size) + 1

    return [[x, y] for x in range(left, right) for y in range(top, bottom)]