Skip to content

Commit b3efe69

Browse files
marcharperdrvinceknight
authored andcommitted
Change action sort order to match character sort order and update tests
1 parent 77b2a52 commit b3efe69

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

axelrod/action.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ def __init__(self, *args):
2121
@total_ordering
2222
class Action(Enum):
2323
"""Core actions in the Prisoner's Dilemma.
24-
24+
2525
There are only two possible actions, namely Cooperate or Defect,
2626
which are called C and D for convenience.
2727
"""
2828

29-
C = 1 # Cooperate
30-
D = 0 # Defect
29+
C = 0 # Cooperate
30+
D = 1 # Defect
3131

3232
def __lt__(self, other):
3333
return self.value < other.value
@@ -36,7 +36,7 @@ def __repr__(self):
3636
return self.name
3737

3838
def __str__(self):
39-
return repr(self)
39+
return self.name
4040

4141
def flip(self):
4242
"""Returns the opposite Action."""
@@ -48,7 +48,7 @@ def flip(self):
4848
@classmethod
4949
def from_char(cls, character):
5050
"""Converts a single character into an Action.
51-
51+
5252
Parameters
5353
----------
5454
character: a string of length one
@@ -91,7 +91,7 @@ def actions_to_str(actions: Iterable[Action]) -> str:
9191
9292
Example: (D, D, C) would be converted to 'DDC'
9393
94-
Paramteters
94+
Parameters
9595
-----------
9696
actions: iterable of Action
9797
@@ -100,4 +100,4 @@ def actions_to_str(actions: Iterable[Action]) -> str:
100100
str
101101
A string of 'C's and 'D's.
102102
"""
103-
return "".join(map(repr, actions))
103+
return "".join(map(str, actions))

axelrod/tests/unit/test_actions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
class TestAction(unittest.TestCase):
1010
def test_lt(self):
11-
self.assertLess(D, C)
11+
self.assertLess(C, D)
1212

1313
def test_repr(self):
1414
self.assertEqual(repr(C), "C")

0 commit comments

Comments
 (0)