def nb_open_ends(x, y, dx, dy, nb_consec, position):
  """Number of empty intersections (0, 1 or 2) next to the `nb_consec` stones
  (starting from (x,y) and using slope (dx, dy)) in the board position
  `position`.

  Parameters
  ----------
  x: int
    x-coordinate of the start position
  y: int
    x-coordinate of the start position
  dx: int
    x-coordinate slope
  dy: int
    y-coordinate slope
  nb_consec: int
    Maximum number of consecutive stones of color `color` in the board position
    `position`,starting from (x,y) and using slope (dx, dy).
  position: numpy.ndarray
    Position of the board

  Return
  ------
  ends: int
    number of empty intersections next to the consecutive stones
  """
  m = len(position)
  x_1, y_1, x_2, y_2 = x - dx, y - dy, x + nb_consec * dx, y + nb_consec * dy
  nb_open_ends = 0
  nb_open_ends += (0 <= x_1 < m and 0 <= y_1 < m) and position[x_1][y_1] == 0
  nb_open_ends += (0 <= x_2 < m and 0 <= y_2 < m) and position[x_2][y_2] == 0
  return nb_open_ends