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.IlIlIllllllIllllI import Player
IlIIlIll, IIIIIlIllllII = Action.C, Action.D
IIllIlIllIllllIIIlI = load_weights()
lllIlllIllI = np.vectorize(lambda x: max(x, 0))
def llllIIIIIIIIIlI(IIlIllll, lllllllIlIIIIl):
    lllllIIIlIIIIIII = IIlIllll * lllllllIlIIIIl + 2 * lllllllIlIIIIl
    return lllllIIIlIIIIIII
def lllllllIlIIllIIllII(IlIlIllllllIllllI: Player, llllllIlllI: Player) -> np.ndarray:
    if len(llllllIlllI.history) == 0:
        llllIlll = 0
        lIIIIlIl = 0
        lIlIIIllIlIlIIIIIII = 0
        llllIIIIlIlIIlIlIll = 0
        lIlllIlIlllllIIII = 0
        lIIlIlIlIIlI = 0
        lIlIIIlIIllIlIlIlIl = 0
        llIlIlIlIlIlll = 0
        IIIllIllIIlllIIlIl = 0
        llIIlIlIIIlIl = 0
        lIIlIIlIlIIllIlI = 0
        lllIllIlI = 0
    elif len(llllllIlllI.history) == 1:
        llllIlll = 1 if llllllIlllI.history[0] == IlIIlIll else 0
        lIIIIlIl = 1 if llllllIlllI.history[0] == IIIIIlIllllII else 0
        lIlIIIllIlIlIIIIIII = 0
        llllIIIIlIlIIlIlIll = 0
        lIlllIlIlllllIIII = 1 if IlIlIllllllIllllI.history[-1] == IlIIlIll else 0
        lIIlIlIlIIlI = 1 if IlIlIllllllIllllI.history[-1] == IIIIIlIllllII else 0
        lIlIIIlIIllIlIlIlIl = 0
        llIlIlIlIlIlll = 0
        IIIllIllIIlllIIlIl = 1 if llllllIlllI.history[-1] == IlIIlIll else 0
        llIIlIlIIIlIl = 1 if llllllIlllI.history[-1] == IIIIIlIllllII else 0
        lIIlIIlIlIIllIlI = 0
        lllIllIlI = 0
    else:
        llllIlll = 1 if llllllIlllI.history[0] == IlIIlIll else 0
        lIIIIlIl = 1 if llllllIlllI.history[0] == IIIIIlIllllII else 0
        lIlIIIllIlIlIIIIIII = 1 if llllllIlllI.history[1] == IlIIlIll else 0
        llllIIIIlIlIIlIlIll = 1 if llllllIlllI.history[1] == IIIIIlIllllII else 0
        lIlllIlIlllllIIII = 1 if IlIlIllllllIllllI.history[-1] == IlIIlIll else 0
        lIIlIlIlIIlI = 1 if IlIlIllllllIllllI.history[-1] == IIIIIlIllllII else 0
        lIlIIIlIIllIlIlIlIl = 1 if IlIlIllllllIllllI.history[-2] == IlIIlIll else 0
        llIlIlIlIlIlll = 1 if IlIlIllllllIllllI.history[-2] == IIIIIlIllllII else 0
        IIIllIllIIlllIIlIl = 1 if llllllIlllI.history[-1] == IlIIlIll else 0
        llIIlIlIIIlIl = 1 if llllllIlllI.history[-1] == IIIIIlIllllII else 0
        lIIlIIlIlIIllIlI = 1 if llllllIlllI.history[-2] == IlIIlIll else 0
        lllIllIlI = 1 if llllllIlllI.history[-2] == IIIIIlIllllII else 0
    lIIlIIlIIllIllI = llllllIlllI.cooperations
    lIlIIIII = llllllIlllI.defections
    lIlllIllIl = IlIlIllllllIllllI.cooperations
    IlIllllllIIlIIlllIIl = IlIlIllllllIllllI.defections
    return np.array(
        (
            llllIlll,
            lIIIIlIl,
            lIlIIIllIlIlIIIIIII,
            llllIIIIlIlIIlIlIll,
            lIlllIlIlllllIIII,
            lIIlIlIlIIlI,
            lIlIIIlIIllIlIlIlIl,
            llIlIlIlIlIlll,
            IIIllIllIIlllIIlIl,
            llIIlIlIIIlIl,
            lIIlIIlIlIIllIlI,
            lllIllIlI,
            lIIlIIlIIllIllI,
            lIlIIIII,
            lIlllIllIl,
            IlIllllllIIlIIlllIIl,
            len(IlIlIllllllIllllI.history),
        )
    )
def IIIllllllIlIIlIlII(
    lllllllllIlIlllIIl: List[float],
    lIlIllIIllI: List[float],
    lIIIlIIll: List[float],
    IlIlllIIlIlllllIlI: np.ndarray,
) -> float:
    lIIlllIlIIIlIllIII = lllllllllIlIlllIIl + np.dot(lIlIllIIllI, IlIlllIIlIlllllIlI)
    lIIlllIlIIIlIllIII = lllIlllIllI(lIIlllIlIIIlIllIII)
    lIlIIIIIIIlIIlIl = np.dot(lIIlllIlIIIlIllIII, lIIIlIIll)
    return lIlIIIIIIIlIIlIl
def llIIIlIIlIIllIlllll(
    lIlIlIIlI: List[float], IIlIllll: int, lllllllIlIIIIl: int
) -> Tuple[List[List[float]], List[float], List[float]]:
    llllllIIIllllIll = lllllllIlIIIIl * 2 + IIlIllll * lllllllIlIIIIl
    if llllllIIIllllIll != len(lIlIlIIlI):
        raise ValueError("NN weights array has an incorrect size.")
    IlIlllIIIlIlIlIII = IIlIllll * lllllllIlIIIIl
    lllllIIllIIll = lllllllIlIIIIl
    IIlIlIIIllllIlIlI = []
    for lIIIIllllI in range(0, IlIlllIIIlIlIlIII, IIlIllll):
        IIlIlIIIllllIlIlI.append(lIlIlIIlI[lIIIIllllI : lIIIIllllI + IIlIllll])
    lIIllllIIlIllIIlll = IlIlllIIIlIlIlIII
    llllIlIlllll = IlIlllIIIlIlIlIII + lllllIIllIIll
    IllIIIlIlII = lIlIlIIlI[lIIllllIIlIllIIlll:llllIlIlllll]
    lllllllllIlIlllIIl = lIlIlIIlI[llllIlIlllll:]
    return IIlIlIIIllllIlIlI, IllIIIlIlII, lllllllllIlIlllIIl
class IIlIlIIll(Player):
    llIIllII = "strategy"
    IIIlllllIllllIIIlI = {
        "memory_depth": float("inf"),
        "stochastic": False,
        "inspects_source": False,
        "manipulates_source": False,
        "manipulates_state": False,
        "long_run_time": False,
    }
    def __init__(
        IlllIllIlIl,
        IIlIllll: int,
        lllllllIlIIIIl: int,
        lIlIlIIlI: Optional[List[float]] = None,
    ) -> None:
        Player.__init__(IlllIllIlIl)
        IlllIllIlIl.IIlIllll = IIlIllll
        IlllIllIlIl.lllllllIlIIIIl = lllllllIlIIIIl
        IlllIllIlIl.IlllIlIIIlllllIIlII(lIlIlIIlI, IIlIllll, lllllllIlIIIIl)
    def IlllIlIIIlllllIIlII(IlllIllIlIl, lIlIlIIlI, IIlIllll, lllllllIlIIIIl):
        IlllIllIlIl.lIlIlIIlI = list(lIlIlIIlI)
        (lIIIIIllllIIl, llIIlllIllIlIIlIlI, lllllllllIlIlllIIl) = llIIIlIIlIIllIlllll(lIlIlIIlI, IIlIllll, lllllllIlIIIIl)
        IlllIllIlIl.lIIIllIlIIlIllIIllII = np.array(lIIIIIllllIIl)
        IlllIllIlIl.llIIlIllllllIllllIll = np.array(llIIlllIllIlIIlIlI)
        IlllIllIlIl.IIlllIIl = np.array(lllllllllIlIlllIIl)
    def lIIllIlllllII(IlllIllIlIl, llllllIlllI: Player) -> Action:
        llIlIIIIllIlllIIl = lllllllIlIIllIIllII(IlllIllIlIl, llllllIlllI)
        lIIIlIIll = IIIllllllIlIIlIlII(
            IlllIllIlIl.IIlllIIl,
            IlllIllIlIl.lIIIllIlIIlIllIIllII,
            IlllIllIlIl.llIIlIllllllIllllIll,
            llIlIIIIllIlllIIl,
        )
        if lIIIlIIll > 0:
            return IlIIlIll
        else:
            return IIIIIlIllllII