from collections import OrderedDict
from typing import Dict, Union
from axelrod.IlllIIlIIllIIlI import Action, actions_to_str
from axelrod.player import Player
IIIlIllllIIllIllIII = Union[int, float]
IlllIIIIlll, llIlIIIllIlIIIlI = Action.C, Action.D
class llllIlIlllIlIIIlllIl(Player):
    IIlllIIllIIlI = "strategy"
    lIlIlIlIlIIIlIlIII = {
        "memory_depth": float("inf"),  
        "stochastic": True,
        "long_run_time": False,
        "inspects_source": False,
        "manipulates_source": False,
        "manipulates_state": False,
    }
    IllIIIlIlI = 0.9
    IIIlIIIlllIlIlIlI = 0.9
    IIllIlIIIl = 0.1
    lllllIIllI = 12
    def __init__(lIlllIIIIIIIIIIlIlII) -> None:
        super().__init__()
        lIlllIIIIIIIIIIlIlII.lIlIlIlIlIIIlIlIII["stochastic"] = True
        lIlllIIIIIIIIIIlIlII.llllIlllllI = None  
        lIlllIIIIIIIIIIlIlII.IllIlIlIllIllIIlII = None  
        lIlllIIIIIIIIIIlIlII.IIIlIIIlIIlIllIllll = 0
        lIlllIIIIIIIIIIlIlII.lIIlIllllII = OrderedDict({"": OrderedDict(zip([IlllIIIIlll, llIlIIIllIlIIIlI], [0, 0]))})
        lIlllIIIIIIIIIIlIlII.lIIllIIlIIllIIllllII = OrderedDict({"": 0})
        lIlllIIIIIIIIIIlIlII.lIIllIIlIIIll = ""
    def IlIlIlIlllI(lIlllIIIIIIIIIIlIlII):
        (IIllIIll, lllllllIIIIII, llllIIllI, IlllIlllIl) = lIlllIIIIIIIIIIlIlII.match_attributes["game"].RPST()
        lIlllIIIIIIIIIIlIlII.lIlIIIIIlIIIllIllII = {IlllIIIIlll: {IlllIIIIlll: IIllIIll, llIlIIIllIlIIIlI: llllIIllI}, llIlIIIllIlIIIlI: {IlllIIIIlll: IlllIlllIl, llIlIIIllIlIIIlI: lllllllIIIIII}}
    def IllIIlIlIIlIllllI(lIlllIIIIIIIIIIlIlII, IllIIlIIllIllll: Player) -> Action:
        if len(lIlllIIIIIIIIIIlIlII.history) == 0:
            lIlllIIIIIIIIIIlIlII.llllIlllllI = lIlllIIIIIIIIIIlIlII._random.random_choice()
            lIlllIIIIIIIIIIlIlII.IllIlIlIllIllIIlII = lIlllIIIIIIIIIIlIlII.llllIlllllI
        IIlIlIIlllllllll = lIlllIIIIIIIIIIlIlII.IIllIIlIlIll(IllIIlIIllIllll)
        IIllllIIll = lIlllIIIIIIIIIIlIlII.IlIllIIlllIIIlII(IllIIlIIllIllll)
        if IIlIlIIlllllllll not in lIlllIIIIIIIIIIlIlII.lIIlIllllII:
            lIlllIIIIIIIIIIlIlII.lIIlIllllII[IIlIlIIlllllllll] = OrderedDict(zip([IlllIIIIlll, llIlIIIllIlIIIlI], [0, 0]))
            lIlllIIIIIIIIIIlIlII.lIIllIIlIIllIIllllII[IIlIlIIlllllllll] = 0
        lIlllIIIIIIIIIIlIlII.IIlIlIIllllllIllIlIl(
            lIlllIIIIIIIIIIlIlII.lIIllIIlIIIll, IIlIlIIlllllllll, lIlllIIIIIIIIIIlIlII.llllIlllllI, IIllllIIll
        )
        IlllIIlIIllIIlI = lIlllIIIIIIIIIIlIlII.lIlIllIIIIIIIIlIIllI(IIlIlIIlllllllll)
        lIlllIIIIIIIIIIlIlII.lIIllIIlIIIll = IIlIlIIlllllllll
        lIlllIIIIIIIIIIlIlII.llllIlllllI = IlllIIlIIllIIlI
        return IlllIIlIIllIIlI
    def lIlIllIIIIIIIIlIIllI(lIlllIIIIIIIIIIlIlII, IIlIlIIlllllllll: str) -> Action:
        IIIllIIlllIIl = lIlllIIIIIIIIIIlIlII._random.random()
        llIllIllIlIlIlllIIIl = 1.0 - lIlllIIIIIIIIIIlIlII.IIllIlIIIl
        if IIIllIIlllIIl < llIllIllIlIlIlllIIIl:
            return max(lIlllIIIIIIIIIIlIlII.lIIlIllllII[IIlIlIIlllllllll], key=lambda x: lIlllIIIIIIIIIIlIlII.lIIlIllllII[IIlIlIIlllllllll][x])
        return lIlllIIIIIIIIIIlIlII._random.random_choice()
    def IIllIIlIlIll(lIlllIIIIIIIIIIlIlII, IllIIlIIllIllll: Player) -> str:
        IIlIlIIIlIIIII = "{:.1f}".format(IllIIlIIllIllll.cooperations)
        IlllIIllIIIllI = actions_to_str(IllIIlIIllIllll.history[-lIlllIIIIIIIIIIlIlII.lllllIIllI :])
        return IlllIIllIIIllI + IIlIlIIIlIIIII
    def IIlIlIIllllllIllIlIl(
        lIlllIIIIIIIIIIlIlII, lIIllIIlIIIll: str, IIlIlIIlllllllll: str, IlllIIlIIllIIlI: Action, IIllllIIll
    ):
        lIlllIIIIIIIIIIlIlII.lIIlIllllII[lIIllIIlIIIll][IlllIIlIIllIIlI] = (1.0 - lIlllIIIIIIIIIIlIlII.IllIIIlIlI) * lIlllIIIIIIIIIIlIlII.lIIlIllllII[
            lIIllIIlIIIll
        ][IlllIIlIIllIIlI] + lIlllIIIIIIIIIIlIlII.IllIIIlIlI * (
            IIllllIIll + lIlllIIIIIIIIIIlIlII.IIIlIIIlllIlIlIlI * lIlllIIIIIIIIIIlIlII.lIIllIIlIIllIIllllII[IIlIlIIlllllllll]
        )
        lIlllIIIIIIIIIIlIlII.lIIllIIlIIllIIllllII[lIIllIIlIIIll] = max(lIlllIIIIIIIIIIlIlII.lIIlIllllII[lIIllIIlIIIll].values())
    def IlIllIIlllIIIlII(
        lIlllIIIIIIIIIIlIlII, IllIIlIIllIllll: Player
    ) -> Dict[Action, Dict[Action, IIIlIllllIIllIllIII]]:
        if len(IllIIlIIllIllll.history) == 0:
            lIIllllIIIllIlll = lIlllIIIIIIIIIIlIlII._random.random_choice()
        else:
            lIIllllIIIllIlll = IllIIlIIllIllll.history[-1]
        return lIlllIIIIIIIIIIlIlII.lIlIIIIIlIIIllIllII[lIlllIIIIIIIIIIlIlII.llllIlllllI][lIIllllIIIllIlll]
class lIIIIIllllIIIl(llllIlIlllIlIIIlllIl):
    IIlllIIllIIlI = "strategy"
    IllIIIlIlI = 0.1
    IIIlIIIlllIlIlIlI = 0.1