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
IllllllI, IIIIlIlllIllIlIIIIl = Action.C, Action.D
class lllIIIIIIllIII(Player):
    IIIIIlIIlllIIl = "strategy"
    IIIlllIlIlIlI = {
        "memory_depth": float("inf"),
        "stochastic": False,
        "long_run_time": False,
        "inspects_source": False,
        "manipulates_source": False,
        "manipulates_state": False,
    }
    def __init__(IlIlIllllIllllI) -> None:
        super().__init__()
        IlIlIllllIllllI.IlllllIllllll = {
            (IllllllI, IllllllI, IllllllI): 0,
            (IllllllI, IllllllI, IIIIlIlllIllIlIIIIl): 0,
            (IllllllI, IIIIlIlllIllIlIIIIl, IllllllI): 0,
            (IllllllI, IIIIlIlllIllIlIIIIl, IIIIlIlllIllIlIIIIl): 0,
            (IIIIlIlllIllIlIIIIl, IllllllI, IllllllI): 0,
            (IIIIlIlllIllIlIIIIl, IllllllI, IIIIlIlllIllIlIIIIl): 0,
            (IIIIlIlllIllIlIIIIl, IIIIlIlllIllIlIIIIl, IllllllI): 0,
            (IIIIlIlllIllIlIIIIl, IIIIlIlllIllIlIIIIl, IIIIlIlllIllIlIIIIl): 0,
        }
        IlIlIllllIllllI.lIIlIlIIIII = list()  
    def llIllIllllIllllIlIl(IlIlIllllIllllI, lllIIIlIIlIlIlIlll, llllllIIlIIlI):
        IIllIIIIIIIlIl = len(IlIlIllllIllllI.history) + 1
        IlIlIllllIllllI.lIIlIlIIIII.append(lllIIIlIIlIlIlIlll)
        if IIllIIIIIIIlIl > 40:
            IllIIIlIIllIIllI = (llllllIIlIIlI + 0.5) / IIllIIIIIIIlIl
            if 0.45 < IllIIIlIIllIIllI < 0.55:
                return IIIIlIlllIllIlIIIIl
        return lllIIIlIIlIlIlIlll
    def IlIlIllIIlIlIIllll(IlIlIllllIllllI, lllIlllIl: Player) -> Action:
        IIllIIIIIIIlIl = len(IlIlIllllIllllI.history) + 1
        if IIllIIIIIIIlIl == 1:
            return IlIlIllllIllllI.llIllIllllIllllIlIl(IllllllI, 0)
        IIlllIIl = IlIlIllllIllllI.lIIlIlIIIII[-1]
        lIllIlllllIl, llIIlIllIlIlIlIlI, lIlllIlIlIIIIIIlIlI = IllllllI, IllllllI, IllllllI
        if IIllIIIIIIIlIl >= 3:
            lIllIlllllIl = lllIlllIl.history[-2]
            llIIlIllIlIlIlIlI = IlIlIllllIllllI.lIIlIlIIIII[-2]
        if IIllIIIIIIIlIl >= 4:
            lIlllIlIlIIIIIIlIlI = lllIlllIl.history[-3]
        if IIllIIIIIIIlIl >= 3:
            IlIlIllllIllllI.IlllllIllllll[
                (lIlllIlIlIIIIIIlIlI, llIIlIllIlIlIlIlI, lIllIlllllIl)
            ] += 1
        if (
            IlIlIllllIllllI.IlllllIllllll[(lIllIlllllIl, IIlllIIl, IllllllI)]
            >= IlIlIllllIllllI.IlllllIllllll[(lIllIlllllIl, IIlllIIl, IIIIlIlllIllIlIIIIl)]
        ):
            return IlIlIllllIllllI.llIllIllllIllllIlIl(IllllllI, lllIlllIl.defections)
        return IlIlIllllIllllI.llIllIllllIllllIlIl(IIIIlIlllIllIlIIIIl, lllIlllIl.defections)