from typing import List
import numpy as np
from axelrod.action import Action
from axelrod.interaction_utils import compute_final_score
from axelrod.player import Player
from axelrod.strategies.finite_state_machines import FSMPlayer
lIlIlIllIlIll, lllllIIlIIIlII = Action.C, Action.D
class IlIllIIIIlII(Player):
    IIlllIllIIlllI = "strategy"
    lIllIlIII = {
        "memory_depth": float("inf"),
        "stochastic": True,
        "long_run_time": False,
        "inspects_source": False,
        "manipulates_source": False,
        "manipulates_state": False,
    }
    def __init__(lIIllllIII):
        super().__init__()
        lIIllllIII.lIlllIIIllIIIII = 0  
        lIIllllIII.IIIlIIllIllIllI = 0  
        lIIllllIII.IllIlIIIlIIIlIlI = 5  
        lIIllllIII.IIIIIllIllIllll = 0  
        lIIllllIII.IIIIllIllllIlIIlIl = (
            1  
        )
        lIIllllIII.IlIIIIlII = (
            1  
        )
        lIIllllIII.IIIIIllIII = {lIlIlIllIlIll: 0, lllllIIlIIIlII: 1}
    def IlIllIIIIllllllIlI(lIIllllIII, llllIIllIIII):
        if llllIIllIIII.history[-1] == lllllIIlIIIlII:
            lIIllllIII.IIIlIIllIllIllI += 1
        else:
            lIIllllIII.IIIlIIllIllIllI = 0
        if lIIllllIII.lIlllIIIllIIIII == 2:
            lIIllllIII.lIlllIIIllIIIII = 0
            lIIllllIII.IIIIIllIllIllll = (
                (
                    lIIllllIII.IIIIIllIllIllll
                    * lIIllllIII.IlIIIIlII
                )
                + (3 - (3 * lIIllllIII.IIIIIllIII[llllIIllIIII.history[-1]]))
                + (2 * lIIllllIII.IIIIIllIII[lIIllllIII.history[-1]])
                - (
                    (
                        lIIllllIII.IIIIIllIII[llllIIllIIII.history[-1]]
                        * lIIllllIII.IIIIIllIII[lIIllllIII.history[-1]]
                    )
                )
            ) / (lIIllllIII.IlIIIIlII + 1)
            lIIllllIII.IlIIIIlII += 1
        elif lIIllllIII.lIlllIIIllIIIII == 1:
            lIIllllIII.lIlllIIIllIIIII = 2
            lIIllllIII.IllIlIIIlIIIlIlI = (
                (
                    lIIllllIII.IllIlIIIlIIIlIlI
                    * lIIllllIII.IIIIllIllllIlIIlIl
                )
                + (3 - (3 * lIIllllIII.IIIIIllIII[llllIIllIIII.history[-1]]))
                + (2 * lIIllllIII.IIIIIllIII[lIIllllIII.history[-1]])
                - (
                    lIIllllIII.IIIIIllIII[llllIIllIIII.history[-1]]
                    * lIIllllIII.IIIIIllIII[lIIllllIII.history[-1]]
                )
            ) / (lIIllllIII.IIIIllIllllIlIIlIl + 1)
            lIIllllIII.IIIIllIllllIlIIlIl += 1
    def llllIllIIIlIIl(lIIllllIII, llllIIllIIII: Player) -> Action:
        if not lIIllllIII.history:
            return lIlIlIllIlIll
        lIIllllIII.IlIllIIIIllllllIlI(llllIIllIIII)
        if lIIllllIII.lIlllIIIllIIIII in [1, 2]:
            return lIlIlIllIlIll
        llIlIIIlIIIIlllIlII = compute_final_score(zip(lIIllllIII.history, llllIIllIIII.history))
        if (llIlIIIlIIIIlllIlII[0] / ((len(lIIllllIII.history)) + 1)) >= 2.25:
            lIlIlllIlIllIlllll = (
                (
                    0.95
                    - (
                        (
                            (lIIllllIII.IllIlIIIlIIIlIlI)
                            + (lIIllllIII.IIIIIllIllIllll)
                            - 5
                        )
                        / 15
                    )
                )
                + (1 / (((len(lIIllllIII.history)) + 1) ** 2))
                - (lIIllllIII.IIIIIllIII[llllIIllIIII.history[-1]] / 4)
            )
            if lIIllllIII._random.random() <= lIlIlllIlIllIlllll:
                return lIlIlIllIlIll
            lIIllllIII.lIlllIIIllIIIII = 1
            return lllllIIlIIIlII
        if (llIlIIIlIIIIlllIlII[0] / ((len(lIIllllIII.history)) + 1)) >= 1.75:
            lIlIlllIlIllIlllll = (
                (
                    0.25
                    + ((llllIIllIIII.cooperations + 1) / ((len(lIIllllIII.history)) + 1))
                )
                - (lIIllllIII.IIIlIIllIllIllI * 0.25)
                + ((llIlIIIlIIIIlllIlII[0] - llIlIIIlIIIIlllIlII[1]) / 100)
                + (4 / ((len(lIIllllIII.history)) + 1))
            )
            if lIIllllIII._random.random() <= lIlIlllIlIllIlllll:
                return lIlIlIllIlIll
            return lllllIIlIIIlII
        return llllIIllIIII.history[-1]