def extract_perception_and_answer(model_output):
    """
    Extract both perception and answer from model output.

    Parses the model's output to extract the perceived initial state and the solution.
    Handles different output formats and section headers.

    Args:
        model_output (str): The raw output from the model

    Returns:
        tuple: (initial_state, solution) where both are 2D arrays or None if parsing fails
    """
    try:
        # Handle plain text format
        if "Initial State" in model_output:
            parts = model_output.split('Initial State\n', 1)
        elif "Perception" in model_output:
            parts = model_output.split('Perception\n', 1)
        else:
            return None, None

        if len(parts) != 2:
            return None, None
        content = parts[1]

        if "Answer" in content:
            perception_answer = content.split('\nAnswer\n')
        elif "Solution" in content:
            perception_answer = content.split('\nSolution\n')
        else:
            return None, None

        if len(perception_answer) != 2:
            return None, None

        perception, answer = perception_answer

        if perception.strip() == "Wrong":
            initial_state = None
            # Remove outer brackets and split into rows
            raw_solution = answer.strip()[2:-2].split('],[')
            solution = [[c for c in row.split(',')] for row in raw_solution]
        else:
            if answer.strip() == "Wrong":
                raw_perception = perception.strip()[2:-2].split('],[')
                initial_state = [[c for c in row.split(',')] for row in raw_perception]
                solution = None
            else:
                # Remove outer brackets and split into rows
                raw_perception = perception.strip()[2:-2].split('],[')
                initial_state = [[c for c in row.split(',')] for row in raw_perception]
                raw_solution = answer.strip()[2:-2].split('],[')
                solution = [[c for c in row.split(',')] for row in raw_solution]

        initial_state = [[cell if cell != '*' else 0 for cell in row] for row in initial_state]

        return initial_state, solution
    except Exception as e:
        print(f"Error parsing output: {e}")
        return None, None

    Extract both perception and answer from model output.

    Parses the model's output to extract the perceived initial state and the solution.
    Handles different output formats and section headers.

    Args:
        model_output (str): The raw output from the model

    Returns:
        tuple: (initial_state, solution) where both are 2D arrays or None if parsing fails
    
vlmeval/dataset/utils/vgrpbench/score.py