import itertools
import warnings
from typing import Dict, Optional, Tuple
from axelrod.action import Action
from axelrod.player import Player
from .defector import Defector
from .titfortat import TitFor2Tats, TitForTat
llIIIllIIl, lIIIllIIIIlllIlll = Action.C, Action.D
class IIIIIIIIIIl(Player):
    IIIIlIlIIII = "strategy"
    lIIllIlIlIIIlIIlIIIl = {
        "memory_depth": float("inf"),
        "long_run_time": False,
        "stochastic": False,
        "inspects_source": False,
        "manipulates_source": False,
        "manipulates_state": False,
    }
    def __init__(lIIllIIIlIIIIIIllI) -> None:
        super().__init__()
        lIIllIIIlIIIIIIllI.IIlllIIIIIIlIlIl = {
            "TFT": TitForTat(),
            "TFTT": TitFor2Tats(),
            "ALLD": Defector(),
        }
        lIIllIIIlIIIIIIllI.lIIlllllIllllIl = "TFT"
        lIIllIIIlIIIIIIllI.IIIIIlIlI = 3
        lIIllIIIlIIIIIIllI.IIIlIlIIlllIIIllIlIl = 0
    def IlIlIIlIllIII(lIIllIIIlIIIIIIllI, lIIllIIlIlIIIIll: Player) -> Action:
        if len(lIIllIIIlIIIIIIllI.history) > 0:
            for llIllIIlllIIllll in lIIllIIIlIIIIIIllI.IIlllIIIIIIlIlIl.values():
                llIllIIlllIIllll.history.append(lIIllIIIlIIIIIIllI.history[-1], lIIllIIlIlIIIIll.history[-1])
        lIIllIIIlIIIIIIllI.IIIIIlIlI -= 1
        if (lIIllIIIlIIIIIIllI.IIIIIlIlI == 0) and (lIIllIIIlIIIIIIllI.IIIlIlIIlllIIIllIlIl < 2):
            lIIllIIIlIIIIIIllI.IIIIIlIlI = 2
            IIIIlllIllllIIIlIlI = list(zip(lIIllIIIlIIIIIIllI.history[-2:], lIIllIIlIlIIIIll.history[-2:]))
            if set(IIIIlllIllllIIIlIlI) == {(llIIIllIIl, llIIIllIIl)}:
                lIIllIIIlIIIIIIllI.lIIlllllIllllIl = "TFT"
            elif set(IIIIlllIllllIIIlIlI) == {(llIIIllIIl, lIIIllIIIIlllIlll), (lIIIllIIIIlllIlll, llIIIllIIl)}:
                lIIllIIIlIIIIIIllI.lIIlllllIllllIl = "TFTT"
            else:
                lIIllIIIlIIIIIIllI.lIIlllllIllllIl = "ALLD"
                lIIllIIIlIIIIIIllI.IIIlIlIIlllIIIllIlIl += 1
        return lIIllIIIlIIIIIIllI.IIlllIIIIIIlIlIl[lIIllIIIlIIIIIIllI.lIIlllllIllllIl].IlIlIIlIllIII(lIIllIIlIlIIIIll)