Skip to content

Commit ae35da3

Browse files
Add docstrings (#1377)
* Cherry-pick merge * Ran black on all files after cherry-pick * Redoing unmerged changes: Added docstrings to files which had not merged. Simplified chained comparisons in SelfSteem Changed set(["game"]) to {"game"} to reduce function call Deleted duplicate TestIdentityDualTransformer class * Resolving merge conflicts * Resolve merge issues Modified .isort.cfg to resolve merge issues. * Resolve merge issues 1. Modified max.size in strategy_lists because len(axl.short_run_time_strategies) < len(axl.strategies) in property.py 2. Added classifiers_list method, in test_filtering.py, and used it in test_boolean_filtering. * Fix isort configuration file. * Run black and isort. Co-authored-by: Vince Knight <[email protected]>
1 parent 2b07a83 commit ae35da3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+191
-74
lines changed

axelrod/strategies/_filters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class ExampleStrategy(Player):
5252
def passes_in_list_filter(player, classifier_key, value):
5353
"""
5454
Tests whether a given list of values exist in the list returned from the
55-
given players's classifier dict for the given classifier_key.
55+
given player's classifier dict for the given classifier_key.
5656
5757
e.g.
5858

axelrod/strategies/adaptive.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def score_last_round(self, opponent: Player):
4242
self.scores[last_round[0]] += scores[0]
4343

4444
def strategy(self, opponent: Player) -> Action:
45+
"""Actual strategy definition that determines player's action."""
4546
# Update scores from the last play
4647
self.score_last_round(opponent)
4748
# Begin by playing the sequence C,C,C,C,C,C,D,D,D,D,D

axelrod/strategies/adaptor.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def __init__(
4545
self.s = 0.0
4646

4747
def strategy(self, opponent: Player) -> Action:
48+
"""Actual strategy definition that determines player's action."""
4849
if self.history:
4950
# Update internal state from the last play
5051
last_round = (self.history[-1], opponent.history[-1])

axelrod/strategies/alternator.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class Alternator(Player):
2525
}
2626

2727
def strategy(self, opponent: Player) -> Action:
28+
"""Actual strategy definition that determines player's action."""
2829
if len(self.history) == 0:
2930
return C
3031
if self.history[-1] == C:

axelrod/strategies/ann.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ def _process_weights(self, weights, num_features, num_hidden):
211211
self.bias_weights = np.array(bias)
212212

213213
def strategy(self, opponent: Player) -> Action:
214+
"""Actual strategy definition that determines player's action."""
214215
features = compute_features(self, opponent)
215216
output = activate(
216217
self.bias_weights,

axelrod/strategies/apavlov.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def __init__(self) -> None:
3333
self.opponent_class = None # type: Optional[str]
3434

3535
def strategy(self, opponent: Player) -> Action:
36+
"""Actual strategy definition that determines player's action."""
3637
# TFT for six rounds
3738
if len(self.history) < 6:
3839
return D if opponent.history[-1:] == [D] else C
@@ -96,6 +97,7 @@ def __init__(self) -> None:
9697
self.opponent_class = None # type: Optional[str]
9798

9899
def strategy(self, opponent: Player) -> Action:
100+
"""Actual strategy definition that determines player's action."""
99101
# TFT for six rounds
100102
if len(self.history) < 6:
101103
return D if opponent.history[-1:] == [D] else C

axelrod/strategies/appeaser.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class Appeaser(Player):
2626
}
2727

2828
def strategy(self, opponent: Player) -> Action:
29+
"""Actual strategy definition that determines player's action."""
2930
if not len(opponent.history):
3031
return C
3132
else:

axelrod/strategies/averagecopier.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class AverageCopier(Player):
2525
}
2626

2727
def strategy(self, opponent: Player) -> Action:
28+
"""Actual strategy definition that determines player's action."""
2829
if len(opponent.history) == 0:
2930
# Randomly picks a strategy (not affected by history).
3031
return self._random.random_choice(0.5)
@@ -52,6 +53,7 @@ class NiceAverageCopier(Player):
5253
}
5354

5455
def strategy(self, opponent: Player) -> Action:
56+
"""Actual strategy definition that determines player's action."""
5557
if len(opponent.history) == 0:
5658
return C
5759
p = opponent.cooperations / len(opponent.history)

axelrod/strategies/axelrod_first.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ def __init__(self) -> None:
245245
self.number_opponent_cooperations_in_response_to_D = 0
246246

247247
def strategy(self, opponent: Player) -> Action:
248+
"""Actual strategy definition that determines player's action."""
248249
round_number = len(self.history) + 1
249250

250251
if round_number == 1:
@@ -347,6 +348,7 @@ def _cooperation_probability(self) -> float:
347348
return max(self._start_coop_prob + slope * rounds, self._end_coop_prob)
348349

349350
def strategy(self, opponent: Player) -> Action:
351+
"""Actual strategy definition that determines player's action."""
350352
if not opponent.history:
351353
return C
352354
if opponent.history[-1] == D:
@@ -491,6 +493,7 @@ class FirstByGrofman(Player):
491493
}
492494

493495
def strategy(self, opponent: Player) -> Action:
496+
"""Actual strategy definition that determines player's action."""
494497
if len(self.history) == 0 or self.history[-1] == opponent.history[-1]:
495498
return C
496499
return self._random.random_choice(2 / 7)
@@ -630,6 +633,7 @@ def score_history(
630633
return a
631634

632635
def strategy(self, opponent: Player) -> Action:
636+
"""Actual strategy definition that determines player's action."""
633637
if len(self.history) == 0:
634638
return C
635639
if len(self.history) == 1:
@@ -713,6 +717,7 @@ def _decrease_retaliation_counter(self):
713717
self.is_retaliating = False
714718

715719
def strategy(self, opponent: Player) -> Action:
720+
"""Actual strategy definition that determines player's action."""
716721
if not opponent.history:
717722
return C
718723

@@ -773,6 +778,7 @@ def __init__(self) -> None:
773778
self._rounds_to_cooperate = 11
774779

775780
def strategy(self, opponent: Player) -> Action:
781+
"""Actual strategy definition that determines player's action."""
776782
if len(self.history) < self._rounds_to_cooperate:
777783
return C
778784
rounds = self._rounds_to_cooperate - 1
@@ -817,6 +823,7 @@ class FirstByAnonymous(Player):
817823
}
818824

819825
def strategy(self, opponent: Player) -> Action:
826+
"""Actual strategy definition that determines player's action."""
820827
r = self._random.uniform(3, 7) / 10
821828
return self._random.random_choice(r)
822829

@@ -872,6 +879,7 @@ def __init__(self, alpha: float = 0.05) -> None:
872879
self.opponent_is_random = False
873880

874881
def strategy(self, opponent: Player) -> Action:
882+
"""Actual strategy definition that determines player's action."""
875883
round_number = len(self.history) + 1
876884

877885
# First 4 moves
@@ -984,6 +992,7 @@ def _score_last_round(self, opponent: Player):
984992
self.opponent_score += scores[1]
985993

986994
def strategy(self, opponent: Player) -> Action:
995+
"""Actual strategy definition that determines player's action."""
987996
if not opponent.history:
988997
return C
989998

axelrod/strategies/axelrod_second.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class SecondByChampion(Player):
4141
}
4242

4343
def strategy(self, opponent: Player) -> Action:
44+
"""Actual strategy definition that determines player's action."""
4445
current_round = len(self.history)
4546
# Cooperate for the first 10 turns
4647
if current_round == 0:
@@ -84,6 +85,7 @@ class SecondByEatherley(Player):
8485
}
8586

8687
def strategy(self, opponent: Player) -> Action:
88+
"""Actual strategy definition that determines player's action."""
8789
# Cooperate on the first move
8890
if not len(opponent.history):
8991
return C
@@ -127,6 +129,7 @@ def __init__(self) -> None:
127129
self.is_TFT = False
128130

129131
def strategy(self, opponent: Player) -> Action:
132+
"""Actual strategy definition that determines player's action."""
130133
# Defect on the first move
131134
if not opponent.history:
132135
return D
@@ -180,6 +183,7 @@ def __init__(self) -> None:
180183
self.patsy = True
181184

182185
def strategy(self, opponent: Player) -> Action:
186+
"""Actual strategy definition that determines player's action."""
183187
# Defect on the first move
184188
if not self.history:
185189
return D
@@ -382,6 +386,7 @@ def update_state(self, opponent):
382386
self.one_turn_after_good_defection_ratio_count += 1
383387

384388
def strategy(self, opponent: Player) -> Action:
389+
"""Actual strategy definition that determines player's action."""
385390

386391
if not self.history:
387392
return C
@@ -467,6 +472,7 @@ class SecondByGrofman(Player):
467472
}
468473

469474
def strategy(self, opponent: Player) -> Action:
475+
"""Actual strategy definition that determines player's action."""
470476
# Cooperate on the first two moves
471477
if len(self.history) < 2:
472478
return C
@@ -539,6 +545,7 @@ def __init__(self):
539545
)
540546

541547
def strategy(self, opponent: Player) -> Action:
548+
"""Actual strategy definition that determines player's action."""
542549
# First update the response matrix.
543550
if len(self.history) >= 2:
544551
if self.history[-2] == D:
@@ -670,6 +677,7 @@ def try_return(self, to_return):
670677
return D
671678

672679
def strategy(self, opponent: Player) -> Action:
680+
"""Actual strategy definition that determines player's action."""
673681
turn = len(self.history) + 1
674682

675683
if turn == 1:
@@ -697,7 +705,7 @@ def strategy(self, opponent: Player) -> Action:
697705
self.mode = "Defect"
698706

699707
# Check for a random strategy
700-
if (coops >= 8 and coops <= 17) and self.cc_counts / coops < 0.7:
708+
if (8 <= coops <= 17) and self.cc_counts / coops < 0.7:
701709
self.mode = "Defect"
702710

703711
self.cd_counts, self.cc_counts = 0, 0
@@ -783,6 +791,7 @@ class SecondByCave(Player):
783791
}
784792

785793
def strategy(self, opponent: Player) -> Action:
794+
"""Actual strategy definition that determines player's action."""
786795
turn = len(self.history) + 1
787796
if turn == 1:
788797
return C
@@ -833,6 +842,7 @@ class SecondByWmAdams(Player):
833842
}
834843

835844
def strategy(self, opponent: Player) -> Action:
845+
"""Actual strategy definition that determines player's action."""
836846
if len(self.history) <= 1:
837847
return C
838848
number_defects = opponent.defections
@@ -889,6 +899,7 @@ def update_score(self, opponent: Player):
889899
self.own_score += game.score(last_round)[0]
890900

891901
def strategy(self, opponent: Player) -> Action:
902+
"""Actual strategy definition that determines player's action."""
892903
if self.mode == "Defect":
893904
return D
894905

@@ -978,6 +989,7 @@ def try_return(self, to_return):
978989
return to_return
979990

980991
def strategy(self, opponent: Player) -> Action:
992+
"""Actual strategy definition that determines player's action."""
981993
if len(opponent.history) == 0:
982994
return C
983995

@@ -1262,6 +1274,7 @@ def detect_parity_streak(self, last_move):
12621274
return True
12631275

12641276
def strategy(self, opponent: Player) -> Action:
1277+
"""Actual strategy definition that determines player's action."""
12651278
turn = len(self.history) + 1
12661279

12671280
if turn == 1:
@@ -1433,6 +1446,7 @@ def _score_last_round(self, opponent: Player):
14331446
self.opponent_score += scores[1]
14341447

14351448
def strategy(self, opponent: Player) -> Action:
1449+
"""Actual strategy definition that determines player's action."""
14361450
current_round = len(self.history) + 1
14371451

14381452
if current_round == 1:
@@ -1507,6 +1521,7 @@ def __init__(self) -> None:
15071521
self.flack = 0.0 # The relative untrustworthiness of opponent
15081522

15091523
def strategy(self, opponent: Player) -> Action:
1524+
"""Actual strategy definition that determines player's action."""
15101525
if not opponent.history:
15111526
return C
15121527

@@ -1833,7 +1848,7 @@ def try_return(self, to_return, opp_def):
18331848
# If so, then override
18341849
if turn > 40:
18351850
portion_defect = (opp_def + 0.5) / turn
1836-
if 0.45 < portion_defect and portion_defect < 0.55:
1851+
if 0.45 < portion_defect < 0.55:
18371852
return D
18381853

18391854
return to_return

axelrod/strategies/backstabber.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class BackStabber(Player):
2727
}
2828

2929
def strategy(self, opponent: Player) -> Action:
30+
"""Actual strategy definition that determines player's action."""
3031
return _backstabber_strategy(opponent)
3132

3233

@@ -56,6 +57,7 @@ class DoubleCrosser(Player):
5657
}
5758

5859
def strategy(self, opponent: Player) -> Action:
60+
"""Actual strategy definition that determines player's action."""
5961
if _opponent_triggers_alt_strategy(opponent):
6062
return _alt_strategy(opponent)
6163
return _backstabber_strategy(opponent)

axelrod/strategies/better_and_better.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class BetterAndBetter(Player):
2525
}
2626

2727
def strategy(self, opponent: Player) -> Action:
28+
"""Actual strategy definition that determines player's action."""
2829
current_round = len(self.history) + 1
2930
probability = current_round / 1000
3031
return self._random.random_choice(probability)

axelrod/strategies/bush_mosteller.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ def stimulus_update(self, opponent: Player):
124124
)
125125

126126
def strategy(self, opponent: Player) -> Action:
127+
"""Actual strategy definition that determines player's action."""
127128

128129
# First turn
129130
if len(self.history) == 0:

axelrod/strategies/calculator.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def set_seed(self, seed: int = None):
3737
self.joss_instance.set_seed(seed)
3838

3939
def strategy(self, opponent: Player) -> Action:
40+
"""Actual strategy definition that determines player's action."""
4041
turn = len(self.history)
4142
if turn > 0:
4243
self.joss_instance.history.append(

axelrod/strategies/cooperator.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class Cooperator(Player):
2626

2727
@staticmethod
2828
def strategy(opponent: Player) -> Action:
29+
"""Actual strategy definition that determines player's action."""
2930
return C
3031

3132

axelrod/strategies/cycler.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def _get_first_three() -> List[Action]:
4545
return [C, D, D]
4646

4747
def strategy(self, opponent: Player) -> Action:
48+
"""Actual strategy definition that determines player's action."""
4849
while self.first_three:
4950
return self.first_three.pop(0)
5051
if self.cycle_counter < self.cycle_length:
@@ -91,6 +92,7 @@ def __init__(self, cycle: str = "CCD") -> None:
9192
self.set_cycle(cycle=cycle)
9293

9394
def strategy(self, opponent: Player) -> Action:
95+
"""Actual strategy definition that determines player's action."""
9496
return next(self.cycle_iter)
9597

9698
def set_cycle(self, cycle: str):

axelrod/strategies/darwin.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def foil_strategy_inspection() -> Action:
6060
return C
6161

6262
def strategy(self, opponent: Player) -> Action:
63+
"""Actual strategy definition that determines player's action."""
6364
trial = len(self.history)
6465

6566
if trial > 0:

axelrod/strategies/dbs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ def compute_prob_rule(self, outcome, alpha=1):
210210
return p_cond
211211

212212
def strategy(self, opponent: Player) -> Action:
213+
"""Actual strategy definition that determines player's action."""
213214
# First move
214215
if not self.history:
215216
return C

axelrod/strategies/defector.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class Defector(Player):
2626

2727
@staticmethod
2828
def strategy(opponent: Player) -> Action:
29+
"""Actual strategy definition that determines player's action."""
2930
return D
3031

3132

axelrod/strategies/doubler.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class Doubler(Player):
2525
}
2626

2727
def strategy(self, opponent: Player) -> Action:
28+
"""Actual strategy definition that determines player's action."""
2829
if not self.history:
2930
return C
3031
if (

axelrod/strategies/finite_state_machines.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ def __init__(
122122
self.fsm = SimpleFSM(transitions, initial_state)
123123

124124
def strategy(self, opponent: Player) -> Action:
125+
"""Actual strategy definition that determines player's action."""
125126
if len(self.history) == 0:
126127
return self.initial_action
127128
else:

0 commit comments

Comments
 (0)