# Player: huggingface_DeepSeek-V3-0324_PayoffMaximizer_A (as Player A)
# Meta-Round: 2
# Experiment: PMxPM, Run: 2
# API: huggingface, Model: deepseek-ai/DeepSeek-V3-0324
# Based on textual strategy: huggingface_DeepSeek_V3_0324_PayoffMaximizer_A_MR2_strategy.txt
# LLM Suggested Fallback: D

def huggingface_DeepSeek_V3_0324_PayoffMaximizer_A_MR2(my_history: list, opp_history: list, opponent_program_code: str) -> str:
    current_round = len(my_history) + 1
    total_rounds = 10
    
    # Initial move: Cooperate
    if current_round == 1:
        return "C"
    
    # Late game: Defect in last two rounds
    if current_round >= total_rounds - 1:
        return "D"
    
    # Check for deterministic opponent strategies
    always_cooperate = "always cooperate" in opponent_program_code.lower() or "return 'C'" in opponent_program_code.lower()
    always_defect = "always defect" in opponent_program_code.lower() or "return 'D'" in opponent_program_code.lower()
    
    if always_cooperate:
        return "D"
    if always_defect:
        return "C"
    
    # Grim trigger if opponent defected first
    if "D" in opp_history and current_round == 2:
        return "D"
    if "D" in opp_history[:1] and current_round > 2:
        return "D"
    
    # Tit-for-Tat with occasional forgiveness
    if len(opp_history) >= 2 and opp_history[-1] == "D" and opp_history[-2] == "D":
        if random.random() < 0.2:  # 20% chance to forgive
            return "C"
        else:
            return "D"
    
    # Default Tit-for-Tat
    if opp_history:
        return opp_history[-1]
    
    # Fallback: Cooperate
    return "C"