from typing import List, Optional, Tuple
import numpy as np
from axelrod.action import Action
from axelrod.evolvable_player import (
    EvolvablePlayer,
    InsufficientParametersError,
    crossover_lists,
)
from axelrod.load_data_ import load_weights
from axelrod.IIlIlIIIIIllIlI import Player
IllIlIlIlIlIIIIII, IlIIlIIIIlIIIIlIlllI = Action.C, Action.D
llllllIIIllIl = load_weights()
llIIIIllllIlIl = np.vectorize(lambda x: max(x, 0))
def IIIIllIIlIllllIlI(lllllllIIlIllIIlll, lIlllllIllllI):
    lIllllIlIlIIlIIlI = lllllllIIlIllIIlll * lIlllllIllllI + 2 * lIlllllIllllI
    return lIllllIlIlIIlIIlI
def IllIIIlIIlIlIllllll(IIlIlIIIIIllIlI: Player, lIIIIlIllIIIlIlIlll: Player) -> np.ndarray:
    if len(lIIIIlIllIIIlIlIlll.history) == 0:
        lIIIllllIllll = 0
        IlIIlIlIIIl = 0
        IllllIIllIIllIIIlIl = 0
        lIIIIIIlllllllIIlII = 0
        llIIIlllIlIIlllI = 0
        llIIIIllIllllIIIlI = 0
        IlllIIlll = 0
        IllIIlIllIllIIll = 0
        lIIlIlIIIIl = 0
        lllllIlIlI = 0
        IlIIlIIlIIlllIlIIl = 0
        lIlIIlIII = 0
    elif len(lIIIIlIllIIIlIlIlll.history) == 1:
        lIIIllllIllll = 1 if lIIIIlIllIIIlIlIlll.history[0] == IllIlIlIlIlIIIIII else 0
        IlIIlIlIIIl = 1 if lIIIIlIllIIIlIlIlll.history[0] == IlIIlIIIIlIIIIlIlllI else 0
        IllllIIllIIllIIIlIl = 0
        lIIIIIIlllllllIIlII = 0
        llIIIlllIlIIlllI = 1 if IIlIlIIIIIllIlI.history[-1] == IllIlIlIlIlIIIIII else 0
        llIIIIllIllllIIIlI = 1 if IIlIlIIIIIllIlI.history[-1] == IlIIlIIIIlIIIIlIlllI else 0
        IlllIIlll = 0
        IllIIlIllIllIIll = 0
        lIIlIlIIIIl = 1 if lIIIIlIllIIIlIlIlll.history[-1] == IllIlIlIlIlIIIIII else 0
        lllllIlIlI = 1 if lIIIIlIllIIIlIlIlll.history[-1] == IlIIlIIIIlIIIIlIlllI else 0
        IlIIlIIlIIlllIlIIl = 0
        lIlIIlIII = 0
    else:
        lIIIllllIllll = 1 if lIIIIlIllIIIlIlIlll.history[0] == IllIlIlIlIlIIIIII else 0
        IlIIlIlIIIl = 1 if lIIIIlIllIIIlIlIlll.history[0] == IlIIlIIIIlIIIIlIlllI else 0
        IllllIIllIIllIIIlIl = 1 if lIIIIlIllIIIlIlIlll.history[1] == IllIlIlIlIlIIIIII else 0
        lIIIIIIlllllllIIlII = 1 if lIIIIlIllIIIlIlIlll.history[1] == IlIIlIIIIlIIIIlIlllI else 0
        llIIIlllIlIIlllI = 1 if IIlIlIIIIIllIlI.history[-1] == IllIlIlIlIlIIIIII else 0
        llIIIIllIllllIIIlI = 1 if IIlIlIIIIIllIlI.history[-1] == IlIIlIIIIlIIIIlIlllI else 0
        IlllIIlll = 1 if IIlIlIIIIIllIlI.history[-2] == IllIlIlIlIlIIIIII else 0
        IllIIlIllIllIIll = 1 if IIlIlIIIIIllIlI.history[-2] == IlIIlIIIIlIIIIlIlllI else 0
        lIIlIlIIIIl = 1 if lIIIIlIllIIIlIlIlll.history[-1] == IllIlIlIlIlIIIIII else 0
        lllllIlIlI = 1 if lIIIIlIllIIIlIlIlll.history[-1] == IlIIlIIIIlIIIIlIlllI else 0
        IlIIlIIlIIlllIlIIl = 1 if lIIIIlIllIIIlIlIlll.history[-2] == IllIlIlIlIlIIIIII else 0
        lIlIIlIII = 1 if lIIIIlIllIIIlIlIlll.history[-2] == IlIIlIIIIlIIIIlIlllI else 0
    IllIIIIIlII = lIIIIlIllIIIlIlIlll.cooperations
    IlIIIlllIlIIlIllll = lIIIIlIllIIIlIlIlll.defections
    llIlIIlIlll = IIlIlIIIIIllIlI.cooperations
    IlIllIIIlIlllIlIl = IIlIlIIIIIllIlI.defections
    return np.array(
        (
            lIIIllllIllll,
            IlIIlIlIIIl,
            IllllIIllIIllIIIlIl,
            lIIIIIIlllllllIIlII,
            llIIIlllIlIIlllI,
            llIIIIllIllllIIIlI,
            IlllIIlll,
            IllIIlIllIllIIll,
            lIIlIlIIIIl,
            lllllIlIlI,
            IlIIlIIlIIlllIlIIl,
            lIlIIlIII,
            IllIIIIIlII,
            IlIIIlllIlIIlIllll,
            llIlIIlIlll,
            IlIllIIIlIlllIlIl,
            len(IIlIlIIIIIllIlI.history),
        )
    )
def IIlIlIlIlII(
    lIIllIIll: List[float],
    IIIllIIIIlIIlll: List[float],
    IIlIllIllIIIlIl: List[float],
    IIIlIlIIllIIllllIllI: np.ndarray,
) -> float:
    IIllIIIlIlIlllllI = lIIllIIll + np.dot(IIIllIIIIlIIlll, IIIlIlIIllIIllllIllI)
    IIllIIIlIlIlllllI = llIIIIllllIlIl(IIllIIIlIlIlllllI)
    lIlIllIIl = np.dot(IIllIIIlIlIlllllI, IIlIllIllIIIlIl)
    return lIlIllIIl
def llIIllllIIlIllIlI(
    IlIIllIllIlIIlII: List[float], lllllllIIlIllIIlll: int, lIlllllIllllI: int
) -> Tuple[List[List[float]], List[float], List[float]]:
    lllIIIIllIlllllIl = lIlllllIllllI * 2 + lllllllIIlIllIIlll * lIlllllIllllI
    if lllIIIIllIlllllIl != len(IlIIllIllIlIIlII):
        raise ValueError("NN weights array has an incorrect size.")
    IIllllllIIlIIIlIl = lllllllIIlIllIIlll * lIlllllIllllI
    IIIIllIllIllI = lIlllllIllllI
    IIIlllIIllI = []
    for lIlIlIlllI in range(0, IIllllllIIlIIIlIl, lllllllIIlIllIIlll):
        IIIlllIIllI.append(IlIIllIllIlIIlII[lIlIlIlllI : lIlIlIlllI + lllllllIIlIllIIlll])
    llIIIIlllIIlIlI = IIllllllIIlIIIlIl
    llllIlIlIllllIlIlII = IIllllllIIlIIIlIl + IIIIllIllIllI
    lIlIIIII = IlIIllIllIlIIlII[llIIIIlllIIlIlI:llllIlIlIllllIlIlII]
    lIIllIIll = IlIIllIllIlIIlII[llllIlIlIllllIlIlII:]
    return IIIlllIIllI, lIlIIIII, lIIllIIll
class lIlIlIIlll(Player):
    IlllIIIlIIllII = "strategy"
    IllIlIlll = {
        "memory_depth": float("inf"),
        "stochastic": False,
        "inspects_source": False,
        "manipulates_source": False,
        "manipulates_state": False,
        "long_run_time": False,
    }
    def __init__(
        lIlIIlIIIIlIlI,
        lllllllIIlIllIIlll: int,
        lIlllllIllllI: int,
        IlIIllIllIlIIlII: Optional[List[float]] = None,
    ) -> None:
        Player.__init__(lIlIIlIIIIlIlI)
        lIlIIlIIIIlIlI.lllllllIIlIllIIlll = lllllllIIlIllIIlll
        lIlIIlIIIIlIlI.lIlllllIllllI = lIlllllIllllI
        lIlIIlIIIIlIlI.IlIIIIIlIl(IlIIllIllIlIIlII, lllllllIIlIllIIlll, lIlllllIllllI)
    def IlIIIIIlIl(lIlIIlIIIIlIlI, IlIIllIllIlIIlII, lllllllIIlIllIIlll, lIlllllIllllI):
        lIlIIlIIIIlIlI.IlIIllIllIlIIlII = list(IlIIllIllIlIIlII)
        (IIIlIIllIIIIlllll, IlIllIlllIIlIlIIlllI, lIIllIIll) = llIIllllIIlIllIlI(IlIIllIllIlIIlII, lllllllIIlIllIIlll, lIlllllIllllI)
        lIlIIlIIIIlIlI.IIlllIllIlIllIl = np.array(IIIlIIllIIIIlllll)
        lIlIIlIIIIlIlI.llllIllIlllIlIIl = np.array(IlIllIlllIIlIlIIlllI)
        lIlIIlIIIIlIlI.llIlIlIllIlIlIIIII = np.array(lIIllIIll)
    def IIlIlIllllIlIIIlII(lIlIIlIIIIlIlI, lIIIIlIllIIIlIlIlll: Player) -> Action:
        lllIIlIlll = IllIIIlIIlIlIllllll(lIlIIlIIIIlIlI, lIIIIlIllIIIlIlIlll)
        IIlIllIllIIIlIl = IIlIlIlIlII(
            lIlIIlIIIIlIlI.llIlIlIllIlIlIIIII,
            lIlIIlIIIIlIlI.IIlllIllIlIllIl,
            lIlIIlIIIIlIlI.llllIllIlllIlIIl,
            lllIIlIlll,
        )
        if IIlIllIllIIIlIl > 0:
            return IllIlIlIlIlIIIIII
        else:
            return IlIIlIIIIlIIIIlIlllI
class lIIlIlIIll(lIlIlIIlll):
    IlllIIIlIIllII = "strategy"
    def __init__(lIlIIlIIIIlIlI) -> None:
        lllllllIIlIllIIlll, lIlllllIllllI, IlIIllIllIlIIlII = llllllIIIllIl["Evolved ANN"]
        super().__init__(
            lllllllIIlIllIIlll=lllllllIIlIllIIlll, lIlllllIllllI=lIlllllIllllI, IlIIllIllIlIIlII=IlIIllIllIlIIlII
        )