Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

class is Action in action.py, removed alias Action=Actions #1054

Merged
merged 6 commits into from
Jul 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion axelrod/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from .version import __version__
from .load_data_ import load_pso_tables, load_weights
from . import graph
from .actions import Actions
from .action import Action
from .random_ import random_choice, seed, Pdf
from .plot import Plot
from .game import DefaultGame, Game
Expand Down
4 changes: 2 additions & 2 deletions axelrod/_strategy_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
from functools import lru_cache

from axelrod.player import update_history
from axelrod.actions import Actions
from axelrod.action import Action
from axelrod.strategies.cooperator import Cooperator
from axelrod.strategies.defector import Defector


C, D = Actions.C, Actions.D
C, D = Action.C, Action.D


def detect_cycle(history, min_size=1, max_size=12, offset=0):
Expand Down
21 changes: 9 additions & 12 deletions axelrod/actions.py → axelrod/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
* Cooperate
* Defect

Use Actions.C and Actions.D instead of 'C' or 'D'. For convenience you can use:
Uses the enumeration, Action.C and Action.D. For convenience you can use:

from Axelrod import Actions
C, D = Actions.C, Actions.D
from axelrod import Action
C, D = Action.C, Action.D
"""

from enum import Enum
Expand All @@ -18,7 +18,7 @@ def __init__(self, *args):
super(UnknownActionError, self).__init__(*args)


class Actions(Enum):
class Action(Enum):

C = 1
D = 0
Expand All @@ -34,10 +34,10 @@ def __str__(self):

def flip(self):
"""Returns the opposite Action. """
if self == Actions.C:
return Actions.D
if self == Actions.D:
return Actions.C
if self == Action.C:
return Action.D
if self == Action.D:
return Action.C

@classmethod
def from_char(cls, character):
Expand All @@ -51,14 +51,11 @@ def from_char(cls, character):
else:
raise UnknownActionError('Character must be "C" or "D".')

# Type alias for actions.
Action = Actions


def str_to_actions(actions: str) -> tuple:
"""Takes a string like 'CCDD' and returns a tuple of the appropriate
actions."""
return tuple(Actions.from_char(element) for element in actions)
return tuple(Action.from_char(element) for element in actions)


def actions_to_str(actions: Iterable[Action]) -> str:
Expand Down
2 changes: 1 addition & 1 deletion axelrod/deterministic_cache.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from collections import UserDict
import pickle

from .actions import Action
from .action import Action
from .player import Player

from typing import List, Tuple
Expand Down
4 changes: 2 additions & 2 deletions axelrod/game.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from .actions import Action, Actions
from .action import Action
from typing import Tuple, Union

C, D = Actions.C, Actions.D
C, D = Action.C, Action.D

Score = Union[int, float]

Expand Down
8 changes: 4 additions & 4 deletions axelrod/interaction_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
import csv
import tqdm

from axelrod.actions import Actions, str_to_actions
from axelrod.action import Action, str_to_actions
from .game import Game


C, D = Actions.C, Actions.D
C, D = Action.C, Action.D


def compute_scores(interactions, game=None):
Expand Down Expand Up @@ -282,7 +282,7 @@ def string_to_interactions(string):
interactions = []
interactions_list = list(string)
while interactions_list:
p1action = Actions.from_char(interactions_list.pop(0))
p2action = Actions.from_char(interactions_list.pop(0))
p1action = Action.from_char(interactions_list.pop(0))
p2action = Action.from_char(interactions_list.pop(0))
interactions.append((p1action, p2action))
return interactions
4 changes: 2 additions & 2 deletions axelrod/match.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from math import ceil, log
import random

from axelrod.actions import Actions
from axelrod.action import Action
from axelrod.game import Game
from axelrod import DEFAULT_TURNS
import axelrod.interaction_utils as iu
from .deterministic_cache import DeterministicCache


C, D = Actions.C, Actions.D
C, D = Action.C, Action.D


def is_stochastic(players, noise):
Expand Down
4 changes: 2 additions & 2 deletions axelrod/mock_player.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from itertools import cycle

from axelrod.actions import Actions, Action
from axelrod.action import Action
from axelrod.player import Player

from typing import List

C, D = Actions.C, Actions.D
C, D = Action.C, Action.D


class MockPlayer(Player):
Expand Down
4 changes: 2 additions & 2 deletions axelrod/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

import numpy as np

from axelrod.actions import Actions
from axelrod.action import Action
from .game import DefaultGame

import types
from typing import Dict, Any

C, D = Actions.C, Actions.D
C, D = Action.C, Action.D


# Strategy classifiers
Expand Down
10 changes: 5 additions & 5 deletions axelrod/random_.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import random
import numpy
from axelrod.actions import Action, Actions
from axelrod.action import Action


def random_choice(p: float = 0.5) -> Action:
Expand All @@ -19,15 +19,15 @@ def random_choice(p: float = 0.5) -> Action:
axelrod.Action
"""
if p == 0:
return Actions.D
return Action.D

if p == 1:
return Actions.C
return Action.C

r = random.random()
if r < p:
return Actions.C
return Actions.D
return Action.C
return Action.D


def randrange(a: int, b: int) -> int:
Expand Down
4 changes: 2 additions & 2 deletions axelrod/result_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
from numpy import mean, nanmedian, std
import tqdm

from axelrod.actions import Actions, str_to_actions
from axelrod.action import Action, str_to_actions
import axelrod.interaction_utils as iu
from . import eigen
from .game import Game


C, D = Actions.C, Actions.D
C, D = Action.C, Action.D


def update_progress_bar(method):
Expand Down
4 changes: 2 additions & 2 deletions axelrod/strategies/adaptive.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from axelrod.actions import Actions, Action
from axelrod.action import Action
from axelrod.player import Player

from typing import List

C, D = Actions.C, Actions.D
C, D = Action.C, Action.D


class Adaptive(Player):
Expand Down
4 changes: 2 additions & 2 deletions axelrod/strategies/alternator.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from axelrod.actions import Action, Actions
from axelrod.action import Action
from axelrod.player import Player

C, D = Actions.C, Actions.D
C, D = Action.C, Action.D


class Alternator(Player):
Expand Down
4 changes: 2 additions & 2 deletions axelrod/strategies/ann.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import numpy as np

from axelrod.actions import Actions, Action
from axelrod.action import Action
from axelrod.player import Player
from axelrod.load_data_ import load_weights

from typing import List, Tuple

C, D = Actions.C, Actions.D
C, D = Action.C, Action.D
nn_weights = load_weights()


Expand Down
4 changes: 2 additions & 2 deletions axelrod/strategies/apavlov.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from axelrod.actions import Actions, Action
from axelrod.action import Action
from axelrod.player import Player

C, D = Actions.C, Actions.D
C, D = Action.C, Action.D


class APavlov2006(Player):
Expand Down
4 changes: 2 additions & 2 deletions axelrod/strategies/appeaser.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from axelrod.actions import Action, Actions
from axelrod.action import Action
from axelrod.player import Player

C, D = Actions.C, Actions.D
C, D = Action.C, Action.D


class Appeaser(Player):
Expand Down
4 changes: 2 additions & 2 deletions axelrod/strategies/averagecopier.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from axelrod.actions import Actions, Action
from axelrod.action import Action
from axelrod.player import Player
from axelrod.random_ import random_choice

C, D = Actions.C, Actions.D
C, D = Action.C, Action.D


class AverageCopier(Player):
Expand Down
4 changes: 2 additions & 2 deletions axelrod/strategies/axelrod_first.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import random

from axelrod.actions import Actions, Action
from axelrod.action import Action
from axelrod.player import Player
from axelrod.random_ import random_choice
from axelrod.strategy_transformers import FinalTransformer
Expand All @@ -14,7 +14,7 @@

from typing import List, Dict, Tuple

C, D = Actions.C, Actions.D
C, D = Action.C, Action.D


class Davis(Player):
Expand Down
4 changes: 2 additions & 2 deletions axelrod/strategies/axelrod_second.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

import random

from axelrod.actions import Actions, Action
from axelrod.action import Action
from axelrod.player import Player
from axelrod.random_ import random_choice

C, D = Actions.C, Actions.D
C, D = Action.C, Action.D


class Champion(Player):
Expand Down
4 changes: 2 additions & 2 deletions axelrod/strategies/backstabber.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from axelrod.actions import Action, Actions
from axelrod.action import Action
from axelrod.player import Player
from axelrod.strategy_transformers import FinalTransformer

C, D = Actions.C, Actions.D
C, D = Action.C, Action.D


@FinalTransformer((D, D), name_prefix=None) # End with two defections
Expand Down
4 changes: 2 additions & 2 deletions axelrod/strategies/better_and_better.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from axelrod.actions import Action, Actions
from axelrod.action import Action
from axelrod.player import Player
from axelrod.random_ import random_choice

C, D = Actions.C, Actions.D
C, D = Action.C, Action.D


class BetterAndBetter(Player):
Expand Down
4 changes: 2 additions & 2 deletions axelrod/strategies/calculator.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from axelrod.actions import Action, Actions
from axelrod.action import Action
from axelrod.player import Player
from .axelrod_first import Joss
from axelrod._strategy_utils import detect_cycle

C, D = Actions.C, Actions.D
C, D = Action.C, Action.D


class Calculator(Player):
Expand Down
4 changes: 2 additions & 2 deletions axelrod/strategies/cooperator.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from axelrod.actions import Action, Actions
from axelrod.action import Action
from axelrod.player import Player

C, D = Actions.C, Actions.D
C, D = Action.C, Action.D


class Cooperator(Player):
Expand Down
4 changes: 2 additions & 2 deletions axelrod/strategies/cycler.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import copy
import itertools

from axelrod.actions import Actions, Action, str_to_actions
from axelrod.action import Action, str_to_actions
from axelrod.player import Player

C, D = Actions.C, Actions.D
C, D = Action.C, Action.D


class AntiCycler(Player):
Expand Down
4 changes: 2 additions & 2 deletions axelrod/strategies/darwin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
indicated by their classifier). We do not recommend putting a lot of time in to
optimising it.
"""
from axelrod.actions import Action, Actions
from axelrod.action import Action
from axelrod.player import Player

C, D = Actions.C, Actions.D
C, D = Action.C, Action.D


class Darwin(Player):
Expand Down
Loading