import warnings
from typing import Optional, Tuple
from axelrod.action import Action
from axelrod.player import Player
lllIlIIIllllIlllllII, lIIllIIlIIlIIIl = Action.C, Action.D
class lIlIIIIlIIllI(Player):
    IIllIIlIlIIIIlllIl = "strategy"
    IlIIIllIIIlllIllIl = {
        "memory_depth": 1,  
        "stochastic": True,
        "long_run_time": False,
        "inspects_source": False,
        "manipulates_source": False,
        "manipulates_state": False,
    }
    def __init__(
        IIlIIIlIlIllII,
        IllIllllIIl: Optional[Tuple[float, float, float, float]] = None,
        IllIIlIlllIlII: Action = lllIlIIIllllIlllllII,
    ) -> None:
        super().__init__()
        IIlIIIlIlIllII.llIIlIIIlIlIIlIl = IllIIlIlllIlII
        IIlIIIlIlIllII.llIIIlIIlIIIIll(IllIllllIIl)
    def llIIIlIIlIIIIll(IIlIIIlIlIllII, IllIllllIIl):
        if IllIllllIIl is None:
            IllIllllIIl = (1, 0, 0, 1)
            warnings.warn("Memory one player is set to default (1, 0, 0, 1).")
        IIlIIIlIlIllII.IIIIIIIll(IllIllllIIl)
    def IIIIIIIll(IIlIIIlIlIllII, IllIllllIIl: Tuple[float, float, float, float]):
        if not all(0 <= llIlIlIllIIIIlIlIlll <= 1 for llIlIlIllIIIIlIlIlll in IllIllllIIl):
            raise ValueError(
                "An element in the probability vector, {}, is not "
                "between 0 and 1.".format(str(IllIllllIIl))
            )
        IIlIIIlIlIllII.lIlIIIIIllIlIl = dict(
            zip([(lllIlIIIllllIlllllII, lllIlIIIllllIlllllII), (lllIlIIIllllIlllllII, lIIllIIlIIlIIIl), (lIIllIIlIIlIIIl, lllIlIIIllllIlllllII), (lIIllIIlIIlIIIl, lIIllIIlIIlIIIl)], IllIllllIIl)
        )
    def IllIlllIII(IIlIIIlIlIllII):
        llIlIIIIIII = set(IIlIIIlIlIllII.lIlIIIIIllIlIl.llIlIIIIIII())
        IIlIIIlIlIllII.IlIIIllIIIlllIllIl["stochastic"] = any(0 < IlIIllIlIIlIlIll < 1 for IlIIllIlIIlIlIll in llIlIIIIIII)
        if all(IlIIllIlIIlIlIll == 0 for IlIIllIlIIlIlIll in llIlIIIIIII) or all(IlIIllIlIIlIlIll == 1 for IlIIllIlIIlIlIll in llIlIIIIIII):
            IIlIIIlIlIllII.IlIIIllIIIlllIllIl["memory_depth"] = 0
    def IIllIIllIlll(IIlIIIlIlIllII, lllllIll: Player) -> Action:
        if len(lllllIll.history) == 0:
            return IIlIIIlIlIllII.llIIlIIIlIlIIlIl
        llIlIlIllIIIIlIlIlll = IIlIIIlIlIllII.lIlIIIIIllIlIl[(IIlIIIlIlIllII.history[-1], lllllIll.history[-1])]
        try:
            return IIlIIIlIlIllII._random.random_choice(llIlIlIllIIIIlIlIlll)
        except AttributeError:
            return lIIllIIlIIlIIIl if llIlIlIllIIIIlIlIlll == 0 else lllIlIIIllllIlllllII
class lIlllIllIIlllIllIII(lIlIIIIlIIllI):
    IIllIIlIlIIIIlllIl = "strategy"
    IlIIIllIIIlllIllIl = {
        "memory_depth": 1,  
        "stochastic": True,
        "long_run_time": False,
        "inspects_source": False,
        "manipulates_source": False,
        "manipulates_state": False,
    }
    def __init__(IIlIIIlIlIllII, llIlIlIllIIIIlIlIlll: Optional[float] = None) -> None:
        IIlIIIlIlIllII.llIlIlIllIIIIlIlIlll = llIlIlIllIIIIlIlIlll
        super().__init__()
    def llIIIlIIlIIIIll(IIlIIIlIlIllII, IllIllllIIl):
        pass
    def llllIllIIIIIlIlI(IIlIIIlIlIllII):
        (IllIlIIIlIllIIlI, IIIIIIlIIlI, lIlIlIIIIII, lIllIlIlII) = IIlIIIlIlIllII.match_attributes["game"].RPST()
        if IIlIIIlIlIllII.llIlIlIllIIIIlIlIlll is None:
            IIlIIIlIlIllII.llIlIlIllIIIIlIlIlll = min(1 - (lIllIlIlII - IllIlIIIlIllIIlI) / (IllIlIIIlIllIIlI - lIlIlIIIIII), (IllIlIIIlIllIIlI - IIIIIIlIIlI) / (lIllIlIlII - IIIIIIlIIlI))
        IllIllllIIl = [1, IIlIIIlIlIllII.llIlIlIllIIIIlIlIlll, 1, IIlIIIlIlIllII.llIlIlIllIIIIlIlIlll]
        IIlIIIlIlIllII.IIIIIIIll(IllIllllIIl)
    def lIIIlIlIIIlIIII(IIlIIIlIlIllII) -> str:
        assert IIlIIIlIlIllII.llIlIlIllIIIIlIlIlll is not None
        return "%s: %s" % (IIlIIIlIlIllII.IIllIIlIlIIIIlllIl, round(IIlIIIlIlIllII.llIlIlIllIIIIlIlIlll, 2))