示例#1
0
    def test_obey_axelrod(self):
        """A test that verifies if the obey_axelrod 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.assertFalse(axelrod.obey_axelrod(strategy()), msg=strategy)

        for strategy in known_basic:
            self.assertTrue(axelrod.obey_axelrod(strategy()), msg=strategy)

        for strategy in known_ordinary:
            self.assertTrue(axelrod.obey_axelrod(strategy()), msg=strategy)
示例#2
0
    def test_obey_axelrod(self):
        """A test that verifies if the obey_axelrod 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.assertFalse(axelrod.obey_axelrod(strategy()), msg=strategy)

        for strategy in known_basic:
            self.assertTrue(axelrod.obey_axelrod(strategy()), msg=strategy)

        for strategy in known_ordinary:
            self.assertTrue(axelrod.obey_axelrod(strategy()), msg=strategy)
示例#3
0
def interactions_generator(player, opponents=None, repetitions=100, noise=0,
                           turns=200):
    if not opponents:
        opponents = [s() for s in axl.all_strategies if axl.obey_axelrod(s())
               and not s().classifier['long_run_time']]

    for opponent in opponents:
        match = axl.Match((player, opponent), turns, noise=noise)
        for rep in range(repetitions):
            match.play()
            yield (player.history, opponent.history)
示例#4
0
文件: knn_test.py 项目: tejastank/NN
def main():

    players = [
        s for s in axl.all_strategies
        if axl.obey_axelrod(s()) and not s().classifier['long_run_time']
    ]

    players.append(KNN)
    players = [s() for s in players]

    tournament = axl.Tournament(players=players, repetitions=60)
    results = tournament.play()

    plot = axl.Plot(results)
    plot.save_all_plots(prefix="knn/tournament")
def axelrod_strategies(cheaters=False, meta=False, transformer=None):
    """Obtains the list of strategies from Axelrod library."""

    s = [s for s in axelrod.all_strategies if axelrod.obey_axelrod(s())]
    if cheaters:
        s.extend(axelrod.cheating_strategies)
    if not meta:
        s = [
            t for t in s
            if not (t.__name__.startswith("Meta") or t.__name__.startswith(
                "NiceMeta") or t.__name__.startswith("NMW"))
        ]
    # Instantiate
    if transformer:
        s = [transformer(t)() for t in s]
    else:
        s = [t() for t in s]
    # Sort by name
    s.sort(key=str)
    return s
示例#6
0
文件: meta.py 项目: tscizzle/Axelrod
from axelrod import Actions, Player, obey_axelrod
from ._strategies import all_strategies
from .hunter import (
    DefectorHunter, AlternatorHunter, RandomHunter, MathConstantHunter,
    CycleHunter, EventualCycleHunter)
from .cooperator import Cooperator
from numpy.random import choice

# Needs to be computed manually to prevent circular dependency
ordinary_strategies = [s for s in all_strategies if obey_axelrod(s)]
C, D = Actions.C, Actions.D


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

    name = "Meta Player"
    team = [Cooperator]
    classifier = {
        'memory_depth': float('inf'),  # Long memory
        'stochastic': False,
        'makes_use_of': set(),
        'long_run_time': True,
        'inspects_source': False,
        'manipulates_source': False,
        'manipulates_state': False
    }

    def __init__(self):
        super(MetaPlayer, self).__init__()
示例#7
0
from axelrod import Actions, Player, init_args, obey_axelrod
from ._strategies import all_strategies
from .hunter import (
    AlternatorHunter,
    CooperatorHunter,
    CycleHunter,
    DefectorHunter,
    EventualCycleHunter,
    MathConstantHunter,
    RandomHunter,
)
from numpy.random import choice
from random import sample

# Needs to be computed manually to prevent circular dependency
ordinary_strategies = [s for s in all_strategies if obey_axelrod(s)]
C, D = Actions.C, Actions.D


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

    name = "Meta Player"
    classifier = {
        'memory_depth': float('inf'),  # Long memory
        'stochastic': True,
        'makes_use_of': set(),
        'long_run_time': True,
        'inspects_source': False,
        'manipulates_source': False,
        'manipulates_state': False
示例#8
0
        os.remove(output_filename)
    except:
        pass

    sample_match_outcomes_parallel(turns,
                                   repetitions,
                                   output_filename,
                                   noise=noise,
                                   processes=processes)

    output_filename = "/ssd/interactions-test.csv1"
    try:
        os.remove(output_filename)
    except:
        pass
    sample_match_outcomes_parallel(turns,
                                   10,
                                   output_filename,
                                   noise=noise,
                                   processes=processes)


if __name__ == "__main__":
    players = [
        s for s in axl.all_strategies
        if axl.obey_axelrod(s()) and not s().classifier['long_run_time']
    ]

    generate_data(repetitions=100)
    process_data()