def _get_difficulty(bsp_leaf, difficulty_map):
  """
  *difficulty_map* is a dict mapping difficulty (int 1-4) to a BSPNode. Returns
  the difficulty of the given leaf, based on which difficulty_map value is its
  ancestor.
  """
  for ancestor in bsp_leaf.ancestors:
    for (k, v) in difficulty_map.items():
      if v == ancestor:
        return k
  raise ValueError("Cannot determine difficulty for this room")