import warnings
from typing import Optional, Tuple
from axelrod.action import Action
from axelrod.player import Player
IlllIllIlIllI, IllIIIlIIIllI = Action.C, Action.D
class lIllIIIll(Player):
    lIIIIlIlIlIIIIlII = "strategy"
    IlllIIIIIll = {
        "memory_depth": 1,  
        "stochastic": True,
        "long_run_time": False,
        "inspects_source": False,
        "manipulates_source": False,
        "manipulates_state": False,
    }
    def __init__(
        llIIlIlIlIlIIlI,
        lllIlIIll: Optional[Tuple[float, float, float, float]] = None,
        IllIllIl: Action = IlllIllIlIllI,
    ) -> None:
        super().__init__()
        llIIlIlIlIlIIlI.lllIIlll = IllIllIl
        llIIlIlIlIlIIlI.lIIllllIIIIlIlIlIllI(lllIlIIll)
    def lIIllllIIIIlIlIlIllI(llIIlIlIlIlIIlI, lllIlIIll):
        if lllIlIIll is None:
            lllIlIIll = (1, 0, 0, 1)
            warnings.warn("Memory one player is set to default (1, 0, 0, 1).")
        llIIlIlIlIlIIlI.IlllIlIIlI(lllIlIIll)
    def IlllIlIIlI(llIIlIlIlIlIIlI, lllIlIIll: Tuple[float, float, float, float]):
        if not all(0 <= llIllIlllIllIIllII <= 1 for llIllIlllIllIIllII in lllIlIIll):
            raise ValueError(
                "An element in the probability vector, {}, is not "
                "between 0 and 1.".format(str(lllIlIIll))
            )
        llIIlIlIlIlIIlI.lllIIIIIIlllI = dict(
            zip([(IlllIllIlIllI, IlllIllIlIllI), (IlllIllIlIllI, IllIIIlIIIllI), (IllIIIlIIIllI, IlllIllIlIllI), (IllIIIlIIIllI, IllIIIlIIIllI)], lllIlIIll)
        )
    def IIIlIIlIlIlll(llIIlIlIlIlIIlI):
        llllllIIIIIIIIll = set(llIIlIlIlIlIIlI.lllIIIIIIlllI.llllllIIIIIIIIll())
        llIIlIlIlIlIIlI.IlllIIIIIll["stochastic"] = any(0 < lIIllIlIlIllII < 1 for lIIllIlIlIllII in llllllIIIIIIIIll)
        if all(lIIllIlIlIllII == 0 for lIIllIlIlIllII in llllllIIIIIIIIll) or all(lIIllIlIlIllII == 1 for lIIllIlIlIllII in llllllIIIIIIIIll):
            llIIlIlIlIlIIlI.IlllIIIIIll["memory_depth"] = 0
    def IllIIIIIIIIllI(llIIlIlIlIlIIlI, IIIIIIIIl: Player) -> Action:
        if len(IIIIIIIIl.history) == 0:
            return llIIlIlIlIlIIlI.lllIIlll
        llIllIlllIllIIllII = llIIlIlIlIlIIlI.lllIIIIIIlllI[(llIIlIlIlIlIIlI.history[-1], IIIIIIIIl.history[-1])]
        try:
            return llIIlIlIlIlIIlI._random.random_choice(llIllIlllIllIIllII)
        except AttributeError:
            return IllIIIlIIIllI if llIllIlllIllIIllII == 0 else IlllIllIlIllI
class lllIlIlIlllIlllIll(lIllIIIll):
    lIIIIlIlIlIIIIlII = "strategy"
    def __init__(llIIlIlIlIlIIlI, llIllIlIlll: Tuple[float, float]) -> None:
        lllIlIIll = (*llIllIlIlll, *llIllIlIlll)
        super().__init__(lllIlIIll)