from typing import Optional
from axelrod._strategy_utils import detect_cycle
from axelrod.action import Action
from axelrod.player import Player
from .axelrod_first import FirstByJoss as Joss
lIIlllllIIIIlIIllIIl, IIllllIllIllIllIIII = Action.C, Action.D
class llIIlIllIlIllllIII(Player):
    lIIlIlllIll = "strategy"
    IlIlIllIIllIlIIl = {
        "memory_depth": float("inf"),
        "stochastic": True,
        "long_run_time": False,
        "inspects_source": False,
        "manipulates_source": False,
        "manipulates_state": False,
    }
    def __init__(lIIlIIIllIlll) -> None:
        lIIlIIIllIlll.llIlIlIIIIlII = Joss()
        super().__init__()
    def lIlIlIIlIIIll(lIIlIIIllIlll, IlIIlIIlIIlIlIlllIIl: Optional[int] = None):
        super().lIlIlIIlIIIll(IlIIlIIlIIlIlIlllIIl)
        lIIlIIIllIlll.llIlIlIIIIlII.lIlIlIIlIIIll(IlIIlIIlIIlIlIlllIIl)
    def IlIIlIllIIIlIlII(lIIlIIIllIlll, llllIlllll: Player) -> Action:
        lllIIIll = len(lIIlIIIllIlll.history)
        if lllIIIll > 0:
            lIIlIIIllIlll.llIlIlIIIIlII.history.append(
                lIIlIIIllIlll.history[-1], llllIlllll.history[-1]
            )
        if lllIIIll == 20:
            lIIlIIIllIlll.lIllIllIlI = detect_cycle(llllIlllll.history)
            return lIIlIIIllIlll.lIIIIIIIIIIIIIIIIllI(llllIlllll)
        if lllIIIll > 20:
            return lIIlIIIllIlll.lIIIIIIIIIIIIIIIIllI(llllIlllll)
        else:
            IllIIIlIIlIllll = lIIlIIIllIlll.llIlIlIIIIlII.IlIIlIllIIIlIlII(llllIlllll)
            return IllIIIlIIlIllll
    def lIIIIIIIIIIIIIIIIllI(lIIlIIIllIlll, llllIlllll: Player) -> Action:
        if lIIlIIIllIlll.lIllIllIlI:
            return IIllllIllIllIllIIII
        else:
            return IIllllIllIllIllIIII if llllIlllll.history[-1:] == [IIllllIllIllIllIIII] else lIIlllllIIIIlIIllIIl