from axelrod.action import Action

from axelrod.player import Player

C, D = Action.C, Action.D

class DoubleResurrection(Player):
    """
    A player starts by cooperating and defects if the number of rounds
    played by the player is greater than five and the last five rounds
    are cooperations.

    If the last five rounds were defections, the player cooperates.

    Names:

    - DoubleResurrection: [Eckhart2015]_
    """

    name = "DoubleResurrection"
    classifier = {
        "memory_depth": 5,
        "stochastic": False,
        "long_run_time": False,
        "inspects_source": False,
        "manipulates_source": False,
        "manipulates_state": False,
    }

    def strategy(self, opponent: Player) -> Action:
        """Actual strategy definition that determines player's action."""
        if len(self.history) == 0:
            return C
        if len(self.history) >= 5 and self.history[-5:] == [C, C, C, C, C]:
            return D
        elif len(self.history) >= 5 and self.history[-5:] == [D, D, D, D, D]:
            return C
        else:
            return opponent.history[-1]