How to use the axelrod.Action function in Axelrod

To help you get started, we’ve selected a few Axelrod examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Axelrod-Python / axelrod-dojo / tests / archetypes / test_gambler.py View on Github external
import axelrod as axl
import random
import unittest

from axelrod_dojo import GamblerParams
from axelrod.strategies.lookerup import Plays
from axelrod.strategies.lookerup import create_lookup_table_keys

C, D = axl.Action.C, axl.Action.D


class TestGamblerParams(unittest.TestCase):
    def test_init(self):
        plays = 2
        op_plays = 2
        op_start_plays = 1

        gambler_params = GamblerParams(plays=plays, op_plays=op_plays,
                                       op_start_plays=op_start_plays)

        self.assertEqual(gambler_params.PlayerClass, axl.Gambler)
        self.assertEqual(gambler_params.plays, plays)
        self.assertEqual(gambler_params.op_plays, op_plays)
        self.assertEqual(gambler_params.op_start_plays, op_start_plays)
github Axelrod-Python / axelrod-dojo / tests / archetypes / test_cycler.py View on Github external
import unittest

import axelrod as axl
from axelrod_dojo.archetypes.cycler import CyclerParams

C, D = axl.Action


class TestCyclerParams(unittest.TestCase):
    def setUp(self):
        self.instance = None

    # Basic creation methods setting the correct params

    def test_creation_seqLen(self):
        axl.seed(0)
        test_length = 10
        self.instance = CyclerParams(sequence_length=test_length)
        self.assertEqual(self.instance.sequence, [C, D, D, C, D, D, D, D, D, D])
        self.assertEqual(self.instance.sequence_length, test_length)
        self.assertEqual(len(self.instance.sequence), test_length)
github Axelrod-Python / Axelrod / axelrod / test_pickling.py View on Github external
import unittest
import pickle
import axelrod as axl
from axelrod.strategy_transformers import FlipTransformer
from axelrod.my_t import transformed, TestFlip


C, D = axl.Action.C, axl.Action.D


class TestPickle(unittest.TestCase):

    def assert_original_acts_same_as_pickled(self, player, turns=100):
        copy = pickle.loads(pickle.dumps(player))
        opponent_1 = axl.CyclerCCCDCD()
        opponent_2 = axl.CyclerCCCDCD()
        axl.seed(0)
        match_1 = axl.Match((player, opponent_1), turns=turns)
        result_1 = match_1.play()

        axl.seed(0)
        match_2 = axl.Match((copy, opponent_2), turns=turns)
        result_2 = match_2.play()
github Axelrod-Python / axelrod-dojo / tests / integration / test_gambler.py View on Github external
import unittest
import tempfile
import csv

import axelrod as axl
import axelrod_dojo as dojo

C, D = axl.Action.C, axl.Action.D


class TestFSMPopulation(unittest.TestCase):
    name = "score"
    turns = 10
    noise = 0
    repetitions = 5
    num_states = 2
    opponents = [s() for s in axl.demo_strategies]
    size = 10

    objective = dojo.prepare_objective(name=name,
                                       turns=turns,
                                       noise=noise,
                                       repetitions=repetitions)
github Axelrod-Python / axelrod-dojo / src / axelrod_dojo / archetypes / gambler.py View on Github external
import random
import numpy as np

from axelrod import Action, Gambler
from axelrod.strategies.lookerup import create_lookup_table_keys
from axelrod_dojo.utils import Params

from axelrod.strategies.lookerup import Plays


C, D = Action.C, Action.D


class GamblerParams(Params):
    """
    A class for a Gambler archetype used to train Gambler strategies using 
    various optimization algorithms. 
    
    More details for the Gambler player can be found in the axelrod 
    documentation: http://axelrod.readthedocs.io/ 
    
    Parameters
    ----------
    plays : integer
        The number of player's last moves to remember
    op_plays : integer
        The number of opponent's last moves to remember
github Axelrod-Python / axelrod-dojo / bin / lookup_evolve.py View on Github external
--plays PLAYS               Number of recent plays in the lookup table [default: 2]
    --op_plays OP_PLAYS         Number of recent plays in the lookup table [default: 2]
    --op_start_plays OP_START_PLAYS   Number of opponent starting plays in the lookup table [default: 2]
"""

import random

from docopt import docopt
import numpy as np

from axelrod import Action
from axelrod.action import actions_to_str
from axelrod.strategies.lookerup import LookerUp, create_lookup_table_keys
from axelrod_dojo import Params, Population, prepare_objective

C, D = Action.C, Action.D


class LookerUpParams(Params):

    def __init__(self, plays, op_plays, op_start_plays, initial_actions=None,
                 mutation_probability=None, table=None):
        self.PlayerClass = LookerUp
        self.plays = plays
        self.op_plays = op_plays
        self.op_start_plays = op_start_plays

        if not initial_actions:
            table_depth = max(self.plays, self.op_plays, self.op_start_plays)
            initial_actions = [random.choice([C, D]) for _ in range(table_depth)]
        self.initial_actions = initial_actions
github Axelrod-Python / axelrod-dojo / bin / ann_evolve.py View on Github external
--noise NOISE               Match noise [default: 0.00]
    --nmoran NMORAN             Moran Population Size, if Moran objective [default: 4]
    --features FEATURES         Number of ANN features [default: 17]
    --hidden HIDDEN             Number of hidden nodes [default: 10]
    --mu_distance DISTANCE      Delta max for weights updates [default: 10]
"""

import random

from docopt import docopt

from axelrod import Action
from axelrod.strategies.ann import ANN
from axelrod_dojo import Params, Population, prepare_objective

C, D = Action.C, Action.D


## Todo: mutation decay
# if decay:
#     mutation_probability *= 0.995
#     mutation_distance *= 0.995


def num_weights(num_features, num_hidden):
    size = num_features * num_hidden + 2 * num_hidden
    return size


class ANNParams(Params):

    def __init__(self, num_features, num_hidden, mutation_probability=0.1,
github Axelrod-Python / axelrod-dojo / src / axelrod_dojo / archetypes / hmm.py View on Github external
import random
from random import randrange

import numpy as np
from axelrod.strategies.hmm import HMMPlayer
from axelrod import Action
from axelrod_dojo.utils import Params

C, D = Action.C, Action.D


def copy_lists(rows):
    new_rows = list(map(list, rows))
    return new_rows

def random_vector(size):
    """Create a random vector of values in [0, 1] that sums to 1."""
    vector = []
    s = 1
    for _ in range(size - 1):
        r = s * random.random()
        vector.append(r)
        s -= r
    vector.append(s)
    return vector