How to use the axelrod.action.Action.C 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 / axelrod / compute_finite_state_machine_memory.py View on Github external
from axelrod.action import Action
from collections import defaultdict, namedtuple
from typing import DefaultDict, Iterator, Dict, Tuple, Set, List

C, D = Action.C, Action.D

Transition = namedtuple(
    "Transition", ["state", "last_opponent_action", "next_state", "next_action"]
)
TransitionDict = Dict[Tuple[int, Action], Tuple[int, Action]]


class Memit(object):
    """
    Memit = unit of memory.

    This represents the amount of memory that we gain with each new piece of
    history.  It includes a state, our_response that we make on our way into that
    state (in_act), and the opponent's action that makes us move out of that state
    (out_act).
github Axelrod-Python / Axelrod / axelrod / strategies / punisher.py View on Github external
from typing import List

from axelrod.action import Action
from axelrod.player import Player

C, D = Action.C, Action.D


class Punisher(Player):
    """
    A player starts by cooperating however will defect if at any point the
    opponent has defected, but forgets after meme_length matches, with
    1<=mem_length<=20 proportional to the amount of time the opponent has
    played D, punishing that player for playing D too often.

    Names:

    - Punisher: Original name by Geraint Palmer
    """

    name = "Punisher"
    classifier = {
github Axelrod-Python / Axelrod / axelrod / strategies / doubler.py View on Github external
from axelrod.action import Action
from axelrod.player import Player

C, D = Action.C, Action.D


class Doubler(Player):
    """
    Cooperates except when the opponent has defected and
    the opponent's cooperation count is less than twice their defection count.

    Names:

    - Doubler: [Prison1998]_
    """

    name = "Doubler"
    classifier = {
        "stochastic": False,
        "memory_depth": float("inf"),
github Axelrod-Python / Axelrod / axelrod / game.py View on Github external
from .action import Action
from typing import Tuple, Union

C, D = Action.C, Action.D

Score = Union[int, float]


class Game(object):
    """A class to hold the game matrix and to score a game accordingly."""

    def __init__(self, r: Score=3, s: Score=0, t: Score=5, p: Score=1) -> None:
        self.scores = {
            (C, C): (r, r),
            (D, D): (p, p),
            (C, D): (s, t),
            (D, C): (t, s),
        }

    def RPST(self) -> Tuple[Score, Score, Score, Score]:
github Axelrod-Python / Axelrod / axelrod / strategies / geller.py View on Github external
"""
The player classes in this module do not obey standard rules of the IPD (as
indicated by their classifier). We do not recommend putting a lot of time in to
optimising them.
"""

from axelrod.action import Action
from axelrod.player import Player
from axelrod.random_ import random_choice
from axelrod._strategy_utils import inspect_strategy

C, D = Action.C, Action.D


class Geller(Player):
    """Observes what the player will do in the next round and adjust.

    If unable to do this: will play randomly.


    This code is inspired by Matthew Williams' talk
    "Cheating at rock-paper-scissors — meta-programming in Python"
    given at Django Weekend Cardiff in February 2014.

    His code is here: https://github.com/mattjw/rps_metaprogramming
    and there's some more info here: http://www.mattjw.net/2014/02/rps-metaprogramming/

    This code is **way** simpler than Matt's, as in this exercise we already
github Axelrod-Python / Axelrod / axelrod / strategies / appeaser.py View on Github external
from axelrod.action import Action
from axelrod.player import Player

C, D = Action.C, Action.D


class Appeaser(Player):
    """A player who tries to guess what the opponent wants.

    Switch the classifier every time the opponent plays D.
    Start with C, switch between C and D when opponent plays D.

    Names:

    - Appeaser: Original Name by Jochen Müller
    """

    name = "Appeaser"
    classifier = {
        "memory_depth": float("inf"),  # Depends on internal memory.