def check_answer(answer, init_board, game_factory):
    """
    Verify if the model's answer is correct for the given puzzle.

    Performs game-specific validations and uses the game factory to check solution correctness.

    Args:
        answer (list): 2D array representing the model's solution
        init_board (list): 2D array representing the initial state
        game_factory (GameFactory): Factory object for the specific game type
    Returns:
        bool: True if the answer is correct, False otherwise
    """
    global GRID_SIZE
    # Game-specific preprocessing for answers
    if game_factory.game_name in ["treesandtents", "starbattle", "hitori", "aquarium", "kakurasu"]:
        for i in range(len(answer)):
            for j in range(len(answer[i])):
                if answer[i][j] in [0, '0']:
                    answer[i][j] = 'e'
    if game_factory.game_name == "oddevensudoku":
        for i in range(len(answer)):
            for j in range(len(answer[i])):
                try:
                    answer[i][j] = int(answer[i][j])
                except Exception as e:
                    return False
    if game_factory.game_name == "lightup":
        # Convert '0' to 'e'
        for i in range(len(answer)):
            for j in range(len(answer[i])):
                if answer[i][j] == '0':
                    answer[i][j] = 'e'
    # Convert string representation to 2D grid if needed
    if isinstance(init_board, str):
        init_grid = [[c for c in row] for row in init_board.strip().split('\n')]
    else:
        init_grid = init_board
    # Check dimensions
    if len(answer) != GRID_SIZE or any(len(row) != GRID_SIZE for row in answer):
        return False

    # Game-specific validation for initial values
    if game_factory.game_name == "hitori":
        # Compare with game_factory.additional_board
        for i in range(GRID_SIZE):
            for j in range(GRID_SIZE):
                if game_factory.additional_board[i][j] not in [0, '0'] and str(game_factory.additional_board[i][j]) != str(answer[i][j]):
                    return False
    elif game_factory.game_name == "nonogram":
        # Convert 0, '0', '*' in answer to 'e'
        for i in range(GRID_SIZE):
            for j in range(GRID_SIZE):
                if answer[i][j] in [0, '0', '*']:
                    answer[i][j] = 'e'
        for i in range(GRID_SIZE):
            for j in range(GRID_SIZE):
                if init_grid[i][j] not in [0, '0'] and str(init_grid[i][j]) != str(answer[i][j]):
                    return False
    elif game_factory.game_name == "fieldexplore":
        for i in range(GRID_SIZE):
            for j in range(GRID_SIZE):
                # 's' on the initial board must be kept
                if init_grid[i][j] == 's' and not answer[i][j] == 's':
                    return False
                try:
                    cell_value = int(init_grid[i][j])
                    if cell_value > 0 and str(answer[i][j]) == 's':
                        return False
                except (ValueError, TypeError):
                    # Cell is not a number, continue with other checks
                    pass
        return True
    else:
        for i in range(GRID_SIZE):
            for j in range(GRID_SIZE):
                if init_grid[i][j] not in [0, '0', 'e'] and str(init_grid[i][j]) != str(answer[i][j]):
                    return False
    # Prepare game state for validation
    game_state = {
        "board": answer,
        "size": GRID_SIZE,
    }

    # Add game-specific state information
    if game_factory.game_name == "skyscraper":
        game_state["clues"] = game_factory.clues
    elif game_factory.game_name == "coloredsudoku":
        game_state["colors"] = game_factory.current_colors
    elif game_factory.game_name == "futoshiki":
        game_state["inequalities"] = game_factory.current_inequalities
    elif game_factory.game_name == "killersudoku":
        game_state["cages"] = game_factory.cages
    elif game_factory.game_name == "renzoku":
        game_state["hints"] = game_factory.hints
    elif game_factory.game_name == 'kakuro':
        game_state["sums"] = game_factory.current_sums
    elif game_factory.game_name == "thermometers":
        game_state["clues"] = game_factory.clues
    elif game_factory.game_name == "treesandtents":
        game_state["clues"] = game_factory.clues
    elif game_factory.game_name == "starbattle":
        game_state["regions"] = game_factory.regions
    elif game_factory.game_name == "hitori":
        game_state["numbers"] = game_factory.numbers
    elif game_factory.game_name == "aquarium":
        game_state["clues"] = game_factory.clues
    elif game_factory.game_name == "kakurasu":
        game_state["clues"] = game_factory.clues
    elif game_factory.game_name == "oddevensudoku":
        game_state["cell_types"] = game_factory.cell_types
    elif game_factory.game_name == "nonogram":
        game_state["hints"] = game_factory.hints
    elif game_factory.game_name == "lightup":
        game_state["wall_numbers"] = game_factory.wall_numbers
    elif game_factory.game_name == "battleships":
        game_state["hints"] = game_factory.hints
    # Validate the solution using the game factory
    try:
        return game_factory.check(game_state)
    except Exception as e:
        print(f"Error checking answer: {e}")
        return False

    Verify if the model's answer is correct for the given puzzle.

    Performs game-specific validations and uses the game factory to check solution correctness.

    Args:
        answer (list): 2D array representing the model's solution
        init_board (list): 2D array representing the initial state
        game_factory (GameFactory): Factory object for the specific game type
    Returns:
        bool: True if the answer is correct, False otherwise
    
vlmeval/dataset/utils/vgrpbench/score.py