Esempio n. 1
0
    def test_is_cheater(self):
        """A test that verifies if the is_cheater function works correctly"""
        known_cheaters = [axelrod.Darwin,
                          axelrod.Geller,
                          axelrod.GellerCooperator,
                          axelrod.GellerDefector,
                          axelrod.MindBender,
                          axelrod.MindController,
                          axelrod.MindWarper,
                          axelrod.MindReader]

        known_basic = [axelrod.Alternator,
                       axelrod.AntiTitForTat,
                       axelrod.Bully,
                       axelrod.Cooperator,
                       axelrod.Defector,
                       axelrod.GoByMajority,
                       axelrod.SuspiciousTitForTat,
                       axelrod.TitForTat,
                       axelrod.WinStayLoseShift]

        known_ordinary = [axelrod.AverageCopier,
                          axelrod.ForgivingTitForTat,
                          axelrod.GoByMajority20,
                          axelrod.GTFT,
                          axelrod.Grudger,
                          axelrod.Inverse,
                          axelrod.Random]

        for strategy in known_cheaters:
            self.assertTrue(axelrod.is_cheater(strategy()), msg=strategy)
            self.assertFalse(axelrod.is_basic(strategy()), msg=strategy)

        for strategy in known_basic:
            self.assertTrue(axelrod.is_basic(strategy()), msg=strategy)
            self.assertFalse(axelrod.is_cheater(strategy()), msg=strategy)

        for strategy in known_ordinary:
            self.assertFalse(axelrod.is_basic(strategy()), msg=strategy)
            self.assertFalse(axelrod.is_cheater(strategy()), msg=strategy)
Esempio n. 2
0
from axelrod import Player, is_cheater
from ._strategies import strategies
from .hunter import DefectorHunter, AlternatorHunter, RandomHunter, MathConstantHunter


# Needs to be computed manually to prevent circular dependency
ordinary_strategies = [s for s in strategies if not is_cheater(s)]


class MetaPlayer(Player):
    """A generic player that has its own team of players."""

    team = []
    classifier = {
        'memory_depth': float('inf'),  # Long memory
        'stochastic': False,
        'inspects_source': False,
        'manipulates_source': False,
        'manipulates_state': False
    }

    def __init__(self):

        super(MetaPlayer, self).__init__()

        # Make sure we don't use any meta players to avoid infinite recursion.
        self.team = [t for t in self.team if not issubclass(t, MetaPlayer)]
        self.nteam = len(self.team)

        # Initiate all the player in out team.
        self.team = [t() for t in self.team]