Skip to content

Commit 094e839

Browse files
drvinceknightmarcharper
authored andcommitted
Tidying after PR comments.
- 'C'/'D' -> C/D - Adding type docstrings.
1 parent a827270 commit 094e839

File tree

2 files changed

+23
-22
lines changed

2 files changed

+23
-22
lines changed

axelrod/interaction_utils.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Functions to calculate results from interactions. Interactions are lists of the
33
form:
44
5-
[('C', 'D'), ('D', 'C'),...]
5+
[(C, D), (D, C),...]
66
77
This is used by both the Match class and the ResultSet class which analyse
88
interactions.
@@ -145,7 +145,7 @@ def compute_state_to_action_distribution(interactions):
145145
Implying that from a state of (C, D) (the first player having played C and
146146
the second playing D) the player in question then played C.
147147
148-
The following counter object, implies that the player in question was in
148+
The following counter object implies that the player in question was in
149149
state (C, D) for a total of 12 times, subsequently cooperating 4 times and
150150
defecting 8 times.
151151
@@ -167,8 +167,8 @@ def compute_state_to_action_distribution(interactions):
167167
if not interactions:
168168
return None
169169

170-
distributions = [Counter([(state, outcome[j]) for state, outcome in zip(interactions,
171-
interactions[1:])])
170+
distributions = [Counter([(state, outcome[j])
171+
for state, outcome in zip(interactions, interactions[1:])])
172172
for j in range(2)]
173173
return distributions
174174

@@ -180,13 +180,12 @@ def compute_normalised_state_to_action_distribution(interactions):
180180
181181
((C, D), C)
182182
183-
Implying that from a state of (C, D) (the first player having played C and
183+
implying that from a state of (C, D) (the first player having played C and
184184
the second playing D) the player in question then played C.
185185
186186
The following counter object, implies that the player in question was only
187-
ever in
188-
state (C, D), subsequently cooperating 1/3 of the time and
189-
defecting 2/3 times.
187+
ever in state (C, D), subsequently cooperating 1/3 of the time and defecting
188+
2/3 times.
190189
191190
Counter({((C, D), C): 0.333333, ((C, D), D): 0.66666667})
192191
@@ -197,11 +196,11 @@ def compute_normalised_state_to_action_distribution(interactions):
197196
this file.
198197
199198
Returns
200-
----------
199+
-------
201200
normalised_state_to_C_distributions : List of Counter Object
202201
List of Counter objects where the keys are the states and actions and
203-
the values the normalized counts.. The
204-
first/second Counter corresponds to the first/second player.
202+
the values the normalized counts. The first/second Counter corresponds
203+
to the first/second player.
205204
"""
206205
if not interactions:
207206
return None
@@ -210,22 +209,22 @@ def compute_normalised_state_to_action_distribution(interactions):
210209
normalized_distribution = []
211210
for player in range(2):
212211
counter = {}
213-
for state in [('C', 'C'), ('C', 'D'), ('D', 'C'), ('D', 'D')]:
214-
C_count = distribution[player].get((state, 'C'), 0)
215-
D_count = distribution[player].get((state, 'D'), 0)
212+
for state in [(C, C), (C, D), (D, C), (D, D)]:
213+
C_count = distribution[player].get((state, C), 0)
214+
D_count = distribution[player].get((state, D), 0)
216215
total = C_count + D_count
217216
if total > 0:
218217
if C_count > 0:
219-
counter[(state, 'C')] = C_count / (C_count + D_count)
218+
counter[(state, C)] = C_count / (C_count + D_count)
220219
if D_count > 0:
221-
counter[(state, 'D')] = D_count / (C_count + D_count)
220+
counter[(state, D)] = D_count / (C_count + D_count)
222221
normalized_distribution.append(Counter(counter))
223222
return normalized_distribution
224223

225224

226225
def sparkline(actions, c_symbol='█', d_symbol=' '):
227226
return ''.join([
228-
c_symbol if play == 'C' else d_symbol for play in actions])
227+
c_symbol if play == C else d_symbol for play in actions])
229228

230229

231230
def compute_sparklines(interactions, c_symbol='█', d_symbol=' '):

axelrod/result_set.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,9 @@ def _build_ranking(self):
340340
@update_progress_bar
341341
def _build_normalised_state_distribution(self):
342342
"""
343-
Returns
344-
----------
343+
Returns:
344+
--------
345+
norm : list
345346
346347
Normalised state distribution. A list of lists of counter objects:
347348
@@ -361,10 +362,11 @@ def _build_normalised_state_distribution(self):
361362
@update_progress_bar
362363
def _build_normalised_state_to_action_distribution(self):
363364
"""
364-
Returns
365-
----------
365+
Returns:
366+
--------
367+
norm : list
366368
367-
Normalised state distribution. A list of lists of counter objects:
369+
A list of lists of counter objects.
368370
369371
Dictionary where the keys are the states and the values are a
370372
normalized counts of the number of times that state goes to a given

0 commit comments

Comments
 (0)